Skip to content

Commit 3296bd7

Browse files
committed
Rename slice::unzip() to vec::unzip()
unzip() has nothing to do with slices, so it belongs in vec.
1 parent 21dae8e commit 3296bd7

File tree

4 files changed

+38
-36
lines changed

4 files changed

+38
-36
lines changed

src/librustc/middle/trans/consts.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ use middle::ty;
3333
use util::ppaux::{Repr, ty_to_str};
3434

3535
use std::c_str::ToCStr;
36-
use std::slice;
36+
use std::{slice, vec};
3737
use std::vec::Vec;
3838
use libc::c_uint;
3939
use syntax::{ast, ast_util};
@@ -94,7 +94,7 @@ fn const_vec(cx: &CrateContext, e: &ast::Expr,
9494
let vec_ty = ty::expr_ty(cx.tcx(), e);
9595
let unit_ty = ty::sequence_element_type(cx.tcx(), vec_ty);
9696
let llunitty = type_of::type_of(cx, unit_ty);
97-
let (vs, inlineable) = slice::unzip(es.iter().map(|e| const_expr(cx, *e, is_local)));
97+
let (vs, inlineable) = vec::unzip(es.iter().map(|e| const_expr(cx, *e, is_local)));
9898
// If the vector contains enums, an LLVM array won't work.
9999
let v = if vs.iter().any(|vi| val_ty(*vi) != llunitty) {
100100
C_struct(cx, vs, false)
@@ -539,7 +539,7 @@ fn const_expr_unadjusted(cx: &CrateContext, e: &ast::Expr,
539539
};
540540

541541
expr::with_field_tys(tcx, ety, Some(e.id), |discr, field_tys| {
542-
let (cs, inlineable) = slice::unzip(field_tys.iter().enumerate()
542+
let (cs, inlineable) = vec::unzip(field_tys.iter().enumerate()
543543
.map(|(ix, &field_ty)| {
544544
match fs.iter().find(|f| field_ty.ident.name == f.ident.node.name) {
545545
Some(f) => const_expr(cx, (*f).expr, is_local),

src/libstd/slice.rs

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -155,25 +155,6 @@ impl<'a, T: Clone, V: Vector<T>> VectorVector<T> for &'a [V] {
155155
}
156156
}
157157

158-
/**
159-
* Convert an iterator of pairs into a pair of vectors.
160-
*
161-
* Returns a tuple containing two vectors where the i-th element of the first
162-
* vector contains the first element of the i-th tuple of the input iterator,
163-
* and the i-th element of the second vector contains the second element
164-
* of the i-th tuple of the input iterator.
165-
*/
166-
pub fn unzip<T, U, V: Iterator<(T, U)>>(mut iter: V) -> (~[T], ~[U]) {
167-
let (lo, _) = iter.size_hint();
168-
let mut ts = Vec::with_capacity(lo);
169-
let mut us = Vec::with_capacity(lo);
170-
for (t, u) in iter {
171-
ts.push(t);
172-
us.push(u);
173-
}
174-
(ts.move_iter().collect(), us.move_iter().collect())
175-
}
176-
177158
/// An Iterator that yields the element swaps needed to produce
178159
/// a sequence of all possible permutations for an indexed sequence of
179160
/// elements. Each permutation is only a single swap apart.
@@ -1242,18 +1223,6 @@ mod tests {
12421223
assert_eq!(v, vec![1, 3, 5]);
12431224
}
12441225

1245-
#[test]
1246-
fn test_zip_unzip() {
1247-
let z1 = vec![(1, 4), (2, 5), (3, 6)];
1248-
1249-
let (left, right) = unzip(z1.iter().map(|&x| x));
1250-
1251-
let (left, right) = (left.as_slice(), right.as_slice());
1252-
assert_eq!((1, 4), (left[0], right[0]));
1253-
assert_eq!((2, 5), (left[1], right[1]));
1254-
assert_eq!((3, 6), (left[2], right[2]));
1255-
}
1256-
12571226
#[test]
12581227
fn test_element_swaps() {
12591228
let mut v = [1, 2, 3];

src/libstd/sync/deque.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ mod tests {
407407
use rand::Rng;
408408
use sync::atomics::{AtomicBool, INIT_ATOMIC_BOOL, SeqCst,
409409
AtomicUint, INIT_ATOMIC_UINT};
410-
use slice;
410+
use vec;
411411

412412
#[test]
413413
fn smoke() {
@@ -603,7 +603,7 @@ mod tests {
603603
let mut pool = BufferPool::<(int, uint)>::new();
604604
let (mut w, s) = pool.deque();
605605

606-
let (threads, hits) = slice::unzip(range(0, NTHREADS).map(|_| {
606+
let (threads, hits) = vec::unzip(range(0, NTHREADS).map(|_| {
607607
let s = s.clone();
608608
let unique_box = box AtomicUint::new(0);
609609
let thread_box = unsafe {

src/libstd/vec.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1436,10 +1436,31 @@ impl<T> Drop for MoveItems<T> {
14361436
}
14371437
}
14381438

1439+
/**
1440+
* Convert an iterator of pairs into a pair of vectors.
1441+
*
1442+
* Returns a tuple containing two vectors where the i-th element of the first
1443+
* vector contains the first element of the i-th tuple of the input iterator,
1444+
* and the i-th element of the second vector contains the second element
1445+
* of the i-th tuple of the input iterator.
1446+
*/
1447+
pub fn unzip<T, U, V: Iterator<(T, U)>>(mut iter: V) -> (Vec<T>, Vec<U>) {
1448+
let (lo, _) = iter.size_hint();
1449+
let mut ts = Vec::with_capacity(lo);
1450+
let mut us = Vec::with_capacity(lo);
1451+
for (t, u) in iter {
1452+
ts.push(t);
1453+
us.push(u);
1454+
}
1455+
(ts, us)
1456+
}
1457+
1458+
14391459
#[cfg(test)]
14401460
mod tests {
14411461
use prelude::*;
14421462
use mem::size_of;
1463+
use super::unzip;
14431464

14441465
#[test]
14451466
fn test_small_vec_struct() {
@@ -1687,4 +1708,16 @@ mod tests {
16871708
assert_eq!([&[1], &[2, 3]].connect_vec(&0), vec![1, 0, 2, 3]);
16881709
assert_eq!([&[1], &[2], &[3]].connect_vec(&0), vec![1, 0, 2, 0, 3]);
16891710
}
1711+
1712+
#[test]
1713+
fn test_zip_unzip() {
1714+
let z1 = vec![(1, 4), (2, 5), (3, 6)];
1715+
1716+
let (left, right) = unzip(z1.iter().map(|&x| x));
1717+
1718+
let (left, right) = (left.as_slice(), right.as_slice());
1719+
assert_eq!((1, 4), (left[0], right[0]));
1720+
assert_eq!((2, 5), (left[1], right[1]));
1721+
assert_eq!((3, 6), (left[2], right[2]));
1722+
}
16901723
}

0 commit comments

Comments
 (0)