Skip to content

Commit

Permalink
rename std::vec -> std::slice
Browse files Browse the repository at this point in the history
Closes #12702
  • Loading branch information
thestinger committed Mar 20, 2014
1 parent 4ca51ae commit ce62032
Show file tree
Hide file tree
Showing 115 changed files with 360 additions and 365 deletions.
4 changes: 2 additions & 2 deletions src/compiletest/runtest.rs
Expand Up @@ -32,7 +32,7 @@ use std::io;
use std::os;
use std::str;
use std::task;
use std::vec;
use std::slice;

use test::MetricMap;

Expand Down Expand Up @@ -500,7 +500,7 @@ fn check_expected_errors(expected_errors: ~[errors::ExpectedError],
proc_res: &ProcRes) {

// true if we found the error in question
let mut found_flags = vec::from_elem(
let mut found_flags = slice::from_elem(
expected_errors.len(), false);

if proc_res.status.success() {
Expand Down
6 changes: 3 additions & 3 deletions src/doc/guide-ffi.md
Expand Up @@ -71,7 +71,7 @@ The raw C API needs to be wrapped to provide memory safety and make use of highe
like vectors. A library can choose to expose only the safe, high-level interface and hide the unsafe
internal details.

Wrapping the functions which expect buffers involves using the `vec::raw` module to manipulate Rust
Wrapping the functions which expect buffers involves using the `slice::raw` module to manipulate Rust
vectors as pointers to memory. Rust's vectors are guaranteed to be a contiguous block of memory. The
length is number of elements currently contained, and the capacity is the total size in elements of
the allocated memory. The length is less than or equal to the capacity.
Expand Down Expand Up @@ -103,7 +103,7 @@ pub fn compress(src: &[u8]) -> ~[u8] {
let psrc = src.as_ptr();
let mut dstlen = snappy_max_compressed_length(srclen);
let mut dst = vec::with_capacity(dstlen as uint);
let mut dst = slice::with_capacity(dstlen as uint);
let pdst = dst.as_mut_ptr();
snappy_compress(psrc, srclen, pdst, &mut dstlen);
Expand All @@ -125,7 +125,7 @@ pub fn uncompress(src: &[u8]) -> Option<~[u8]> {
let mut dstlen: size_t = 0;
snappy_uncompressed_length(psrc, srclen, &mut dstlen);
let mut dst = vec::with_capacity(dstlen as uint);
let mut dst = slice::with_capacity(dstlen as uint);
let pdst = dst.as_mut_ptr();
if snappy_uncompress(psrc, srclen, pdst, &mut dstlen) == 0 {
Expand Down
24 changes: 12 additions & 12 deletions src/doc/guide-tasks.md
Expand Up @@ -255,10 +255,10 @@ might look like the example below.

~~~
# use std::task::spawn;
# use std::vec;
# use std::slice;
// Create a vector of ports, one for each child task
let rxs = vec::from_fn(3, |init_val| {
let rxs = slice::from_fn(3, |init_val| {
let (tx, rx) = channel();
spawn(proc() {
tx.send(some_expensive_computation(init_val));
Expand Down Expand Up @@ -304,7 +304,7 @@ be distributed on the available cores.

~~~
# extern crate sync;
# use std::vec;
# use std::slice;
fn partial_sum(start: uint) -> f64 {
let mut local_sum = 0f64;
for num in range(start*100000, (start+1)*100000) {
Expand All @@ -314,7 +314,7 @@ fn partial_sum(start: uint) -> f64 {
}
fn main() {
let mut futures = vec::from_fn(1000, |ind| sync::Future::spawn( proc() { partial_sum(ind) }));
let mut futures = slice::from_fn(1000, |ind| sync::Future::spawn( proc() { partial_sum(ind) }));
let mut final_res = 0f64;
for ft in futures.mut_iter() {
Expand Down Expand Up @@ -342,15 +342,15 @@ a single large vector of floats. Each task needs the full vector to perform its
extern crate rand;
extern crate sync;
use std::vec;
use std::slice;
use sync::Arc;
fn pnorm(nums: &~[f64], p: uint) -> f64 {
nums.iter().fold(0.0, |a,b| a+(*b).powf(&(p as f64)) ).powf(&(1.0 / (p as f64)))
}
fn main() {
let numbers = vec::from_fn(1000000, |_| rand::random::<f64>());
let numbers = slice::from_fn(1000000, |_| rand::random::<f64>());
let numbers_arc = Arc::new(numbers);
for num in range(1u, 10) {
Expand All @@ -374,9 +374,9 @@ created by the line
# extern crate sync;
# extern crate rand;
# use sync::Arc;
# use std::vec;
# use std::slice;
# fn main() {
# let numbers = vec::from_fn(1000000, |_| rand::random::<f64>());
# let numbers = slice::from_fn(1000000, |_| rand::random::<f64>());
let numbers_arc=Arc::new(numbers);
# }
~~~
Expand All @@ -387,9 +387,9 @@ and a clone of it is sent to each task
# extern crate sync;
# extern crate rand;
# use sync::Arc;
# use std::vec;
# use std::slice;
# fn main() {
# let numbers=vec::from_fn(1000000, |_| rand::random::<f64>());
# let numbers=slice::from_fn(1000000, |_| rand::random::<f64>());
# let numbers_arc = Arc::new(numbers);
# let (tx, rx) = channel();
tx.send(numbers_arc.clone());
Expand All @@ -404,9 +404,9 @@ Each task recovers the underlying data by
# extern crate sync;
# extern crate rand;
# use sync::Arc;
# use std::vec;
# use std::slice;
# fn main() {
# let numbers=vec::from_fn(1000000, |_| rand::random::<f64>());
# let numbers=slice::from_fn(1000000, |_| rand::random::<f64>());
# let numbers_arc=Arc::new(numbers);
# let (tx, rx) = channel();
# tx.send(numbers_arc.clone());
Expand Down
6 changes: 3 additions & 3 deletions src/doc/guide-testing.md
Expand Up @@ -188,18 +188,18 @@ For example:
# #[allow(unused_imports)];
extern crate test;
use std::vec;
use std::slice;
use test::BenchHarness;
#[bench]
fn bench_sum_1024_ints(b: &mut BenchHarness) {
let v = vec::from_fn(1024, |n| n);
let v = slice::from_fn(1024, |n| n);
b.iter(|| {v.iter().fold(0, |old, new| old + *new);} );
}
#[bench]
fn initialise_a_vector(b: &mut BenchHarness) {
b.iter(|| {vec::from_elem(1024, 0u64);} );
b.iter(|| {slice::from_elem(1024, 0u64);} );
b.bytes = 1024 * 8;
}
Expand Down
6 changes: 3 additions & 3 deletions src/etc/unicode.py
Expand Up @@ -162,7 +162,7 @@ def emit_bsearch_range_table(f):
f.write("""
fn bsearch_range_table(c: char, r: &'static [(char,char)]) -> bool {
use cmp::{Equal, Less, Greater};
use vec::ImmutableVector;
use slice::ImmutableVector;
use option::None;
r.bsearch(|&(lo,hi)| {
if lo <= c && c <= hi { Equal }
Expand Down Expand Up @@ -200,7 +200,7 @@ def emit_conversions_module(f, lowerupper, upperlower):
f.write("pub mod conversions {\n")
f.write("""
use cmp::{Equal, Less, Greater};
use vec::ImmutableVector;
use slice::ImmutableVector;
use tuple::Tuple2;
use option::{Option, Some, None};
Expand Down Expand Up @@ -264,7 +264,7 @@ def emit_decomp_module(f, canon, compat, combine):
f.write("pub mod decompose {\n");
f.write(" use option::Option;\n");
f.write(" use option::{Some, None};\n");
f.write(" use vec::ImmutableVector;\n");
f.write(" use slice::ImmutableVector;\n");
f.write("""
fn bsearch_table(c: char, r: &'static [(char, &'static [char])]) -> Option<&'static [char]> {
use cmp::{Equal, Less, Greater};
Expand Down
4 changes: 2 additions & 2 deletions src/libarena/lib.rs
Expand Up @@ -42,7 +42,7 @@ use std::rc::Rc;
use std::rt::global_heap;
use std::intrinsics::{TyDesc, get_tydesc};
use std::intrinsics;
use std::vec;
use std::slice;

// The way arena uses arrays is really deeply awful. The arrays are
// allocated, and have capacities reserved, but the fill for the array
Expand Down Expand Up @@ -111,7 +111,7 @@ impl Arena {

fn chunk(size: uint, is_pod: bool) -> Chunk {
Chunk {
data: Rc::new(RefCell::new(vec::with_capacity(size))),
data: Rc::new(RefCell::new(slice::with_capacity(size))),
fill: Cell::new(0u),
is_pod: Cell::new(is_pod),
}
Expand Down
22 changes: 11 additions & 11 deletions src/libcollections/bitv.rs
Expand Up @@ -16,7 +16,7 @@ use std::iter::RandomAccessIterator;
use std::iter::{Rev, Enumerate, Repeat, Map, Zip};
use std::ops;
use std::uint;
use std::vec;
use std::slice;

#[deriving(Clone)]
struct SmallBitv {
Expand Down Expand Up @@ -278,13 +278,13 @@ impl Bitv {
let s =
if init {
if exact {
vec::from_elem(nelems, !0u)
slice::from_elem(nelems, !0u)
} else {
let mut v = vec::from_elem(nelems-1, !0u);
let mut v = slice::from_elem(nelems-1, !0u);
v.push((1<<nbits % uint::BITS)-1);
v
}
} else { vec::from_elem(nelems, 0u)};
} else { slice::from_elem(nelems, 0u)};
Big(BigBitv::new(s))
};
Bitv {rep: rep, nbits: nbits}
Expand Down Expand Up @@ -452,7 +452,7 @@ impl Bitv {
* Each `uint` in the resulting vector has either value `0u` or `1u`.
*/
pub fn to_vec(&self) -> ~[uint] {
vec::from_fn(self.nbits, |x| self.init_to_vec(x))
slice::from_fn(self.nbits, |x| self.init_to_vec(x))
}

/**
Expand All @@ -473,7 +473,7 @@ impl Bitv {

let len = self.nbits/8 +
if self.nbits % 8 == 0 { 0 } else { 1 };
vec::from_fn(len, |i|
slice::from_fn(len, |i|
bit(self, i, 0) |
bit(self, i, 1) |
bit(self, i, 2) |
Expand All @@ -489,7 +489,7 @@ impl Bitv {
* Transform `self` into a `[bool]` by turning each bit into a `bool`.
*/
pub fn to_bools(&self) -> ~[bool] {
vec::from_fn(self.nbits, |i| self[i])
slice::from_fn(self.nbits, |i| self[i])
}

/**
Expand Down Expand Up @@ -879,7 +879,7 @@ impl BitvSet {
/// and w1/w2 are the words coming from the two vectors self, other.
fn commons<'a>(&'a self, other: &'a BitvSet)
-> Map<'static, ((uint, &'a uint), &'a ~[uint]), (uint, uint, uint),
Zip<Enumerate<vec::Items<'a, uint>>, Repeat<&'a ~[uint]>>> {
Zip<Enumerate<slice::Items<'a, uint>>, Repeat<&'a ~[uint]>>> {
let min = cmp::min(self.bitv.storage.len(), other.bitv.storage.len());
self.bitv.storage.slice(0, min).iter().enumerate()
.zip(Repeat::new(&other.bitv.storage))
Expand All @@ -895,7 +895,7 @@ impl BitvSet {
/// `other`.
fn outliers<'a>(&'a self, other: &'a BitvSet)
-> Map<'static, ((uint, &'a uint), uint), (bool, uint, uint),
Zip<Enumerate<vec::Items<'a, uint>>, Repeat<uint>>> {
Zip<Enumerate<slice::Items<'a, uint>>, Repeat<uint>>> {
let slen = self.bitv.storage.len();
let olen = other.bitv.storage.len();

Expand Down Expand Up @@ -946,7 +946,7 @@ mod tests {
use bitv;

use std::uint;
use std::vec;
use std::slice;
use rand;
use rand::Rng;

Expand All @@ -964,7 +964,7 @@ mod tests {
#[test]
fn test_0_elements() {
let act = Bitv::new(0u, false);
let exp = vec::from_elem::<bool>(0u, false);
let exp = slice::from_elem::<bool>(0u, false);
assert!(act.eq_vec(exp));
}

Expand Down
4 changes: 2 additions & 2 deletions src/libcollections/deque.rs
Expand Up @@ -44,7 +44,7 @@ pub mod bench {
extern crate test;
use self::test::BenchHarness;
use std::container::MutableMap;
use std::vec;
use std::slice;
use rand;
use rand::Rng;

Expand Down Expand Up @@ -90,7 +90,7 @@ pub mod bench {
bh: &mut BenchHarness) {
// setup
let mut rng = rand::XorShiftRng::new();
let mut keys = vec::from_fn(n, |_| rng.gen::<uint>() % n);
let mut keys = slice::from_fn(n, |_| rng.gen::<uint>() % n);

for k in keys.iter() {
map.insert(*k, 1);
Expand Down
4 changes: 2 additions & 2 deletions src/libcollections/hashmap.rs
Expand Up @@ -27,7 +27,7 @@ use std::option::{Option, Some, None};
use rand;
use rand::Rng;
use std::result::{Ok, Err};
use std::vec::{ImmutableVector};
use std::slice::ImmutableVector;

mod table {
use std::clone::Clone;
Expand Down Expand Up @@ -1958,7 +1958,7 @@ mod test_map {
mod test_set {
use super::HashSet;
use std::container::Container;
use std::vec::ImmutableEqVector;
use std::slice::ImmutableEqVector;

#[test]
fn test_disjoint() {
Expand Down
4 changes: 2 additions & 2 deletions src/libcollections/priority_queue.rs
Expand Up @@ -14,7 +14,7 @@

use std::clone::Clone;
use std::mem::{move_val_init, init, replace, swap};
use std::vec;
use std::slice;

/// A priority queue implemented with a binary heap
#[deriving(Clone)]
Expand Down Expand Up @@ -181,7 +181,7 @@ impl<T:Ord> PriorityQueue<T> {

/// PriorityQueue iterator
pub struct Items <'a, T> {
priv iter: vec::Items<'a, T>,
priv iter: slice::Items<'a, T>,
}

impl<'a, T> Iterator<&'a T> for Items<'a, T> {
Expand Down
4 changes: 2 additions & 2 deletions src/libcollections/ringbuf.rs
Expand Up @@ -14,7 +14,7 @@
//! extra::container::Deque`.

use std::cmp;
use std::vec;
use std::slice;
use std::iter::{Rev, RandomAccessIterator};

use deque::Deque;
Expand Down Expand Up @@ -118,7 +118,7 @@ impl<T> RingBuf<T> {
/// Create an empty RingBuf with space for at least `n` elements.
pub fn with_capacity(n: uint) -> RingBuf<T> {
RingBuf{nelts: 0, lo: 0,
elts: vec::from_fn(cmp::max(MINIMUM_CAPACITY, n), |_| None)}
elts: slice::from_fn(cmp::max(MINIMUM_CAPACITY, n), |_| None)}
}

/// Retrieve an element in the RingBuf by index
Expand Down
8 changes: 4 additions & 4 deletions src/libcollections/smallintmap.rs
Expand Up @@ -17,7 +17,7 @@

use std::iter::{Enumerate, FilterMap, Rev};
use std::mem::replace;
use std::vec;
use std::slice;

#[allow(missing_doc)]
pub struct SmallIntMap<T> {
Expand Down Expand Up @@ -153,7 +153,7 @@ impl<V> SmallIntMap<V> {
/// Empties the hash map, moving all values into the specified closure
pub fn move_iter(&mut self)
-> FilterMap<(uint, Option<V>), (uint, V),
Enumerate<vec::MoveItems<Option<V>>>>
Enumerate<slice::MoveItems<Option<V>>>>
{
let values = replace(&mut self.v, ~[]);
values.move_iter().enumerate().filter_map(|(i, v)| {
Expand Down Expand Up @@ -236,7 +236,7 @@ macro_rules! double_ended_iterator {
pub struct Entries<'a, T> {
priv front: uint,
priv back: uint,
priv iter: vec::Items<'a, Option<T>>
priv iter: slice::Items<'a, Option<T>>
}

iterator!(impl Entries -> (uint, &'a T), get_ref)
Expand All @@ -246,7 +246,7 @@ pub type RevEntries<'a, T> = Rev<Entries<'a, T>>;
pub struct MutEntries<'a, T> {
priv front: uint,
priv back: uint,
priv iter: vec::MutItems<'a, Option<T>>
priv iter: slice::MutItems<'a, Option<T>>
}

iterator!(impl MutEntries -> (uint, &'a mut T), get_mut_ref)
Expand Down

5 comments on commit ce62032

@bors
Copy link
Contributor

@bors bors commented on ce62032 Mar 20, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on ce62032 Mar 20, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging thestinger/rust/slice = ce62032 into auto

@bors
Copy link
Contributor

@bors bors commented on ce62032 Mar 20, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thestinger/rust/slice = ce62032 merged ok, testing candidate = 7aded2a

@bors
Copy link
Contributor

@bors bors commented on ce62032 Mar 20, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on ce62032 Mar 20, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = 7aded2a

Please sign in to comment.