diff options
| author | bors <bors@rust-lang.org> | 2015-07-09 10:36:41 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2015-07-09 10:36:41 +0000 |
| commit | f11502cda8a05aae9b260141ac9c4538d46bb01b (patch) | |
| tree | fd3a72c4bf63d6d12a48155843dd172af01a6a70 /src/libstd | |
| parent | 517e087c16749086a3a0fec453af3d1c53232605 (diff) | |
| parent | 836f32e7697195a482b88883cbbe4a2dd986d8cb (diff) | |
| download | rust-f11502cda8a05aae9b260141ac9c4538d46bb01b.tar.gz rust-f11502cda8a05aae9b260141ac9c4538d46bb01b.zip | |
Auto merge of #26904 - bluss:no-repeat, r=alexcrichton
In a followup to PR #26849, improve one more location for I/O where we can use `Vec::resize` to ensure better performance when zeroing buffers. Use the `vec![elt; n]` macro everywhere we can in the tree. It replaces `repeat(elt).take(n).collect()` which is more verbose, requires type hints, and right now produces worse code. `vec![]` is preferable for vector initialization. The `vec![]` replacement touches upon one I/O path too, Stdin::read for windows, and that should be a small improvement. r? @alexcrichton
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/collections/hash/map.rs | 6 | ||||
| -rw-r--r-- | src/libstd/io/cursor.rs | 5 | ||||
| -rw-r--r-- | src/libstd/sys/windows/stdio.rs | 3 |
3 files changed, 7 insertions, 7 deletions
diff --git a/src/libstd/collections/hash/map.rs b/src/libstd/collections/hash/map.rs index 1dca3b77f38..06a30670e8b 100644 --- a/src/libstd/collections/hash/map.rs +++ b/src/libstd/collections/hash/map.rs @@ -1638,7 +1638,7 @@ mod test_map { use super::HashMap; use super::Entry::{Occupied, Vacant}; - use iter::{range_inclusive, repeat}; + use iter::range_inclusive; use cell::RefCell; use rand::{thread_rng, Rng}; @@ -1698,7 +1698,7 @@ mod test_map { #[test] fn test_drops() { DROP_VECTOR.with(|slot| { - *slot.borrow_mut() = repeat(0).take(200).collect(); + *slot.borrow_mut() = vec![0; 200]; }); { @@ -1757,7 +1757,7 @@ mod test_map { #[test] fn test_move_iter_drops() { DROP_VECTOR.with(|v| { - *v.borrow_mut() = repeat(0).take(200).collect(); + *v.borrow_mut() = vec![0; 200]; }); let hm = { diff --git a/src/libstd/io/cursor.rs b/src/libstd/io/cursor.rs index 72743106abf..f059b24baf6 100644 --- a/src/libstd/io/cursor.rs +++ b/src/libstd/io/cursor.rs @@ -13,7 +13,6 @@ use io::prelude::*; use cmp; use io::{self, SeekFrom, Error, ErrorKind}; -use iter::repeat; use slice; /// A `Cursor` is a type which wraps a non-I/O object to provide a `Seek` @@ -143,7 +142,9 @@ impl Write for Cursor<Vec<u8>> { // currently are let pos = self.position(); let amt = pos.saturating_sub(self.inner.len() as u64); - self.inner.extend(repeat(0).take(amt as usize)); + // use `resize` so that the zero filling is as efficient as possible + let len = self.inner.len(); + self.inner.resize(len + amt as usize, 0); // Figure out what bytes will be used to overwrite what's currently // there (left), and what will be appended on the end (right) diff --git a/src/libstd/sys/windows/stdio.rs b/src/libstd/sys/windows/stdio.rs index 9961fef714a..356787d5bf0 100644 --- a/src/libstd/sys/windows/stdio.rs +++ b/src/libstd/sys/windows/stdio.rs @@ -12,7 +12,6 @@ use prelude::v1::*; use io::prelude::*; use io::{self, Cursor}; -use iter::repeat; use libc; use ptr; use str; @@ -94,7 +93,7 @@ impl Stdin { let mut utf8 = self.utf8.lock().unwrap(); // Read more if the buffer is empty if utf8.position() as usize == utf8.get_ref().len() { - let mut utf16: Vec<u16> = repeat(0u16).take(0x1000).collect(); + let mut utf16 = vec![0u16; 0x1000]; let mut num = 0; try!(cvt(unsafe { c::ReadConsoleW(handle, |
