Skip to content

Commit 97da34d

Browse files
committed
---
yaml --- r: 153279 b: refs/heads/try2 c: e2d107c h: refs/heads/master i: 153277: 5d00bfc 153275: aa7aae4 153271: 3090a16 153263: d722a20 153247: bad7461 153215: 4beff38 v: v3
1 parent cdcbe08 commit 97da34d

File tree

2 files changed

+23
-23
lines changed

2 files changed

+23
-23
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 7d3899430b71d3ebed6b3fbf6ec47b042f513979
8+
refs/heads/try2: e2d107c397acbc7b0d9677c36882616308346ed9
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/libcollections/vec.rs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,13 @@ impl<T: Clone> Vec<T> {
198198
#[inline]
199199
pub fn from_slice(values: &[T]) -> Vec<T> {
200200
let mut vector = Vec::with_capacity(values.len());
201-
vector.push_all(values);
201+
202+
// Directly call `unsafe_push_all_clone` so we can skip a call to
203+
// `reserve_addtional`.
204+
unsafe {
205+
unsafe_push_all_clone(&mut vector, values);
206+
}
207+
202208
vector
203209
}
204210

@@ -240,8 +246,9 @@ impl<T: Clone> Vec<T> {
240246
/// ```
241247
#[inline]
242248
pub fn push_all(&mut self, other: &[T]) {
249+
self.reserve_additional(other.len());
250+
243251
unsafe {
244-
self.reserve_additional(other.len());
245252
unsafe_push_all_clone(self, other)
246253
}
247254
}
@@ -323,31 +330,24 @@ impl<T: Clone> Vec<T> {
323330
#[unstable]
324331
impl<T:Clone> Clone for Vec<T> {
325332
fn clone(&self) -> Vec<T> {
326-
unsafe {
327-
let mut vector = Vec::with_capacity(self.len);
328-
unsafe_push_all_clone(&mut vector, self.as_slice());
329-
vector
330-
}
333+
Vec::from_slice(self.as_slice())
331334
}
332335

333336
fn clone_from(&mut self, other: &Vec<T>) {
334-
unsafe {
335-
// drop anything in self that will not be overwritten
336-
if self.len() > other.len() {
337-
self.truncate(other.len())
338-
}
339-
340-
// reuse the contained values' allocations/resources.
341-
for (place, thing) in self.mut_iter().zip(other.iter()) {
342-
place.clone_from(thing)
343-
}
337+
// drop anything in self that will not be overwritten
338+
if self.len() > other.len() {
339+
self.truncate(other.len())
340+
}
344341

345-
// self.len <= other.len due to the truncate above, so the
346-
// slice here is always in-bounds.
347-
let slice = other.slice_from(self.len());
348-
self.reserve_additional(slice.len());
349-
unsafe_push_all_clone(self, slice)
342+
// reuse the contained values' allocations/resources.
343+
for (place, thing) in self.mut_iter().zip(other.iter()) {
344+
place.clone_from(thing)
350345
}
346+
347+
// self.len <= other.len due to the truncate above, so the
348+
// slice here is always in-bounds.
349+
let slice = other.slice_from(self.len());
350+
self.push_all(slice);
351351
}
352352
}
353353

0 commit comments

Comments
 (0)