rollup merge of #20061: aturon/stab-2-vec-slice
Conflicts: src/libcollections/slice.rs src/libcollections/vec.rs src/libstd/sys/windows/os.rs
This commit is contained in:
commit
67d13883f8
80 changed files with 2525 additions and 2524 deletions
|
@ -32,6 +32,7 @@ use std::io::process;
|
||||||
use std::io::timer;
|
use std::io::timer;
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::os;
|
use std::os;
|
||||||
|
use std::iter::repeat;
|
||||||
use std::str;
|
use std::str;
|
||||||
use std::string::String;
|
use std::string::String;
|
||||||
use std::thread::Thread;
|
use std::thread::Thread;
|
||||||
|
@ -947,8 +948,7 @@ fn check_expected_errors(expected_errors: Vec<errors::ExpectedError> ,
|
||||||
proc_res: &ProcRes) {
|
proc_res: &ProcRes) {
|
||||||
|
|
||||||
// true if we found the error in question
|
// true if we found the error in question
|
||||||
let mut found_flags = Vec::from_elem(
|
let mut found_flags: Vec<_> = repeat(false).take(expected_errors.len()).collect();
|
||||||
expected_errors.len(), false);
|
|
||||||
|
|
||||||
if proc_res.status.success() {
|
if proc_res.status.success() {
|
||||||
fatal("process did not return an error status");
|
fatal("process did not return an error status");
|
||||||
|
@ -1308,7 +1308,7 @@ fn make_run_args(config: &Config, props: &TestProps, testfile: &Path) ->
|
||||||
// Add the arguments in the run_flags directive
|
// Add the arguments in the run_flags directive
|
||||||
args.extend(split_maybe_args(&props.run_flags).into_iter());
|
args.extend(split_maybe_args(&props.run_flags).into_iter());
|
||||||
|
|
||||||
let prog = args.remove(0).unwrap();
|
let prog = args.remove(0);
|
||||||
return ProcArgs {
|
return ProcArgs {
|
||||||
prog: prog,
|
prog: prog,
|
||||||
args: args,
|
args: args,
|
||||||
|
|
|
@ -96,7 +96,7 @@ use heap::deallocate;
|
||||||
/// use std::thread::Thread;
|
/// use std::thread::Thread;
|
||||||
///
|
///
|
||||||
/// fn main() {
|
/// fn main() {
|
||||||
/// let numbers = Vec::from_fn(100, |i| i as f32);
|
/// let numbers: Vec<_> = range(0, 100u32).map(|i| i as f32).collect();
|
||||||
/// let shared_numbers = Arc::new(numbers);
|
/// let shared_numbers = Arc::new(numbers);
|
||||||
///
|
///
|
||||||
/// for _ in range(0u, 10) {
|
/// for _ in range(0u, 10) {
|
||||||
|
|
|
@ -66,7 +66,7 @@
|
||||||
//! // for a simpler implementation.
|
//! // for a simpler implementation.
|
||||||
//! fn shortest_path(adj_list: &Vec<Vec<Edge>>, start: uint, goal: uint) -> uint {
|
//! fn shortest_path(adj_list: &Vec<Vec<Edge>>, start: uint, goal: uint) -> uint {
|
||||||
//! // dist[node] = current shortest distance from `start` to `node`
|
//! // dist[node] = current shortest distance from `start` to `node`
|
||||||
//! let mut dist = Vec::from_elem(adj_list.len(), uint::MAX);
|
//! let mut dist: Vec<_> = range(0, adj_list.len()).map(|_| uint::MAX).collect();
|
||||||
//!
|
//!
|
||||||
//! let mut heap = BinaryHeap::new();
|
//! let mut heap = BinaryHeap::new();
|
||||||
//!
|
//!
|
||||||
|
|
|
@ -85,7 +85,7 @@ use core::prelude::*;
|
||||||
use core::cmp;
|
use core::cmp;
|
||||||
use core::default::Default;
|
use core::default::Default;
|
||||||
use core::fmt;
|
use core::fmt;
|
||||||
use core::iter::{Cloned, Chain, Enumerate, Repeat, Skip, Take};
|
use core::iter::{Cloned, Chain, Enumerate, Repeat, Skip, Take, repeat};
|
||||||
use core::iter;
|
use core::iter;
|
||||||
use core::num::Int;
|
use core::num::Int;
|
||||||
use core::slice::{Iter, IterMut};
|
use core::slice::{Iter, IterMut};
|
||||||
|
@ -267,7 +267,7 @@ impl Bitv {
|
||||||
pub fn from_elem(nbits: uint, bit: bool) -> Bitv {
|
pub fn from_elem(nbits: uint, bit: bool) -> Bitv {
|
||||||
let nblocks = blocks_for_bits(nbits);
|
let nblocks = blocks_for_bits(nbits);
|
||||||
let mut bitv = Bitv {
|
let mut bitv = Bitv {
|
||||||
storage: Vec::from_elem(nblocks, if bit { !0u32 } else { 0u32 }),
|
storage: repeat(if bit { !0u32 } else { 0u32 }).take(nblocks).collect(),
|
||||||
nbits: nbits
|
nbits: nbits
|
||||||
};
|
};
|
||||||
bitv.fix_last_block();
|
bitv.fix_last_block();
|
||||||
|
@ -651,7 +651,7 @@ impl Bitv {
|
||||||
|
|
||||||
let len = self.nbits/8 +
|
let len = self.nbits/8 +
|
||||||
if self.nbits % 8 == 0 { 0 } else { 1 };
|
if self.nbits % 8 == 0 { 0 } else { 1 };
|
||||||
Vec::from_fn(len, |i|
|
range(0, len).map(|i|
|
||||||
bit(self, i, 0) |
|
bit(self, i, 0) |
|
||||||
bit(self, i, 1) |
|
bit(self, i, 1) |
|
||||||
bit(self, i, 2) |
|
bit(self, i, 2) |
|
||||||
|
@ -660,7 +660,7 @@ impl Bitv {
|
||||||
bit(self, i, 5) |
|
bit(self, i, 5) |
|
||||||
bit(self, i, 6) |
|
bit(self, i, 6) |
|
||||||
bit(self, i, 7)
|
bit(self, i, 7)
|
||||||
)
|
).collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Deprecated: Use `iter().collect()`.
|
/// Deprecated: Use `iter().collect()`.
|
||||||
|
@ -834,7 +834,7 @@ impl Bitv {
|
||||||
// Allocate new words, if needed
|
// Allocate new words, if needed
|
||||||
if new_nblocks > self.storage.len() {
|
if new_nblocks > self.storage.len() {
|
||||||
let to_add = new_nblocks - self.storage.len();
|
let to_add = new_nblocks - self.storage.len();
|
||||||
self.storage.grow(to_add, full_value);
|
self.storage.extend(repeat(full_value).take(to_add));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Adjust internal bit count
|
// Adjust internal bit count
|
||||||
|
|
|
@ -555,10 +555,10 @@ impl <K, V> Node<K, V> {
|
||||||
let node = mem::replace(left_and_out, unsafe { Node::new_internal(capacity_from_b(b)) });
|
let node = mem::replace(left_and_out, unsafe { Node::new_internal(capacity_from_b(b)) });
|
||||||
left_and_out._len = 1;
|
left_and_out._len = 1;
|
||||||
unsafe {
|
unsafe {
|
||||||
ptr::write(left_and_out.keys_mut().unsafe_mut(0), key);
|
ptr::write(left_and_out.keys_mut().get_unchecked_mut(0), key);
|
||||||
ptr::write(left_and_out.vals_mut().unsafe_mut(0), value);
|
ptr::write(left_and_out.vals_mut().get_unchecked_mut(0), value);
|
||||||
ptr::write(left_and_out.edges_mut().unsafe_mut(0), node);
|
ptr::write(left_and_out.edges_mut().get_unchecked_mut(0), node);
|
||||||
ptr::write(left_and_out.edges_mut().unsafe_mut(1), right);
|
ptr::write(left_and_out.edges_mut().get_unchecked_mut(1), right);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -637,7 +637,7 @@ impl<'a, K: 'a, V: 'a> Handle<&'a Node<K, V>, handle::Edge, handle::Internal> {
|
||||||
/// making it more suitable for moving down a chain of nodes.
|
/// making it more suitable for moving down a chain of nodes.
|
||||||
pub fn into_edge(self) -> &'a Node<K, V> {
|
pub fn into_edge(self) -> &'a Node<K, V> {
|
||||||
unsafe {
|
unsafe {
|
||||||
self.node.edges().unsafe_get(self.index)
|
self.node.edges().get_unchecked(self.index)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -648,7 +648,7 @@ impl<'a, K: 'a, V: 'a> Handle<&'a mut Node<K, V>, handle::Edge, handle::Internal
|
||||||
/// `edge_mut`, making it more suitable for moving down a chain of nodes.
|
/// `edge_mut`, making it more suitable for moving down a chain of nodes.
|
||||||
pub fn into_edge_mut(self) -> &'a mut Node<K, V> {
|
pub fn into_edge_mut(self) -> &'a mut Node<K, V> {
|
||||||
unsafe {
|
unsafe {
|
||||||
self.node.edges_mut().unsafe_mut(self.index)
|
self.node.edges_mut().get_unchecked_mut(self.index)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -722,7 +722,7 @@ impl<K, V, NodeRef: DerefMut<Node<K, V>>> Handle<NodeRef, handle::Edge, handle::
|
||||||
/// confused with `node`, which references the parent node of what is returned here.
|
/// confused with `node`, which references the parent node of what is returned here.
|
||||||
pub fn edge_mut(&mut self) -> &mut Node<K, V> {
|
pub fn edge_mut(&mut self) -> &mut Node<K, V> {
|
||||||
unsafe {
|
unsafe {
|
||||||
self.node.edges_mut().unsafe_mut(self.index)
|
self.node.edges_mut().get_unchecked_mut(self.index)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -830,8 +830,8 @@ impl<'a, K: 'a, V: 'a, NodeType> Handle<&'a Node<K, V>, handle::KV, NodeType> {
|
||||||
let (keys, vals) = self.node.as_slices();
|
let (keys, vals) = self.node.as_slices();
|
||||||
unsafe {
|
unsafe {
|
||||||
(
|
(
|
||||||
keys.unsafe_get(self.index),
|
keys.get_unchecked(self.index),
|
||||||
vals.unsafe_get(self.index)
|
vals.get_unchecked(self.index)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -845,8 +845,8 @@ impl<'a, K: 'a, V: 'a, NodeType> Handle<&'a mut Node<K, V>, handle::KV, NodeType
|
||||||
let (keys, vals) = self.node.as_slices_mut();
|
let (keys, vals) = self.node.as_slices_mut();
|
||||||
unsafe {
|
unsafe {
|
||||||
(
|
(
|
||||||
keys.unsafe_mut(self.index),
|
keys.get_unchecked_mut(self.index),
|
||||||
vals.unsafe_mut(self.index)
|
vals.get_unchecked_mut(self.index)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -870,14 +870,14 @@ impl<'a, K: 'a, V: 'a, NodeRef: Deref<Node<K, V>> + 'a, NodeType> Handle<NodeRef
|
||||||
// /// reference with a lifetime as large as `into_kv_mut`, but it also does not consume the
|
// /// reference with a lifetime as large as `into_kv_mut`, but it also does not consume the
|
||||||
// /// handle.
|
// /// handle.
|
||||||
// pub fn key(&'a self) -> &'a K {
|
// pub fn key(&'a self) -> &'a K {
|
||||||
// unsafe { self.node.keys().unsafe_get(self.index) }
|
// unsafe { self.node.keys().get_unchecked(self.index) }
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// /// Returns a reference to the value pointed-to by this handle. This doesn't return a
|
// /// Returns a reference to the value pointed-to by this handle. This doesn't return a
|
||||||
// /// reference with a lifetime as large as `into_kv_mut`, but it also does not consume the
|
// /// reference with a lifetime as large as `into_kv_mut`, but it also does not consume the
|
||||||
// /// handle.
|
// /// handle.
|
||||||
// pub fn val(&'a self) -> &'a V {
|
// pub fn val(&'a self) -> &'a V {
|
||||||
// unsafe { self.node.vals().unsafe_get(self.index) }
|
// unsafe { self.node.vals().get_unchecked(self.index) }
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -887,14 +887,14 @@ impl<'a, K: 'a, V: 'a, NodeRef: DerefMut<Node<K, V>> + 'a, NodeType> Handle<Node
|
||||||
/// reference with a lifetime as large as `into_kv_mut`, but it also does not consume the
|
/// reference with a lifetime as large as `into_kv_mut`, but it also does not consume the
|
||||||
/// handle.
|
/// handle.
|
||||||
pub fn key_mut(&'a mut self) -> &'a mut K {
|
pub fn key_mut(&'a mut self) -> &'a mut K {
|
||||||
unsafe { self.node.keys_mut().unsafe_mut(self.index) }
|
unsafe { self.node.keys_mut().get_unchecked_mut(self.index) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a mutable reference to the value pointed-to by this handle. This doesn't return a
|
/// Returns a mutable reference to the value pointed-to by this handle. This doesn't return a
|
||||||
/// reference with a lifetime as large as `into_kv_mut`, but it also does not consume the
|
/// reference with a lifetime as large as `into_kv_mut`, but it also does not consume the
|
||||||
/// handle.
|
/// handle.
|
||||||
pub fn val_mut(&'a mut self) -> &'a mut V {
|
pub fn val_mut(&'a mut self) -> &'a mut V {
|
||||||
unsafe { self.node.vals_mut().unsafe_mut(self.index) }
|
unsafe { self.node.vals_mut().get_unchecked_mut(self.index) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1078,7 +1078,7 @@ impl<K, V> Node<K, V> {
|
||||||
debug_assert!(!self.is_leaf());
|
debug_assert!(!self.is_leaf());
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
let ret = ptr::read(self.edges().unsafe_get(0));
|
let ret = ptr::read(self.edges().get_unchecked(0));
|
||||||
self.destroy();
|
self.destroy();
|
||||||
ptr::write(self, ret);
|
ptr::write(self, ret);
|
||||||
}
|
}
|
||||||
|
@ -1092,8 +1092,8 @@ impl<K, V> Node<K, V> {
|
||||||
unsafe fn push_kv(&mut self, key: K, val: V) {
|
unsafe fn push_kv(&mut self, key: K, val: V) {
|
||||||
let len = self.len();
|
let len = self.len();
|
||||||
|
|
||||||
ptr::write(self.keys_mut().unsafe_mut(len), key);
|
ptr::write(self.keys_mut().get_unchecked_mut(len), key);
|
||||||
ptr::write(self.vals_mut().unsafe_mut(len), val);
|
ptr::write(self.vals_mut().get_unchecked_mut(len), val);
|
||||||
|
|
||||||
self._len += 1;
|
self._len += 1;
|
||||||
}
|
}
|
||||||
|
@ -1103,7 +1103,7 @@ impl<K, V> Node<K, V> {
|
||||||
unsafe fn push_edge(&mut self, edge: Node<K, V>) {
|
unsafe fn push_edge(&mut self, edge: Node<K, V>) {
|
||||||
let len = self.len();
|
let len = self.len();
|
||||||
|
|
||||||
ptr::write(self.edges_mut().unsafe_mut(len), edge);
|
ptr::write(self.edges_mut().get_unchecked_mut(len), edge);
|
||||||
}
|
}
|
||||||
|
|
||||||
// This must be followed by insert_edge on an internal node.
|
// This must be followed by insert_edge on an internal node.
|
||||||
|
@ -1120,12 +1120,12 @@ impl<K, V> Node<K, V> {
|
||||||
self.len() - index
|
self.len() - index
|
||||||
);
|
);
|
||||||
|
|
||||||
ptr::write(self.keys_mut().unsafe_mut(index), key);
|
ptr::write(self.keys_mut().get_unchecked_mut(index), key);
|
||||||
ptr::write(self.vals_mut().unsafe_mut(index), val);
|
ptr::write(self.vals_mut().get_unchecked_mut(index), val);
|
||||||
|
|
||||||
self._len += 1;
|
self._len += 1;
|
||||||
|
|
||||||
self.vals_mut().unsafe_mut(index)
|
self.vals_mut().get_unchecked_mut(index)
|
||||||
}
|
}
|
||||||
|
|
||||||
// This can only be called immediately after a call to insert_kv.
|
// This can only be called immediately after a call to insert_kv.
|
||||||
|
@ -1136,14 +1136,14 @@ impl<K, V> Node<K, V> {
|
||||||
self.edges().as_ptr().offset(index as int),
|
self.edges().as_ptr().offset(index as int),
|
||||||
self.len() - index
|
self.len() - index
|
||||||
);
|
);
|
||||||
ptr::write(self.edges_mut().unsafe_mut(index), edge);
|
ptr::write(self.edges_mut().get_unchecked_mut(index), edge);
|
||||||
}
|
}
|
||||||
|
|
||||||
// This must be followed by pop_edge on an internal node.
|
// This must be followed by pop_edge on an internal node.
|
||||||
#[inline]
|
#[inline]
|
||||||
unsafe fn pop_kv(&mut self) -> (K, V) {
|
unsafe fn pop_kv(&mut self) -> (K, V) {
|
||||||
let key = ptr::read(self.keys().unsafe_get(self.len() - 1));
|
let key = ptr::read(self.keys().get_unchecked(self.len() - 1));
|
||||||
let val = ptr::read(self.vals().unsafe_get(self.len() - 1));
|
let val = ptr::read(self.vals().get_unchecked(self.len() - 1));
|
||||||
|
|
||||||
self._len -= 1;
|
self._len -= 1;
|
||||||
|
|
||||||
|
@ -1153,7 +1153,7 @@ impl<K, V> Node<K, V> {
|
||||||
// This can only be called immediately after a call to pop_kv.
|
// This can only be called immediately after a call to pop_kv.
|
||||||
#[inline]
|
#[inline]
|
||||||
unsafe fn pop_edge(&mut self) -> Node<K, V> {
|
unsafe fn pop_edge(&mut self) -> Node<K, V> {
|
||||||
let edge = ptr::read(self.edges().unsafe_get(self.len() + 1));
|
let edge = ptr::read(self.edges().get_unchecked(self.len() + 1));
|
||||||
|
|
||||||
edge
|
edge
|
||||||
}
|
}
|
||||||
|
@ -1161,8 +1161,8 @@ impl<K, V> Node<K, V> {
|
||||||
// This must be followed by remove_edge on an internal node.
|
// This must be followed by remove_edge on an internal node.
|
||||||
#[inline]
|
#[inline]
|
||||||
unsafe fn remove_kv(&mut self, index: uint) -> (K, V) {
|
unsafe fn remove_kv(&mut self, index: uint) -> (K, V) {
|
||||||
let key = ptr::read(self.keys().unsafe_get(index));
|
let key = ptr::read(self.keys().get_unchecked(index));
|
||||||
let val = ptr::read(self.vals().unsafe_get(index));
|
let val = ptr::read(self.vals().get_unchecked(index));
|
||||||
|
|
||||||
ptr::copy_memory(
|
ptr::copy_memory(
|
||||||
self.keys_mut().as_mut_ptr().offset(index as int),
|
self.keys_mut().as_mut_ptr().offset(index as int),
|
||||||
|
@ -1183,7 +1183,7 @@ impl<K, V> Node<K, V> {
|
||||||
// This can only be called immediately after a call to remove_kv.
|
// This can only be called immediately after a call to remove_kv.
|
||||||
#[inline]
|
#[inline]
|
||||||
unsafe fn remove_edge(&mut self, index: uint) -> Node<K, V> {
|
unsafe fn remove_edge(&mut self, index: uint) -> Node<K, V> {
|
||||||
let edge = ptr::read(self.edges().unsafe_get(index));
|
let edge = ptr::read(self.edges().get_unchecked(index));
|
||||||
|
|
||||||
ptr::copy_memory(
|
ptr::copy_memory(
|
||||||
self.edges_mut().as_mut_ptr().offset(index as int),
|
self.edges_mut().as_mut_ptr().offset(index as int),
|
||||||
|
@ -1230,8 +1230,8 @@ impl<K, V> Node<K, V> {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
let key = ptr::read(self.keys().unsafe_get(right_offset - 1));
|
let key = ptr::read(self.keys().get_unchecked(right_offset - 1));
|
||||||
let val = ptr::read(self.vals().unsafe_get(right_offset - 1));
|
let val = ptr::read(self.vals().get_unchecked(right_offset - 1));
|
||||||
|
|
||||||
self._len = right_offset - 1;
|
self._len = right_offset - 1;
|
||||||
|
|
||||||
|
@ -1250,8 +1250,8 @@ impl<K, V> Node<K, V> {
|
||||||
let old_len = self.len();
|
let old_len = self.len();
|
||||||
self._len += right.len() + 1;
|
self._len += right.len() + 1;
|
||||||
|
|
||||||
ptr::write(self.keys_mut().unsafe_mut(old_len), key);
|
ptr::write(self.keys_mut().get_unchecked_mut(old_len), key);
|
||||||
ptr::write(self.vals_mut().unsafe_mut(old_len), val);
|
ptr::write(self.vals_mut().get_unchecked_mut(old_len), val);
|
||||||
|
|
||||||
ptr::copy_nonoverlapping_memory(
|
ptr::copy_nonoverlapping_memory(
|
||||||
self.keys_mut().as_mut_ptr().offset(old_len as int + 1),
|
self.keys_mut().as_mut_ptr().offset(old_len as int + 1),
|
||||||
|
|
|
@ -1294,8 +1294,10 @@ mod tests {
|
||||||
v.pop();
|
v.pop();
|
||||||
}
|
}
|
||||||
1 => {
|
1 => {
|
||||||
m.pop_front();
|
if !v.is_empty() {
|
||||||
v.remove(0);
|
m.pop_front();
|
||||||
|
v.remove(0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
2 | 4 => {
|
2 | 4 => {
|
||||||
m.push_front(-i);
|
m.push_front(-i);
|
||||||
|
|
|
@ -128,8 +128,8 @@ mod prelude {
|
||||||
pub use unicode::char::UnicodeChar;
|
pub use unicode::char::UnicodeChar;
|
||||||
|
|
||||||
// from collections.
|
// from collections.
|
||||||
pub use slice::{CloneSliceExt, VectorVector};
|
pub use slice::{CloneSliceExt, SliceConcatExt};
|
||||||
pub use str::{IntoMaybeOwned, StrVector};
|
pub use str::IntoMaybeOwned;
|
||||||
pub use string::{String, ToString};
|
pub use string::{String, ToString};
|
||||||
pub use vec::Vec;
|
pub use vec::Vec;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1154,7 +1154,7 @@ impl<'a, T> Iterator<&'a T> for Iter<'a, T> {
|
||||||
}
|
}
|
||||||
let tail = self.tail;
|
let tail = self.tail;
|
||||||
self.tail = wrap_index(self.tail + 1, self.ring.len());
|
self.tail = wrap_index(self.tail + 1, self.ring.len());
|
||||||
unsafe { Some(self.ring.unsafe_get(tail)) }
|
unsafe { Some(self.ring.get_unchecked(tail)) }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -1171,7 +1171,7 @@ impl<'a, T> DoubleEndedIterator<&'a T> for Iter<'a, T> {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
self.head = wrap_index(self.head - 1, self.ring.len());
|
self.head = wrap_index(self.head - 1, self.ring.len());
|
||||||
unsafe { Some(self.ring.unsafe_get(self.head)) }
|
unsafe { Some(self.ring.get_unchecked(self.head)) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1190,7 +1190,7 @@ impl<'a, T> RandomAccessIterator<&'a T> for Iter<'a, T> {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
let idx = wrap_index(self.tail + j, self.ring.len());
|
let idx = wrap_index(self.tail + j, self.ring.len());
|
||||||
unsafe { Some(self.ring.unsafe_get(idx)) }
|
unsafe { Some(self.ring.get_unchecked(idx)) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -77,6 +77,7 @@ use slice::SliceExt;
|
||||||
use string::String;
|
use string::String;
|
||||||
use unicode;
|
use unicode;
|
||||||
use vec::Vec;
|
use vec::Vec;
|
||||||
|
use slice::SliceConcatExt;
|
||||||
|
|
||||||
pub use core::str::{from_utf8, CharEq, Chars, CharIndices};
|
pub use core::str::{from_utf8, CharEq, Chars, CharIndices};
|
||||||
pub use core::str::{Bytes, CharSplits, is_utf8};
|
pub use core::str::{Bytes, CharSplits, is_utf8};
|
||||||
|
@ -93,71 +94,45 @@ pub use core::str::{SplitN, RSplitN};
|
||||||
Section: Creating a string
|
Section: Creating a string
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/// Methods for vectors of strings.
|
impl<S: Str> SliceConcatExt<str, String> for [S] {
|
||||||
#[unstable = "functionality may be replaced with iterators"]
|
|
||||||
pub trait StrVector for Sized? {
|
|
||||||
/// Concatenates a vector of strings.
|
|
||||||
///
|
|
||||||
/// # Examples
|
|
||||||
///
|
|
||||||
/// ```rust
|
|
||||||
/// let first = "Restaurant at the End of the".to_string();
|
|
||||||
/// let second = " Universe".to_string();
|
|
||||||
/// let string_vec = vec![first, second];
|
|
||||||
/// assert_eq!(string_vec.concat(), "Restaurant at the End of the Universe".to_string());
|
|
||||||
/// ```
|
|
||||||
fn concat(&self) -> String;
|
|
||||||
|
|
||||||
/// Concatenates a vector of strings, placing a given separator between each.
|
|
||||||
///
|
|
||||||
/// # Examples
|
|
||||||
///
|
|
||||||
/// ```rust
|
|
||||||
/// let first = "Roast".to_string();
|
|
||||||
/// let second = "Sirloin Steak".to_string();
|
|
||||||
/// let string_vec = vec![first, second];
|
|
||||||
/// assert_eq!(string_vec.connect(", "), "Roast, Sirloin Steak".to_string());
|
|
||||||
/// ```
|
|
||||||
fn connect(&self, sep: &str) -> String;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(deprecated)]
|
|
||||||
impl<S: Str> StrVector for [S] {
|
|
||||||
fn concat(&self) -> String {
|
fn concat(&self) -> String {
|
||||||
if self.is_empty() {
|
let s = self.as_slice();
|
||||||
|
|
||||||
|
if s.is_empty() {
|
||||||
return String::new();
|
return String::new();
|
||||||
}
|
}
|
||||||
|
|
||||||
// `len` calculation may overflow but push_str will check boundaries
|
// `len` calculation may overflow but push_str will check boundaries
|
||||||
let len = self.iter().map(|s| s.as_slice().len()).sum();
|
let len = s.iter().map(|s| s.as_slice().len()).sum();
|
||||||
|
|
||||||
let mut result = String::with_capacity(len);
|
let mut result = String::with_capacity(len);
|
||||||
|
|
||||||
for s in self.iter() {
|
for s in s.iter() {
|
||||||
result.push_str(s.as_slice());
|
result.push_str(s.as_slice())
|
||||||
}
|
}
|
||||||
|
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
fn connect(&self, sep: &str) -> String {
|
fn connect(&self, sep: &str) -> String {
|
||||||
if self.is_empty() {
|
let s = self.as_slice();
|
||||||
|
|
||||||
|
if s.is_empty() {
|
||||||
return String::new();
|
return String::new();
|
||||||
}
|
}
|
||||||
|
|
||||||
// concat is faster
|
// concat is faster
|
||||||
if sep.is_empty() {
|
if sep.is_empty() {
|
||||||
return self.concat();
|
return s.concat();
|
||||||
}
|
}
|
||||||
|
|
||||||
// this is wrong without the guarantee that `self` is non-empty
|
// this is wrong without the guarantee that `self` is non-empty
|
||||||
// `len` calculation may overflow but push_str but will check boundaries
|
// `len` calculation may overflow but push_str but will check boundaries
|
||||||
let len = sep.len() * (self.len() - 1)
|
let len = sep.len() * (s.len() - 1)
|
||||||
+ self.iter().map(|s| s.as_slice().len()).sum();
|
+ s.iter().map(|s| s.as_slice().len()).sum();
|
||||||
let mut result = String::with_capacity(len);
|
let mut result = String::with_capacity(len);
|
||||||
let mut first = true;
|
let mut first = true;
|
||||||
|
|
||||||
for s in self.iter() {
|
for s in s.iter() {
|
||||||
if first {
|
if first {
|
||||||
first = false;
|
first = false;
|
||||||
} else {
|
} else {
|
||||||
|
@ -169,18 +144,6 @@ impl<S: Str> StrVector for [S] {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S: Str, T: AsSlice<S>> StrVector for T {
|
|
||||||
#[inline]
|
|
||||||
fn concat(&self) -> String {
|
|
||||||
self.as_slice().concat()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn connect(&self, sep: &str) -> String {
|
|
||||||
self.as_slice().connect(sep)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Section: Iterators
|
Section: Iterators
|
||||||
*/
|
*/
|
||||||
|
@ -221,7 +184,7 @@ pub struct Decompositions<'a> {
|
||||||
impl<'a> Iterator<char> for Decompositions<'a> {
|
impl<'a> Iterator<char> for Decompositions<'a> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn next(&mut self) -> Option<char> {
|
fn next(&mut self) -> Option<char> {
|
||||||
match self.buffer.head() {
|
match self.buffer.first() {
|
||||||
Some(&(c, 0)) => {
|
Some(&(c, 0)) => {
|
||||||
self.sorted = false;
|
self.sorted = false;
|
||||||
self.buffer.remove(0);
|
self.buffer.remove(0);
|
||||||
|
@ -268,13 +231,16 @@ impl<'a> Iterator<char> for Decompositions<'a> {
|
||||||
self.sorted = true;
|
self.sorted = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
match self.buffer.remove(0) {
|
if self.buffer.is_empty() {
|
||||||
Some((c, 0)) => {
|
None
|
||||||
self.sorted = false;
|
} else {
|
||||||
Some(c)
|
match self.buffer.remove(0) {
|
||||||
|
(c, 0) => {
|
||||||
|
self.sorted = false;
|
||||||
|
Some(c)
|
||||||
|
}
|
||||||
|
(c, _) => Some(c),
|
||||||
}
|
}
|
||||||
Some((c, _)) => Some(c),
|
|
||||||
None => None
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -747,7 +713,7 @@ pub trait StrExt for Sized?: ops::Slice<uint, str> {
|
||||||
if me.is_empty() { return t.chars().count(); }
|
if me.is_empty() { return t.chars().count(); }
|
||||||
if t.is_empty() { return me.chars().count(); }
|
if t.is_empty() { return me.chars().count(); }
|
||||||
|
|
||||||
let mut dcol = Vec::from_fn(t.len() + 1, |x| x);
|
let mut dcol: Vec<_> = range(0, t.len() + 1).collect();
|
||||||
let mut t_last = 0;
|
let mut t_last = 0;
|
||||||
|
|
||||||
for (i, sc) in me.chars().enumerate() {
|
for (i, sc) in me.chars().enumerate() {
|
||||||
|
@ -1892,22 +1858,12 @@ mod tests {
|
||||||
assert_eq!("ะเทศไท", "ประเทศไทย中华Việt Nam".slice_chars(2, 8));
|
assert_eq!("ะเทศไท", "ประเทศไทย中华Việt Nam".slice_chars(2, 8));
|
||||||
}
|
}
|
||||||
|
|
||||||
struct S {
|
|
||||||
x: [String, .. 2]
|
|
||||||
}
|
|
||||||
|
|
||||||
impl AsSlice<String> for S {
|
|
||||||
fn as_slice<'a> (&'a self) -> &'a [String] {
|
|
||||||
&self.x
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn s(x: &str) -> String { x.into_string() }
|
fn s(x: &str) -> String { x.into_string() }
|
||||||
|
|
||||||
macro_rules! test_concat {
|
macro_rules! test_concat {
|
||||||
($expected: expr, $string: expr) => {
|
($expected: expr, $string: expr) => {
|
||||||
{
|
{
|
||||||
let s = $string.concat();
|
let s: String = $string.concat();
|
||||||
assert_eq!($expected, s);
|
assert_eq!($expected, s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1915,22 +1871,10 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_concat_for_different_types() {
|
fn test_concat_for_different_types() {
|
||||||
test_concat!("ab", ["a", "b"]);
|
test_concat!("ab", vec![s("a"), s("b")]);
|
||||||
test_concat!("ab", [s("a"), s("b")]);
|
|
||||||
test_concat!("ab", vec!["a", "b"]);
|
test_concat!("ab", vec!["a", "b"]);
|
||||||
test_concat!("ab", vec!["a", "b"].as_slice());
|
test_concat!("ab", vec!["a", "b"].as_slice());
|
||||||
test_concat!("ab", vec![s("a"), s("b")]);
|
test_concat!("ab", vec![s("a"), s("b")]);
|
||||||
|
|
||||||
let mut v0 = ["a", "b"];
|
|
||||||
let mut v1 = [s("a"), s("b")];
|
|
||||||
unsafe {
|
|
||||||
use std::c_vec::CVec;
|
|
||||||
|
|
||||||
test_concat!("ab", CVec::new(v0.as_mut_ptr(), v0.len()));
|
|
||||||
test_concat!("ab", CVec::new(v1.as_mut_ptr(), v1.len()));
|
|
||||||
}
|
|
||||||
|
|
||||||
test_concat!("ab", S { x: [s("a"), s("b")] });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -1959,17 +1903,6 @@ mod tests {
|
||||||
test_connect!("a-b", vec!["a", "b"], hyphen.as_slice());
|
test_connect!("a-b", vec!["a", "b"], hyphen.as_slice());
|
||||||
test_connect!("a-b", vec!["a", "b"].as_slice(), "-");
|
test_connect!("a-b", vec!["a", "b"].as_slice(), "-");
|
||||||
test_connect!("a-b", vec![s("a"), s("b")], "-");
|
test_connect!("a-b", vec![s("a"), s("b")], "-");
|
||||||
|
|
||||||
let mut v0 = ["a", "b"];
|
|
||||||
let mut v1 = [s("a"), s("b")];
|
|
||||||
unsafe {
|
|
||||||
use std::c_vec::CVec;
|
|
||||||
|
|
||||||
test_connect!("a-b", CVec::new(v0.as_mut_ptr(), v0.len()), "-");
|
|
||||||
test_connect!("a-b", CVec::new(v1.as_mut_ptr(), v1.len()), hyphen.as_slice());
|
|
||||||
}
|
|
||||||
|
|
||||||
test_connect!("a-b", S { x: [s("a"), s("b")] }, "-");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -3339,7 +3272,7 @@ mod tests {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod bench {
|
mod bench {
|
||||||
use super::*;
|
use super::*;
|
||||||
use prelude::{SliceExt, IteratorExt, DoubleEndedIteratorExt};
|
use prelude::{SliceExt, IteratorExt, DoubleEndedIteratorExt, SliceConcatExt};
|
||||||
use test::Bencher;
|
use test::Bencher;
|
||||||
use test::black_box;
|
use test::black_box;
|
||||||
|
|
||||||
|
@ -3502,7 +3435,7 @@ mod bench {
|
||||||
fn bench_connect(b: &mut Bencher) {
|
fn bench_connect(b: &mut Bencher) {
|
||||||
let s = "ศไทย中华Việt Nam; Mary had a little lamb, Little lamb";
|
let s = "ศไทย中华Việt Nam; Mary had a little lamb, Little lamb";
|
||||||
let sep = "→";
|
let sep = "→";
|
||||||
let v = [s, s, s, s, s, s, s, s, s, s];
|
let v = vec![s, s, s, s, s, s, s, s, s, s];
|
||||||
b.iter(|| {
|
b.iter(|| {
|
||||||
assert_eq!(v.connect(sep).len(), s.len() * 10 + sep.len() * 9);
|
assert_eq!(v.connect(sep).len(), s.len() * 10 + sep.len() * 9);
|
||||||
})
|
})
|
||||||
|
|
|
@ -151,7 +151,7 @@ impl String {
|
||||||
let mut i = 0;
|
let mut i = 0;
|
||||||
let total = v.len();
|
let total = v.len();
|
||||||
fn unsafe_get(xs: &[u8], i: uint) -> u8 {
|
fn unsafe_get(xs: &[u8], i: uint) -> u8 {
|
||||||
unsafe { *xs.unsafe_get(i) }
|
unsafe { *xs.get_unchecked(i) }
|
||||||
}
|
}
|
||||||
fn safe_get(xs: &[u8], i: uint, total: uint) -> u8 {
|
fn safe_get(xs: &[u8], i: uint, total: uint) -> u8 {
|
||||||
if i >= total {
|
if i >= total {
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -448,7 +448,7 @@ impl<V> VecMap<V> {
|
||||||
pub fn insert(&mut self, key: uint, value: V) -> Option<V> {
|
pub fn insert(&mut self, key: uint, value: V) -> Option<V> {
|
||||||
let len = self.v.len();
|
let len = self.v.len();
|
||||||
if len <= key {
|
if len <= key {
|
||||||
self.v.grow_fn(key - len + 1, |_| None);
|
self.v.extend(range(0, key - len + 1).map(|_| None));
|
||||||
}
|
}
|
||||||
replace(&mut self.v[key], Some(value))
|
replace(&mut self.v[key], Some(value))
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,6 +59,7 @@ pub use self::MinMaxResult::*;
|
||||||
use clone::Clone;
|
use clone::Clone;
|
||||||
use cmp;
|
use cmp;
|
||||||
use cmp::Ord;
|
use cmp::Ord;
|
||||||
|
use default::Default;
|
||||||
use mem;
|
use mem;
|
||||||
use num::{ToPrimitive, Int};
|
use num::{ToPrimitive, Int};
|
||||||
use ops::{Add, Deref, FnMut};
|
use ops::{Add, Deref, FnMut};
|
||||||
|
@ -68,20 +69,6 @@ use uint;
|
||||||
|
|
||||||
#[deprecated = "renamed to Extend"] pub use self::Extend as Extendable;
|
#[deprecated = "renamed to Extend"] pub use self::Extend as Extendable;
|
||||||
|
|
||||||
/// Conversion from an `Iterator`
|
|
||||||
#[unstable = "may be replaced by a more general conversion trait"]
|
|
||||||
pub trait FromIterator<A> {
|
|
||||||
/// Build a container with elements from an external iterator.
|
|
||||||
fn from_iter<T: Iterator<A>>(iterator: T) -> Self;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A type growable from an `Iterator` implementation
|
|
||||||
#[unstable = "just renamed as part of collections reform"]
|
|
||||||
pub trait Extend<A> {
|
|
||||||
/// Extend a container with the elements yielded by an arbitrary iterator
|
|
||||||
fn extend<T: Iterator<A>>(&mut self, iterator: T);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// An interface for dealing with "external iterators". These types of iterators
|
/// An interface for dealing with "external iterators". These types of iterators
|
||||||
/// can be resumed at any time as all state is stored internally as opposed to
|
/// can be resumed at any time as all state is stored internally as opposed to
|
||||||
/// being located on the call stack.
|
/// being located on the call stack.
|
||||||
|
@ -106,6 +93,20 @@ pub trait Iterator<A> {
|
||||||
fn size_hint(&self) -> (uint, Option<uint>) { (0, None) }
|
fn size_hint(&self) -> (uint, Option<uint>) { (0, None) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Conversion from an `Iterator`
|
||||||
|
#[unstable = "may be replaced by a more general conversion trait"]
|
||||||
|
pub trait FromIterator<A> {
|
||||||
|
/// Build a container with elements from an external iterator.
|
||||||
|
fn from_iter<T: Iterator<A>>(iterator: T) -> Self;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A type growable from an `Iterator` implementation
|
||||||
|
#[unstable = "just renamed as part of collections reform"]
|
||||||
|
pub trait Extend<A> {
|
||||||
|
/// Extend a container with the elements yielded by an arbitrary iterator
|
||||||
|
fn extend<T: Iterator<A>>(&mut self, iterator: T);
|
||||||
|
}
|
||||||
|
|
||||||
#[unstable = "new convention for extension traits"]
|
#[unstable = "new convention for extension traits"]
|
||||||
/// An extension trait providing numerous methods applicable to all iterators.
|
/// An extension trait providing numerous methods applicable to all iterators.
|
||||||
pub trait IteratorExt<A>: Iterator<A> {
|
pub trait IteratorExt<A>: Iterator<A> {
|
||||||
|
@ -223,7 +224,6 @@ pub trait IteratorExt<A>: Iterator<A> {
|
||||||
Enumerate{iter: self, count: 0}
|
Enumerate{iter: self, count: 0}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Creates an iterator that has a `.peek()` method
|
/// Creates an iterator that has a `.peek()` method
|
||||||
/// that returns an optional reference to the next element.
|
/// that returns an optional reference to the next element.
|
||||||
///
|
///
|
||||||
|
@ -471,6 +471,35 @@ pub trait IteratorExt<A>: Iterator<A> {
|
||||||
FromIterator::from_iter(self)
|
FromIterator::from_iter(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Loops through the entire iterator, collecting all of the elements into
|
||||||
|
/// one of two containers, depending on a predicate. The elements of the
|
||||||
|
/// first container satisfy the predicate, while the elements of the second
|
||||||
|
/// do not.
|
||||||
|
///
|
||||||
|
/// ```
|
||||||
|
/// let vec = vec![1i, 2i, 3i, 4i];
|
||||||
|
/// let (even, odd): (Vec<int>, Vec<int>) = vec.into_iter().partition(|&n| n % 2 == 0);
|
||||||
|
/// assert_eq!(even, vec![2, 4]);
|
||||||
|
/// assert_eq!(odd, vec![1, 3]);
|
||||||
|
/// ```
|
||||||
|
#[unstable = "recently added as part of collections reform"]
|
||||||
|
fn partition<B, F>(mut self, mut f: F) -> (B, B) where
|
||||||
|
B: Default + Extend<A>, F: FnMut(&A) -> bool
|
||||||
|
{
|
||||||
|
let mut left: B = Default::default();
|
||||||
|
let mut right: B = Default::default();
|
||||||
|
|
||||||
|
for x in self {
|
||||||
|
if f(&x) {
|
||||||
|
left.extend(Some(x).into_iter())
|
||||||
|
} else {
|
||||||
|
right.extend(Some(x).into_iter())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
(left, right)
|
||||||
|
}
|
||||||
|
|
||||||
/// Loops through `n` iterations, returning the `n`th element of the
|
/// Loops through `n` iterations, returning the `n`th element of the
|
||||||
/// iterator.
|
/// iterator.
|
||||||
///
|
///
|
||||||
|
@ -661,6 +690,42 @@ pub trait IteratorExt<A>: Iterator<A> {
|
||||||
#[unstable = "trait is unstable"]
|
#[unstable = "trait is unstable"]
|
||||||
impl<A, I> IteratorExt<A> for I where I: Iterator<A> {}
|
impl<A, I> IteratorExt<A> for I where I: Iterator<A> {}
|
||||||
|
|
||||||
|
/// Extention trait for iterators of pairs.
|
||||||
|
#[unstable = "newly added trait, likely to be merged with IteratorExt"]
|
||||||
|
pub trait IteratorPairExt<A, B>: Iterator<(A, B)> {
|
||||||
|
/// Converts an iterator of pairs into a pair of containers.
|
||||||
|
///
|
||||||
|
/// Loops through the entire iterator, collecting the first component of
|
||||||
|
/// each item into one new container, and the second component into another.
|
||||||
|
fn unzip<FromA, FromB>(mut self) -> (FromA, FromB) where
|
||||||
|
FromA: Default + Extend<A>, FromB: Default + Extend<B>
|
||||||
|
{
|
||||||
|
struct SizeHint<A>(uint, Option<uint>);
|
||||||
|
impl<A> Iterator<A> for SizeHint<A> {
|
||||||
|
fn next(&mut self) -> Option<A> { None }
|
||||||
|
fn size_hint(&self) -> (uint, Option<uint>) {
|
||||||
|
(self.0, self.1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let (lo, hi) = self.size_hint();
|
||||||
|
let mut ts: FromA = Default::default();
|
||||||
|
let mut us: FromB = Default::default();
|
||||||
|
|
||||||
|
ts.extend(SizeHint(lo, hi));
|
||||||
|
us.extend(SizeHint(lo, hi));
|
||||||
|
|
||||||
|
for (t, u) in self {
|
||||||
|
ts.extend(Some(t).into_iter());
|
||||||
|
us.extend(Some(u).into_iter());
|
||||||
|
}
|
||||||
|
|
||||||
|
(ts, us)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<A, B, I> IteratorPairExt<A, B> for I where I: Iterator<(A, B)> {}
|
||||||
|
|
||||||
/// A range iterator able to yield elements from both ends
|
/// A range iterator able to yield elements from both ends
|
||||||
///
|
///
|
||||||
/// A `DoubleEndedIterator` can be thought of as a deque in that `next()` and `next_back()` exhaust
|
/// A `DoubleEndedIterator` can be thought of as a deque in that `next()` and `next_back()` exhaust
|
||||||
|
|
|
@ -52,7 +52,7 @@ pub use cmp::{Ordering, Equiv};
|
||||||
pub use cmp::Ordering::{Less, Equal, Greater};
|
pub use cmp::Ordering::{Less, Equal, Greater};
|
||||||
pub use iter::{FromIterator, Extend, IteratorExt};
|
pub use iter::{FromIterator, Extend, IteratorExt};
|
||||||
pub use iter::{Iterator, DoubleEndedIterator, DoubleEndedIteratorExt, RandomAccessIterator};
|
pub use iter::{Iterator, DoubleEndedIterator, DoubleEndedIteratorExt, RandomAccessIterator};
|
||||||
pub use iter::{IteratorCloneExt, CloneIteratorExt};
|
pub use iter::{IteratorCloneExt, CloneIteratorExt, IteratorPairExt};
|
||||||
pub use iter::{IteratorOrdExt, MutableDoubleEndedIterator, ExactSizeIterator};
|
pub use iter::{IteratorOrdExt, MutableDoubleEndedIterator, ExactSizeIterator};
|
||||||
pub use num::{ToPrimitive, FromPrimitive};
|
pub use num::{ToPrimitive, FromPrimitive};
|
||||||
pub use option::Option;
|
pub use option::Option;
|
||||||
|
|
|
@ -46,6 +46,8 @@ use num::Int;
|
||||||
use ops::{FnMut, mod};
|
use ops::{FnMut, mod};
|
||||||
use option::Option;
|
use option::Option;
|
||||||
use option::Option::{None, Some};
|
use option::Option::{None, Some};
|
||||||
|
use result::Result;
|
||||||
|
use result::Result::{Ok, Err};
|
||||||
use ptr;
|
use ptr;
|
||||||
use ptr::PtrExt;
|
use ptr::PtrExt;
|
||||||
use mem;
|
use mem;
|
||||||
|
@ -68,23 +70,23 @@ pub trait SliceExt<T> for Sized? {
|
||||||
fn slice_to<'a>(&'a self, end: uint) -> &'a [T];
|
fn slice_to<'a>(&'a self, end: uint) -> &'a [T];
|
||||||
fn split_at<'a>(&'a self, mid: uint) -> (&'a [T], &'a [T]);
|
fn split_at<'a>(&'a self, mid: uint) -> (&'a [T], &'a [T]);
|
||||||
fn iter<'a>(&'a self) -> Iter<'a, T>;
|
fn iter<'a>(&'a self) -> Iter<'a, T>;
|
||||||
fn split<'a, P>(&'a self, pred: P) -> Splits<'a, T, P>
|
fn split<'a, P>(&'a self, pred: P) -> Split<'a, T, P>
|
||||||
where P: FnMut(&T) -> bool;
|
where P: FnMut(&T) -> bool;
|
||||||
fn splitn<'a, P>(&'a self, n: uint, pred: P) -> SplitsN<Splits<'a, T, P>>
|
fn splitn<'a, P>(&'a self, n: uint, pred: P) -> SplitN<'a, T, P>
|
||||||
where P: FnMut(&T) -> bool;
|
where P: FnMut(&T) -> bool;
|
||||||
fn rsplitn<'a, P>(&'a self, n: uint, pred: P) -> SplitsN<Splits<'a, T, P>>
|
fn rsplitn<'a, P>(&'a self, n: uint, pred: P) -> RSplitN<'a, T, P>
|
||||||
where P: FnMut(&T) -> bool;
|
where P: FnMut(&T) -> bool;
|
||||||
fn windows<'a>(&'a self, size: uint) -> Windows<'a, T>;
|
fn windows<'a>(&'a self, size: uint) -> Windows<'a, T>;
|
||||||
fn chunks<'a>(&'a self, size: uint) -> Chunks<'a, T>;
|
fn chunks<'a>(&'a self, size: uint) -> Chunks<'a, T>;
|
||||||
fn get<'a>(&'a self, index: uint) -> Option<&'a T>;
|
fn get<'a>(&'a self, index: uint) -> Option<&'a T>;
|
||||||
fn head<'a>(&'a self) -> Option<&'a T>;
|
fn first<'a>(&'a self) -> Option<&'a T>;
|
||||||
fn tail<'a>(&'a self) -> &'a [T];
|
fn tail<'a>(&'a self) -> &'a [T];
|
||||||
fn init<'a>(&'a self) -> &'a [T];
|
fn init<'a>(&'a self) -> &'a [T];
|
||||||
fn last<'a>(&'a self) -> Option<&'a T>;
|
fn last<'a>(&'a self) -> Option<&'a T>;
|
||||||
unsafe fn unsafe_get<'a>(&'a self, index: uint) -> &'a T;
|
unsafe fn get_unchecked<'a>(&'a self, index: uint) -> &'a T;
|
||||||
fn as_ptr(&self) -> *const T;
|
fn as_ptr(&self) -> *const T;
|
||||||
fn binary_search<F>(&self, f: F) -> BinarySearchResult
|
fn binary_search_by<F>(&self, f: F) -> Result<uint, uint> where
|
||||||
where F: FnMut(&T) -> Ordering;
|
F: FnMut(&T) -> Ordering;
|
||||||
fn len(&self) -> uint;
|
fn len(&self) -> uint;
|
||||||
fn is_empty(&self) -> bool { self.len() == 0 }
|
fn is_empty(&self) -> bool { self.len() == 0 }
|
||||||
fn get_mut<'a>(&'a mut self, index: uint) -> Option<&'a mut T>;
|
fn get_mut<'a>(&'a mut self, index: uint) -> Option<&'a mut T>;
|
||||||
|
@ -93,21 +95,21 @@ pub trait SliceExt<T> for Sized? {
|
||||||
fn slice_from_mut<'a>(&'a mut self, start: uint) -> &'a mut [T];
|
fn slice_from_mut<'a>(&'a mut self, start: uint) -> &'a mut [T];
|
||||||
fn slice_to_mut<'a>(&'a mut self, end: uint) -> &'a mut [T];
|
fn slice_to_mut<'a>(&'a mut self, end: uint) -> &'a mut [T];
|
||||||
fn iter_mut<'a>(&'a mut self) -> IterMut<'a, T>;
|
fn iter_mut<'a>(&'a mut self) -> IterMut<'a, T>;
|
||||||
fn head_mut<'a>(&'a mut self) -> Option<&'a mut T>;
|
fn first_mut<'a>(&'a mut self) -> Option<&'a mut T>;
|
||||||
fn tail_mut<'a>(&'a mut self) -> &'a mut [T];
|
fn tail_mut<'a>(&'a mut self) -> &'a mut [T];
|
||||||
fn init_mut<'a>(&'a mut self) -> &'a mut [T];
|
fn init_mut<'a>(&'a mut self) -> &'a mut [T];
|
||||||
fn last_mut<'a>(&'a mut self) -> Option<&'a mut T>;
|
fn last_mut<'a>(&'a mut self) -> Option<&'a mut T>;
|
||||||
fn split_mut<'a, P>(&'a mut self, pred: P) -> MutSplits<'a, T, P>
|
fn split_mut<'a, P>(&'a mut self, pred: P) -> SplitMut<'a, T, P>
|
||||||
where P: FnMut(&T) -> bool;
|
where P: FnMut(&T) -> bool;
|
||||||
fn splitn_mut<P>(&mut self, n: uint, pred: P) -> SplitsN<MutSplits<T, P>>
|
fn splitn_mut<P>(&mut self, n: uint, pred: P) -> SplitNMut<T, P>
|
||||||
where P: FnMut(&T) -> bool;
|
where P: FnMut(&T) -> bool;
|
||||||
fn rsplitn_mut<P>(&mut self, n: uint, pred: P) -> SplitsN<MutSplits<T, P>>
|
fn rsplitn_mut<P>(&mut self, n: uint, pred: P) -> RSplitNMut<T, P>
|
||||||
where P: FnMut(&T) -> bool;
|
where P: FnMut(&T) -> bool;
|
||||||
fn chunks_mut<'a>(&'a mut self, chunk_size: uint) -> MutChunks<'a, T>;
|
fn chunks_mut<'a>(&'a mut self, chunk_size: uint) -> ChunksMut<'a, T>;
|
||||||
fn swap(&mut self, a: uint, b: uint);
|
fn swap(&mut self, a: uint, b: uint);
|
||||||
fn split_at_mut<'a>(&'a mut self, mid: uint) -> (&'a mut [T], &'a mut [T]);
|
fn split_at_mut<'a>(&'a mut self, mid: uint) -> (&'a mut [T], &'a mut [T]);
|
||||||
fn reverse(&mut self);
|
fn reverse(&mut self);
|
||||||
unsafe fn unsafe_mut<'a>(&'a mut self, index: uint) -> &'a mut T;
|
unsafe fn get_unchecked_mut<'a>(&'a mut self, index: uint) -> &'a mut T;
|
||||||
fn as_mut_ptr(&mut self) -> *mut T;
|
fn as_mut_ptr(&mut self) -> *mut T;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -145,11 +147,11 @@ impl<T> SliceExt<T> for [T] {
|
||||||
unsafe {
|
unsafe {
|
||||||
let p = self.as_ptr();
|
let p = self.as_ptr();
|
||||||
if mem::size_of::<T>() == 0 {
|
if mem::size_of::<T>() == 0 {
|
||||||
Iter{ptr: p,
|
Iter {ptr: p,
|
||||||
end: (p as uint + self.len()) as *const T,
|
end: (p as uint + self.len()) as *const T,
|
||||||
marker: marker::ContravariantLifetime::<'a>}
|
marker: marker::ContravariantLifetime::<'a>}
|
||||||
} else {
|
} else {
|
||||||
Iter{ptr: p,
|
Iter {ptr: p,
|
||||||
end: p.offset(self.len() as int),
|
end: p.offset(self.len() as int),
|
||||||
marker: marker::ContravariantLifetime::<'a>}
|
marker: marker::ContravariantLifetime::<'a>}
|
||||||
}
|
}
|
||||||
|
@ -157,8 +159,8 @@ impl<T> SliceExt<T> for [T] {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn split<'a, P>(&'a self, pred: P) -> Splits<'a, T, P> where P: FnMut(&T) -> bool {
|
fn split<'a, P>(&'a self, pred: P) -> Split<'a, T, P> where P: FnMut(&T) -> bool {
|
||||||
Splits {
|
Split {
|
||||||
v: self,
|
v: self,
|
||||||
pred: pred,
|
pred: pred,
|
||||||
finished: false
|
finished: false
|
||||||
|
@ -166,24 +168,28 @@ impl<T> SliceExt<T> for [T] {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn splitn<'a, P>(&'a self, n: uint, pred: P) -> SplitsN<Splits<'a, T, P>> where
|
fn splitn<'a, P>(&'a self, n: uint, pred: P) -> SplitN<'a, T, P> where
|
||||||
P: FnMut(&T) -> bool,
|
P: FnMut(&T) -> bool,
|
||||||
{
|
{
|
||||||
SplitsN {
|
SplitN {
|
||||||
iter: self.split(pred),
|
inner: GenericSplitN {
|
||||||
count: n,
|
iter: self.split(pred),
|
||||||
invert: false
|
count: n,
|
||||||
|
invert: false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn rsplitn<'a, P>(&'a self, n: uint, pred: P) -> SplitsN<Splits<'a, T, P>> where
|
fn rsplitn<'a, P>(&'a self, n: uint, pred: P) -> RSplitN<'a, T, P> where
|
||||||
P: FnMut(&T) -> bool,
|
P: FnMut(&T) -> bool,
|
||||||
{
|
{
|
||||||
SplitsN {
|
RSplitN {
|
||||||
iter: self.split(pred),
|
inner: GenericSplitN {
|
||||||
count: n,
|
iter: self.split(pred),
|
||||||
invert: true
|
count: n,
|
||||||
|
invert: true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -205,7 +211,7 @@ impl<T> SliceExt<T> for [T] {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn head(&self) -> Option<&T> {
|
fn first(&self) -> Option<&T> {
|
||||||
if self.len() == 0 { None } else { Some(&self[0]) }
|
if self.len() == 0 { None } else { Some(&self[0]) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -223,7 +229,7 @@ impl<T> SliceExt<T> for [T] {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
unsafe fn unsafe_get(&self, index: uint) -> &T {
|
unsafe fn get_unchecked(&self, index: uint) -> &T {
|
||||||
transmute(self.repr().data.offset(index as int))
|
transmute(self.repr().data.offset(index as int))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -233,14 +239,16 @@ impl<T> SliceExt<T> for [T] {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[unstable]
|
#[unstable]
|
||||||
fn binary_search<F>(&self, mut f: F) -> BinarySearchResult where F: FnMut(&T) -> Ordering {
|
fn binary_search_by<F>(&self, mut f: F) -> Result<uint, uint> where
|
||||||
|
F: FnMut(&T) -> Ordering
|
||||||
|
{
|
||||||
let mut base : uint = 0;
|
let mut base : uint = 0;
|
||||||
let mut lim : uint = self.len();
|
let mut lim : uint = self.len();
|
||||||
|
|
||||||
while lim != 0 {
|
while lim != 0 {
|
||||||
let ix = base + (lim >> 1);
|
let ix = base + (lim >> 1);
|
||||||
match f(&self[ix]) {
|
match f(&self[ix]) {
|
||||||
Equal => return BinarySearchResult::Found(ix),
|
Equal => return Ok(ix),
|
||||||
Less => {
|
Less => {
|
||||||
base = ix + 1;
|
base = ix + 1;
|
||||||
lim -= 1;
|
lim -= 1;
|
||||||
|
@ -249,7 +257,7 @@ impl<T> SliceExt<T> for [T] {
|
||||||
}
|
}
|
||||||
lim >>= 1;
|
lim >>= 1;
|
||||||
}
|
}
|
||||||
return BinarySearchResult::NotFound(base);
|
Err(base)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -292,11 +300,11 @@ impl<T> SliceExt<T> for [T] {
|
||||||
unsafe {
|
unsafe {
|
||||||
let p = self.as_mut_ptr();
|
let p = self.as_mut_ptr();
|
||||||
if mem::size_of::<T>() == 0 {
|
if mem::size_of::<T>() == 0 {
|
||||||
IterMut{ptr: p,
|
IterMut {ptr: p,
|
||||||
end: (p as uint + self.len()) as *mut T,
|
end: (p as uint + self.len()) as *mut T,
|
||||||
marker: marker::ContravariantLifetime::<'a>}
|
marker: marker::ContravariantLifetime::<'a>}
|
||||||
} else {
|
} else {
|
||||||
IterMut{ptr: p,
|
IterMut {ptr: p,
|
||||||
end: p.offset(self.len() as int),
|
end: p.offset(self.len() as int),
|
||||||
marker: marker::ContravariantLifetime::<'a>}
|
marker: marker::ContravariantLifetime::<'a>}
|
||||||
}
|
}
|
||||||
|
@ -311,7 +319,7 @@ impl<T> SliceExt<T> for [T] {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn head_mut(&mut self) -> Option<&mut T> {
|
fn first_mut(&mut self) -> Option<&mut T> {
|
||||||
if self.len() == 0 { None } else { Some(&mut self[0]) }
|
if self.len() == 0 { None } else { Some(&mut self[0]) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -327,36 +335,40 @@ impl<T> SliceExt<T> for [T] {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn split_mut<'a, P>(&'a mut self, pred: P) -> MutSplits<'a, T, P> where P: FnMut(&T) -> bool {
|
fn split_mut<'a, P>(&'a mut self, pred: P) -> SplitMut<'a, T, P> where P: FnMut(&T) -> bool {
|
||||||
MutSplits { v: self, pred: pred, finished: false }
|
SplitMut { v: self, pred: pred, finished: false }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn splitn_mut<'a, P>(&'a mut self, n: uint, pred: P) -> SplitsN<MutSplits<'a, T, P>> where
|
fn splitn_mut<'a, P>(&'a mut self, n: uint, pred: P) -> SplitNMut<'a, T, P> where
|
||||||
P: FnMut(&T) -> bool
|
P: FnMut(&T) -> bool
|
||||||
{
|
{
|
||||||
SplitsN {
|
SplitNMut {
|
||||||
iter: self.split_mut(pred),
|
inner: GenericSplitN {
|
||||||
count: n,
|
iter: self.split_mut(pred),
|
||||||
invert: false
|
count: n,
|
||||||
|
invert: false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn rsplitn_mut<'a, P>(&'a mut self, n: uint, pred: P) -> SplitsN<MutSplits<'a, T, P>> where
|
fn rsplitn_mut<'a, P>(&'a mut self, n: uint, pred: P) -> RSplitNMut<'a, T, P> where
|
||||||
P: FnMut(&T) -> bool,
|
P: FnMut(&T) -> bool,
|
||||||
{
|
{
|
||||||
SplitsN {
|
RSplitNMut {
|
||||||
iter: self.split_mut(pred),
|
inner: GenericSplitN {
|
||||||
count: n,
|
iter: self.split_mut(pred),
|
||||||
invert: true
|
count: n,
|
||||||
|
invert: true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn chunks_mut(&mut self, chunk_size: uint) -> MutChunks<T> {
|
fn chunks_mut(&mut self, chunk_size: uint) -> ChunksMut<T> {
|
||||||
assert!(chunk_size > 0);
|
assert!(chunk_size > 0);
|
||||||
MutChunks { v: self, chunk_size: chunk_size }
|
ChunksMut { v: self, chunk_size: chunk_size }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn swap(&mut self, a: uint, b: uint) {
|
fn swap(&mut self, a: uint, b: uint) {
|
||||||
|
@ -375,8 +387,8 @@ impl<T> SliceExt<T> for [T] {
|
||||||
while i < ln / 2 {
|
while i < ln / 2 {
|
||||||
// Unsafe swap to avoid the bounds check in safe swap.
|
// Unsafe swap to avoid the bounds check in safe swap.
|
||||||
unsafe {
|
unsafe {
|
||||||
let pa: *mut T = self.unsafe_mut(i);
|
let pa: *mut T = self.get_unchecked_mut(i);
|
||||||
let pb: *mut T = self.unsafe_mut(ln - i - 1);
|
let pb: *mut T = self.get_unchecked_mut(ln - i - 1);
|
||||||
ptr::swap(pa, pb);
|
ptr::swap(pa, pb);
|
||||||
}
|
}
|
||||||
i += 1;
|
i += 1;
|
||||||
|
@ -384,7 +396,7 @@ impl<T> SliceExt<T> for [T] {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
unsafe fn unsafe_mut(&mut self, index: uint) -> &mut T {
|
unsafe fn get_unchecked_mut(&mut self, index: uint) -> &mut T {
|
||||||
transmute((self.repr().data as *mut T).offset(index as int))
|
transmute((self.repr().data as *mut T).offset(index as int))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -468,21 +480,26 @@ impl<T> ops::SliceMut<uint, [T]> for [T] {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Extension methods for slices containing `PartialEq` elements.
|
/// Extension methods for slices containing `PartialEq` elements.
|
||||||
#[unstable = "may merge with other traits"]
|
#[unstable = "may merge with SliceExt"]
|
||||||
pub trait PartialEqSliceExt<T: PartialEq> for Sized? {
|
pub trait PartialEqSliceExt<T: PartialEq> for Sized? {
|
||||||
/// Find the first index containing a matching value.
|
/// Find the first index containing a matching value.
|
||||||
|
#[experimental]
|
||||||
fn position_elem(&self, t: &T) -> Option<uint>;
|
fn position_elem(&self, t: &T) -> Option<uint>;
|
||||||
|
|
||||||
/// Find the last index containing a matching value.
|
/// Find the last index containing a matching value.
|
||||||
|
#[experimental]
|
||||||
fn rposition_elem(&self, t: &T) -> Option<uint>;
|
fn rposition_elem(&self, t: &T) -> Option<uint>;
|
||||||
|
|
||||||
/// Return true if the slice contains an element with the given value.
|
/// Return true if the slice contains an element with the given value.
|
||||||
|
#[stable]
|
||||||
fn contains(&self, x: &T) -> bool;
|
fn contains(&self, x: &T) -> bool;
|
||||||
|
|
||||||
/// Returns true if `needle` is a prefix of the slice.
|
/// Returns true if `needle` is a prefix of the slice.
|
||||||
|
#[stable]
|
||||||
fn starts_with(&self, needle: &[T]) -> bool;
|
fn starts_with(&self, needle: &[T]) -> bool;
|
||||||
|
|
||||||
/// Returns true if `needle` is a suffix of the slice.
|
/// Returns true if `needle` is a suffix of the slice.
|
||||||
|
#[stable]
|
||||||
fn ends_with(&self, needle: &[T]) -> bool;
|
fn ends_with(&self, needle: &[T]) -> bool;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -520,19 +537,16 @@ impl<T: PartialEq> PartialEqSliceExt<T> for [T] {
|
||||||
#[unstable = "may merge with other traits"]
|
#[unstable = "may merge with other traits"]
|
||||||
#[allow(missing_docs)] // docs in libcollections
|
#[allow(missing_docs)] // docs in libcollections
|
||||||
pub trait OrdSliceExt<T: Ord> for Sized? {
|
pub trait OrdSliceExt<T: Ord> for Sized? {
|
||||||
#[unstable = "name likely to change"]
|
fn binary_search(&self, x: &T) -> Result<uint, uint>;
|
||||||
fn binary_search_elem(&self, x: &T) -> BinarySearchResult;
|
|
||||||
#[experimental]
|
|
||||||
fn next_permutation(&mut self) -> bool;
|
fn next_permutation(&mut self) -> bool;
|
||||||
#[experimental]
|
|
||||||
fn prev_permutation(&mut self) -> bool;
|
fn prev_permutation(&mut self) -> bool;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[unstable = "trait is unstable"]
|
#[unstable = "trait is unstable"]
|
||||||
impl<T: Ord> OrdSliceExt<T> for [T] {
|
impl<T: Ord> OrdSliceExt<T> for [T] {
|
||||||
#[unstable]
|
#[unstable]
|
||||||
fn binary_search_elem(&self, x: &T) -> BinarySearchResult {
|
fn binary_search(&self, x: &T) -> Result<uint, uint> {
|
||||||
self.binary_search(|p| p.cmp(x))
|
self.binary_search_by(|p| p.cmp(x))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[experimental]
|
#[experimental]
|
||||||
|
@ -619,28 +633,30 @@ impl<T: Clone> CloneSliceExt<T> for [T] {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// Common traits
|
// Common traits
|
||||||
//
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
/// Data that is viewable as a slice.
|
/// Data that is viewable as a slice.
|
||||||
#[unstable = "may merge with other traits"]
|
#[experimental = "will be replaced by slice syntax"]
|
||||||
pub trait AsSlice<T> for Sized? {
|
pub trait AsSlice<T> for Sized? {
|
||||||
/// Work with `self` as a slice.
|
/// Work with `self` as a slice.
|
||||||
fn as_slice<'a>(&'a self) -> &'a [T];
|
fn as_slice<'a>(&'a self) -> &'a [T];
|
||||||
}
|
}
|
||||||
|
|
||||||
#[unstable = "trait is unstable"]
|
#[experimental = "trait is experimental"]
|
||||||
impl<T> AsSlice<T> for [T] {
|
impl<T> AsSlice<T> for [T] {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn as_slice<'a>(&'a self) -> &'a [T] { self }
|
fn as_slice<'a>(&'a self) -> &'a [T] { self }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[experimental = "trait is experimental"]
|
||||||
impl<'a, T, Sized? U: AsSlice<T>> AsSlice<T> for &'a U {
|
impl<'a, T, Sized? U: AsSlice<T>> AsSlice<T> for &'a U {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn as_slice(&self) -> &[T] { AsSlice::as_slice(*self) }
|
fn as_slice(&self) -> &[T] { AsSlice::as_slice(*self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[experimental = "trait is experimental"]
|
||||||
impl<'a, T, Sized? U: AsSlice<T>> AsSlice<T> for &'a mut U {
|
impl<'a, T, Sized? U: AsSlice<T>> AsSlice<T> for &'a mut U {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn as_slice(&self) -> &[T] { AsSlice::as_slice(*self) }
|
fn as_slice(&self) -> &[T] { AsSlice::as_slice(*self) }
|
||||||
|
@ -656,7 +672,7 @@ impl<'a, T> Default for &'a [T] {
|
||||||
// Iterators
|
// Iterators
|
||||||
//
|
//
|
||||||
|
|
||||||
// The shared definition of the `Item` and `IterMut` iterators
|
// The shared definition of the `Iter` and `IterMut` iterators
|
||||||
macro_rules! iterator {
|
macro_rules! iterator {
|
||||||
(struct $name:ident -> $ptr:ty, $elem:ty) => {
|
(struct $name:ident -> $ptr:ty, $elem:ty) => {
|
||||||
#[experimental = "needs review"]
|
#[experimental = "needs review"]
|
||||||
|
@ -736,9 +752,8 @@ macro_rules! make_slice {
|
||||||
}}
|
}}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Immutable slice iterator
|
/// Immutable slice iterator
|
||||||
#[experimental = "needs review"]
|
#[stable]
|
||||||
pub struct Iter<'a, T: 'a> {
|
pub struct Iter<'a, T: 'a> {
|
||||||
ptr: *const T,
|
ptr: *const T,
|
||||||
end: *const T,
|
end: *const T,
|
||||||
|
@ -813,7 +828,7 @@ impl<'a, T> RandomAccessIterator<&'a T> for Iter<'a, T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Mutable slice iterator.
|
/// Mutable slice iterator.
|
||||||
#[experimental = "needs review"]
|
#[stable]
|
||||||
pub struct IterMut<'a, T: 'a> {
|
pub struct IterMut<'a, T: 'a> {
|
||||||
ptr: *mut T,
|
ptr: *mut T,
|
||||||
end: *mut T,
|
end: *mut T,
|
||||||
|
@ -876,9 +891,9 @@ iterator!{struct IterMut -> *mut T, &'a mut T}
|
||||||
#[experimental = "needs review"]
|
#[experimental = "needs review"]
|
||||||
impl<'a, T> ExactSizeIterator<&'a mut T> for IterMut<'a, T> {}
|
impl<'a, T> ExactSizeIterator<&'a mut T> for IterMut<'a, T> {}
|
||||||
|
|
||||||
/// An abstraction over the splitting iterators, so that splitn, splitn_mut etc
|
/// An internal abstraction over the splitting iterators, so that
|
||||||
/// can be implemented once.
|
/// splitn, splitn_mut etc can be implemented once.
|
||||||
trait SplitsIter<E>: DoubleEndedIterator<E> {
|
trait SplitIter<E>: DoubleEndedIterator<E> {
|
||||||
/// Mark the underlying iterator as complete, extracting the remaining
|
/// Mark the underlying iterator as complete, extracting the remaining
|
||||||
/// portion of the slice.
|
/// portion of the slice.
|
||||||
fn finish(&mut self) -> Option<E>;
|
fn finish(&mut self) -> Option<E>;
|
||||||
|
@ -886,8 +901,8 @@ trait SplitsIter<E>: DoubleEndedIterator<E> {
|
||||||
|
|
||||||
/// An iterator over subslices separated by elements that match a predicate
|
/// An iterator over subslices separated by elements that match a predicate
|
||||||
/// function.
|
/// function.
|
||||||
#[experimental = "needs review"]
|
#[stable]
|
||||||
pub struct Splits<'a, T:'a, P> where P: FnMut(&T) -> bool {
|
pub struct Split<'a, T:'a, P> where P: FnMut(&T) -> bool {
|
||||||
v: &'a [T],
|
v: &'a [T],
|
||||||
pred: P,
|
pred: P,
|
||||||
finished: bool
|
finished: bool
|
||||||
|
@ -895,9 +910,9 @@ pub struct Splits<'a, T:'a, P> where P: FnMut(&T) -> bool {
|
||||||
|
|
||||||
// FIXME(#19839) Remove in favor of `#[deriving(Clone)]`
|
// FIXME(#19839) Remove in favor of `#[deriving(Clone)]`
|
||||||
#[stable]
|
#[stable]
|
||||||
impl<'a, T, P> Clone for Splits<'a, T, P> where P: Clone + FnMut(&T) -> bool {
|
impl<'a, T, P> Clone for Split<'a, T, P> where P: Clone + FnMut(&T) -> bool {
|
||||||
fn clone(&self) -> Splits<'a, T, P> {
|
fn clone(&self) -> Split<'a, T, P> {
|
||||||
Splits {
|
Split {
|
||||||
v: self.v,
|
v: self.v,
|
||||||
pred: self.pred.clone(),
|
pred: self.pred.clone(),
|
||||||
finished: self.finished,
|
finished: self.finished,
|
||||||
|
@ -906,7 +921,7 @@ impl<'a, T, P> Clone for Splits<'a, T, P> where P: Clone + FnMut(&T) -> bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[experimental = "needs review"]
|
#[experimental = "needs review"]
|
||||||
impl<'a, T, P> Iterator<&'a [T]> for Splits<'a, T, P> where P: FnMut(&T) -> bool {
|
impl<'a, T, P> Iterator<&'a [T]> for Split<'a, T, P> where P: FnMut(&T) -> bool {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn next(&mut self) -> Option<&'a [T]> {
|
fn next(&mut self) -> Option<&'a [T]> {
|
||||||
if self.finished { return None; }
|
if self.finished { return None; }
|
||||||
|
@ -932,7 +947,7 @@ impl<'a, T, P> Iterator<&'a [T]> for Splits<'a, T, P> where P: FnMut(&T) -> bool
|
||||||
}
|
}
|
||||||
|
|
||||||
#[experimental = "needs review"]
|
#[experimental = "needs review"]
|
||||||
impl<'a, T, P> DoubleEndedIterator<&'a [T]> for Splits<'a, T, P> where P: FnMut(&T) -> bool {
|
impl<'a, T, P> DoubleEndedIterator<&'a [T]> for Split<'a, T, P> where P: FnMut(&T) -> bool {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn next_back(&mut self) -> Option<&'a [T]> {
|
fn next_back(&mut self) -> Option<&'a [T]> {
|
||||||
if self.finished { return None; }
|
if self.finished { return None; }
|
||||||
|
@ -948,7 +963,7 @@ impl<'a, T, P> DoubleEndedIterator<&'a [T]> for Splits<'a, T, P> where P: FnMut(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, T, P> SplitsIter<&'a [T]> for Splits<'a, T, P> where P: FnMut(&T) -> bool {
|
impl<'a, T, P> SplitIter<&'a [T]> for Split<'a, T, P> where P: FnMut(&T) -> bool {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn finish(&mut self) -> Option<&'a [T]> {
|
fn finish(&mut self) -> Option<&'a [T]> {
|
||||||
if self.finished { None } else { self.finished = true; Some(self.v) }
|
if self.finished { None } else { self.finished = true; Some(self.v) }
|
||||||
|
@ -957,14 +972,14 @@ impl<'a, T, P> SplitsIter<&'a [T]> for Splits<'a, T, P> where P: FnMut(&T) -> bo
|
||||||
|
|
||||||
/// An iterator over the subslices of the vector which are separated
|
/// An iterator over the subslices of the vector which are separated
|
||||||
/// by elements that match `pred`.
|
/// by elements that match `pred`.
|
||||||
#[experimental = "needs review"]
|
#[stable]
|
||||||
pub struct MutSplits<'a, T:'a, P> where P: FnMut(&T) -> bool {
|
pub struct SplitMut<'a, T:'a, P> where P: FnMut(&T) -> bool {
|
||||||
v: &'a mut [T],
|
v: &'a mut [T],
|
||||||
pred: P,
|
pred: P,
|
||||||
finished: bool
|
finished: bool
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, T, P> SplitsIter<&'a mut [T]> for MutSplits<'a, T, P> where P: FnMut(&T) -> bool {
|
impl<'a, T, P> SplitIter<&'a mut [T]> for SplitMut<'a, T, P> where P: FnMut(&T) -> bool {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn finish(&mut self) -> Option<&'a mut [T]> {
|
fn finish(&mut self) -> Option<&'a mut [T]> {
|
||||||
if self.finished {
|
if self.finished {
|
||||||
|
@ -977,7 +992,7 @@ impl<'a, T, P> SplitsIter<&'a mut [T]> for MutSplits<'a, T, P> where P: FnMut(&T
|
||||||
}
|
}
|
||||||
|
|
||||||
#[experimental = "needs review"]
|
#[experimental = "needs review"]
|
||||||
impl<'a, T, P> Iterator<&'a mut [T]> for MutSplits<'a, T, P> where P: FnMut(&T) -> bool {
|
impl<'a, T, P> Iterator<&'a mut [T]> for SplitMut<'a, T, P> where P: FnMut(&T) -> bool {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn next(&mut self) -> Option<&'a mut [T]> {
|
fn next(&mut self) -> Option<&'a mut [T]> {
|
||||||
if self.finished { return None; }
|
if self.finished { return None; }
|
||||||
|
@ -1010,7 +1025,7 @@ impl<'a, T, P> Iterator<&'a mut [T]> for MutSplits<'a, T, P> where P: FnMut(&T)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[experimental = "needs review"]
|
#[experimental = "needs review"]
|
||||||
impl<'a, T, P> DoubleEndedIterator<&'a mut [T]> for MutSplits<'a, T, P> where
|
impl<'a, T, P> DoubleEndedIterator<&'a mut [T]> for SplitMut<'a, T, P> where
|
||||||
P: FnMut(&T) -> bool,
|
P: FnMut(&T) -> bool,
|
||||||
{
|
{
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -1033,17 +1048,17 @@ impl<'a, T, P> DoubleEndedIterator<&'a mut [T]> for MutSplits<'a, T, P> where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// An iterator over subslices separated by elements that match a predicate
|
/// An private iterator over subslices separated by elements that
|
||||||
/// function, splitting at most a fixed number of times.
|
/// match a predicate function, splitting at most a fixed number of
|
||||||
#[experimental = "needs review"]
|
/// times.
|
||||||
pub struct SplitsN<I> {
|
struct GenericSplitN<I> {
|
||||||
iter: I,
|
iter: I,
|
||||||
count: uint,
|
count: uint,
|
||||||
invert: bool
|
invert: bool
|
||||||
}
|
}
|
||||||
|
|
||||||
#[experimental = "needs review"]
|
#[experimental = "needs review"]
|
||||||
impl<E, I: SplitsIter<E>> Iterator<E> for SplitsN<I> {
|
impl<E, I: SplitIter<E>> Iterator<E> for GenericSplitN<I> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn next(&mut self) -> Option<E> {
|
fn next(&mut self) -> Option<E> {
|
||||||
if self.count == 0 {
|
if self.count == 0 {
|
||||||
|
@ -1061,6 +1076,55 @@ impl<E, I: SplitsIter<E>> Iterator<E> for SplitsN<I> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// An iterator over subslices separated by elements that match a predicate
|
||||||
|
/// function, limited to a given number of splits.
|
||||||
|
pub struct SplitN<'a, T: 'a, P> where P: FnMut(&T) -> bool {
|
||||||
|
inner: GenericSplitN<Split<'a, T, P>>
|
||||||
|
}
|
||||||
|
|
||||||
|
/// An iterator over subslices separated by elements that match a
|
||||||
|
/// predicate function, limited to a given number of splits, starting
|
||||||
|
/// from the end of the slice.
|
||||||
|
pub struct RSplitN<'a, T: 'a, P> where P: FnMut(&T) -> bool {
|
||||||
|
inner: GenericSplitN<Split<'a, T, P>>
|
||||||
|
}
|
||||||
|
|
||||||
|
/// An iterator over subslices separated by elements that match a predicate
|
||||||
|
/// function, limited to a given number of splits.
|
||||||
|
pub struct SplitNMut<'a, T: 'a, P> where P: FnMut(&T) -> bool {
|
||||||
|
inner: GenericSplitN<SplitMut<'a, T, P>>
|
||||||
|
}
|
||||||
|
|
||||||
|
/// An iterator over subslices separated by elements that match a
|
||||||
|
/// predicate function, limited to a given number of splits, starting
|
||||||
|
/// from the end of the slice.
|
||||||
|
pub struct RSplitNMut<'a, T: 'a, P> where P: FnMut(&T) -> bool {
|
||||||
|
inner: GenericSplitN<SplitMut<'a, T, P>>
|
||||||
|
}
|
||||||
|
|
||||||
|
macro_rules! forward_iterator {
|
||||||
|
($name:ident: $elem:ident, $iter_of:ty) => {
|
||||||
|
impl<'a, $elem, P> Iterator<$iter_of> for $name<'a, $elem, P> where
|
||||||
|
P: FnMut(&T) -> bool
|
||||||
|
{
|
||||||
|
#[inline]
|
||||||
|
fn next(&mut self) -> Option<$iter_of> {
|
||||||
|
self.inner.next()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn size_hint(&self) -> (uint, Option<uint>) {
|
||||||
|
self.inner.size_hint()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
forward_iterator! { SplitN: T, &'a [T] }
|
||||||
|
forward_iterator! { RSplitN: T, &'a [T] }
|
||||||
|
forward_iterator! { SplitNMut: T, &'a mut [T] }
|
||||||
|
forward_iterator! { RSplitNMut: T, &'a mut [T] }
|
||||||
|
|
||||||
/// An iterator over overlapping subslices of length `size`.
|
/// An iterator over overlapping subslices of length `size`.
|
||||||
#[deriving(Clone)]
|
#[deriving(Clone)]
|
||||||
#[experimental = "needs review"]
|
#[experimental = "needs review"]
|
||||||
|
@ -1172,13 +1236,13 @@ impl<'a, T> RandomAccessIterator<&'a [T]> for Chunks<'a, T> {
|
||||||
/// elements at a time). When the slice len is not evenly divided by the chunk
|
/// elements at a time). When the slice len is not evenly divided by the chunk
|
||||||
/// size, the last slice of the iteration will be the remainder.
|
/// size, the last slice of the iteration will be the remainder.
|
||||||
#[experimental = "needs review"]
|
#[experimental = "needs review"]
|
||||||
pub struct MutChunks<'a, T:'a> {
|
pub struct ChunksMut<'a, T:'a> {
|
||||||
v: &'a mut [T],
|
v: &'a mut [T],
|
||||||
chunk_size: uint
|
chunk_size: uint
|
||||||
}
|
}
|
||||||
|
|
||||||
#[experimental = "needs review"]
|
#[experimental = "needs review"]
|
||||||
impl<'a, T> Iterator<&'a mut [T]> for MutChunks<'a, T> {
|
impl<'a, T> Iterator<&'a mut [T]> for ChunksMut<'a, T> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn next(&mut self) -> Option<&'a mut [T]> {
|
fn next(&mut self) -> Option<&'a mut [T]> {
|
||||||
if self.v.len() == 0 {
|
if self.v.len() == 0 {
|
||||||
|
@ -1206,7 +1270,7 @@ impl<'a, T> Iterator<&'a mut [T]> for MutChunks<'a, T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[experimental = "needs review"]
|
#[experimental = "needs review"]
|
||||||
impl<'a, T> DoubleEndedIterator<&'a mut [T]> for MutChunks<'a, T> {
|
impl<'a, T> DoubleEndedIterator<&'a mut [T]> for ChunksMut<'a, T> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn next_back(&mut self) -> Option<&'a mut [T]> {
|
fn next_back(&mut self) -> Option<&'a mut [T]> {
|
||||||
if self.v.len() == 0 {
|
if self.v.len() == 0 {
|
||||||
|
@ -1224,51 +1288,12 @@ impl<'a, T> DoubleEndedIterator<&'a mut [T]> for MutChunks<'a, T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// The result of calling `binary_search`.
|
|
||||||
///
|
|
||||||
/// `Found` means the search succeeded, and the contained value is the
|
|
||||||
/// index of the matching element. `NotFound` means the search
|
|
||||||
/// succeeded, and the contained value is an index where a matching
|
|
||||||
/// value could be inserted while maintaining sort order.
|
|
||||||
#[deriving(Copy, PartialEq, Show)]
|
|
||||||
#[experimental = "needs review"]
|
|
||||||
pub enum BinarySearchResult {
|
|
||||||
/// The index of the found value.
|
|
||||||
Found(uint),
|
|
||||||
/// The index where the value should have been found.
|
|
||||||
NotFound(uint)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[experimental = "needs review"]
|
|
||||||
impl BinarySearchResult {
|
|
||||||
/// Converts a `Found` to `Some`, `NotFound` to `None`.
|
|
||||||
/// Similar to `Result::ok`.
|
|
||||||
pub fn found(&self) -> Option<uint> {
|
|
||||||
match *self {
|
|
||||||
BinarySearchResult::Found(i) => Some(i),
|
|
||||||
BinarySearchResult::NotFound(_) => None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Convert a `Found` to `None`, `NotFound` to `Some`.
|
|
||||||
/// Similar to `Result::err`.
|
|
||||||
pub fn not_found(&self) -> Option<uint> {
|
|
||||||
match *self {
|
|
||||||
BinarySearchResult::Found(_) => None,
|
|
||||||
BinarySearchResult::NotFound(i) => Some(i)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Free functions
|
// Free functions
|
||||||
//
|
//
|
||||||
|
|
||||||
/// Converts a pointer to A into a slice of length 1 (without copying).
|
/// Converts a pointer to A into a slice of length 1 (without copying).
|
||||||
#[unstable = "waiting for DST"]
|
#[unstable]
|
||||||
pub fn ref_slice<'a, A>(s: &'a A) -> &'a [A] {
|
pub fn ref_slice<'a, A>(s: &'a A) -> &'a [A] {
|
||||||
unsafe {
|
unsafe {
|
||||||
transmute(RawSlice { data: s, len: 1 })
|
transmute(RawSlice { data: s, len: 1 })
|
||||||
|
@ -1276,7 +1301,7 @@ pub fn ref_slice<'a, A>(s: &'a A) -> &'a [A] {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Converts a pointer to A into a slice of length 1 (without copying).
|
/// Converts a pointer to A into a slice of length 1 (without copying).
|
||||||
#[unstable = "waiting for DST"]
|
#[unstable]
|
||||||
pub fn mut_ref_slice<'a, A>(s: &'a mut A) -> &'a mut [A] {
|
pub fn mut_ref_slice<'a, A>(s: &'a mut A) -> &'a mut [A] {
|
||||||
unsafe {
|
unsafe {
|
||||||
let ptr: *const A = transmute(s);
|
let ptr: *const A = transmute(s);
|
||||||
|
@ -1310,7 +1335,7 @@ pub fn mut_ref_slice<'a, A>(s: &'a mut A) -> &'a mut [A] {
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
#[inline]
|
#[inline]
|
||||||
#[unstable = "just renamed from `mod raw`"]
|
#[unstable = "should be renamed to from_raw_parts"]
|
||||||
pub unsafe fn from_raw_buf<'a, T>(p: &'a *const T, len: uint) -> &'a [T] {
|
pub unsafe fn from_raw_buf<'a, T>(p: &'a *const T, len: uint) -> &'a [T] {
|
||||||
transmute(RawSlice { data: *p, len: len })
|
transmute(RawSlice { data: *p, len: len })
|
||||||
}
|
}
|
||||||
|
@ -1322,7 +1347,7 @@ pub unsafe fn from_raw_buf<'a, T>(p: &'a *const T, len: uint) -> &'a [T] {
|
||||||
/// not being able to provide a non-aliasing guarantee of the returned mutable
|
/// not being able to provide a non-aliasing guarantee of the returned mutable
|
||||||
/// slice.
|
/// slice.
|
||||||
#[inline]
|
#[inline]
|
||||||
#[unstable = "just renamed from `mod raw`"]
|
#[unstable = "jshould be renamed to from_raw_parts_mut"]
|
||||||
pub unsafe fn from_raw_mut_buf<'a, T>(p: &'a *mut T, len: uint) -> &'a mut [T] {
|
pub unsafe fn from_raw_mut_buf<'a, T>(p: &'a *mut T, len: uint) -> &'a mut [T] {
|
||||||
transmute(RawSlice { data: *p as *const T, len: len })
|
transmute(RawSlice { data: *p as *const T, len: len })
|
||||||
}
|
}
|
||||||
|
@ -1497,39 +1522,28 @@ impl<T: PartialOrd> PartialOrd for [T] {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Extension methods for immutable slices containing integers.
|
/// Extension methods for slices containing integers.
|
||||||
#[experimental]
|
#[experimental]
|
||||||
pub trait ImmutableIntSlice<U, S> for Sized? {
|
pub trait IntSliceExt<U, S> for Sized? {
|
||||||
/// Converts the slice to an immutable slice of unsigned integers with the same width.
|
/// Converts the slice to an immutable slice of unsigned integers with the same width.
|
||||||
fn as_unsigned<'a>(&'a self) -> &'a [U];
|
fn as_unsigned<'a>(&'a self) -> &'a [U];
|
||||||
/// Converts the slice to an immutable slice of signed integers with the same width.
|
/// Converts the slice to an immutable slice of signed integers with the same width.
|
||||||
fn as_signed<'a>(&'a self) -> &'a [S];
|
fn as_signed<'a>(&'a self) -> &'a [S];
|
||||||
}
|
|
||||||
|
|
||||||
/// Extension methods for mutable slices containing integers.
|
|
||||||
#[experimental]
|
|
||||||
pub trait MutableIntSlice<U, S> for Sized?: ImmutableIntSlice<U, S> {
|
|
||||||
/// Converts the slice to a mutable slice of unsigned integers with the same width.
|
/// Converts the slice to a mutable slice of unsigned integers with the same width.
|
||||||
fn as_unsigned_mut<'a>(&'a mut self) -> &'a mut [U];
|
fn as_unsigned_mut<'a>(&'a mut self) -> &'a mut [U];
|
||||||
/// Converts the slice to a mutable slice of signed integers with the same width.
|
/// Converts the slice to a mutable slice of signed integers with the same width.
|
||||||
fn as_signed_mut<'a>(&'a mut self) -> &'a mut [S];
|
fn as_signed_mut<'a>(&'a mut self) -> &'a mut [S];
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! impl_immut_int_slice {
|
macro_rules! impl_int_slice {
|
||||||
($u:ty, $s:ty, $t:ty) => {
|
($u:ty, $s:ty, $t:ty) => {
|
||||||
#[experimental]
|
#[experimental]
|
||||||
impl ImmutableIntSlice<$u, $s> for [$t] {
|
impl IntSliceExt<$u, $s> for [$t] {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn as_unsigned(&self) -> &[$u] { unsafe { transmute(self) } }
|
fn as_unsigned(&self) -> &[$u] { unsafe { transmute(self) } }
|
||||||
#[inline]
|
#[inline]
|
||||||
fn as_signed(&self) -> &[$s] { unsafe { transmute(self) } }
|
fn as_signed(&self) -> &[$s] { unsafe { transmute(self) } }
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
macro_rules! impl_mut_int_slice {
|
|
||||||
($u:ty, $s:ty, $t:ty) => {
|
|
||||||
#[experimental]
|
|
||||||
impl MutableIntSlice<$u, $s> for [$t] {
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn as_unsigned_mut(&mut self) -> &mut [$u] { unsafe { transmute(self) } }
|
fn as_unsigned_mut(&mut self) -> &mut [$u] { unsafe { transmute(self) } }
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -1538,17 +1552,15 @@ macro_rules! impl_mut_int_slice {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! impl_int_slice {
|
macro_rules! impl_int_slices {
|
||||||
($u:ty, $s:ty) => {
|
($u:ty, $s:ty) => {
|
||||||
impl_immut_int_slice! { $u, $s, $u }
|
impl_int_slice! { $u, $s, $u }
|
||||||
impl_immut_int_slice! { $u, $s, $s }
|
impl_int_slice! { $u, $s, $s }
|
||||||
impl_mut_int_slice! { $u, $s, $u }
|
|
||||||
impl_mut_int_slice! { $u, $s, $s }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl_int_slice! { u8, i8 }
|
impl_int_slices! { u8, i8 }
|
||||||
impl_int_slice! { u16, i16 }
|
impl_int_slices! { u16, i16 }
|
||||||
impl_int_slice! { u32, i32 }
|
impl_int_slices! { u32, i32 }
|
||||||
impl_int_slice! { u64, i64 }
|
impl_int_slices! { u64, i64 }
|
||||||
impl_int_slice! { uint, int }
|
impl_int_slices! { uint, int }
|
||||||
|
|
|
@ -8,30 +8,30 @@
|
||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
use std::slice::BinarySearchResult::{Found, NotFound};
|
use core::result::Result::{Ok, Err};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn binary_search_not_found() {
|
fn binary_search_not_found() {
|
||||||
let b = [1i, 2, 4, 6, 8, 9];
|
let b = [1i, 2, 4, 6, 8, 9];
|
||||||
assert!(b.binary_search(|v| v.cmp(&6)) == Found(3));
|
assert!(b.binary_search_by(|v| v.cmp(&6)) == Ok(3));
|
||||||
let b = [1i, 2, 4, 6, 8, 9];
|
let b = [1i, 2, 4, 6, 8, 9];
|
||||||
assert!(b.binary_search(|v| v.cmp(&5)) == NotFound(3));
|
assert!(b.binary_search_by(|v| v.cmp(&5)) == Err(3));
|
||||||
let b = [1i, 2, 4, 6, 7, 8, 9];
|
let b = [1i, 2, 4, 6, 7, 8, 9];
|
||||||
assert!(b.binary_search(|v| v.cmp(&6)) == Found(3));
|
assert!(b.binary_search_by(|v| v.cmp(&6)) == Ok(3));
|
||||||
let b = [1i, 2, 4, 6, 7, 8, 9];
|
let b = [1i, 2, 4, 6, 7, 8, 9];
|
||||||
assert!(b.binary_search(|v| v.cmp(&5)) == NotFound(3));
|
assert!(b.binary_search_by(|v| v.cmp(&5)) == Err(3));
|
||||||
let b = [1i, 2, 4, 6, 8, 9];
|
let b = [1i, 2, 4, 6, 8, 9];
|
||||||
assert!(b.binary_search(|v| v.cmp(&8)) == Found(4));
|
assert!(b.binary_search_by(|v| v.cmp(&8)) == Ok(4));
|
||||||
let b = [1i, 2, 4, 6, 8, 9];
|
let b = [1i, 2, 4, 6, 8, 9];
|
||||||
assert!(b.binary_search(|v| v.cmp(&7)) == NotFound(4));
|
assert!(b.binary_search_by(|v| v.cmp(&7)) == Err(4));
|
||||||
let b = [1i, 2, 4, 6, 7, 8, 9];
|
let b = [1i, 2, 4, 6, 7, 8, 9];
|
||||||
assert!(b.binary_search(|v| v.cmp(&8)) == Found(5));
|
assert!(b.binary_search_by(|v| v.cmp(&8)) == Ok(5));
|
||||||
let b = [1i, 2, 4, 5, 6, 8, 9];
|
let b = [1i, 2, 4, 5, 6, 8, 9];
|
||||||
assert!(b.binary_search(|v| v.cmp(&7)) == NotFound(5));
|
assert!(b.binary_search_by(|v| v.cmp(&7)) == Err(5));
|
||||||
let b = [1i, 2, 4, 5, 6, 8, 9];
|
let b = [1i, 2, 4, 5, 6, 8, 9];
|
||||||
assert!(b.binary_search(|v| v.cmp(&0)) == NotFound(0));
|
assert!(b.binary_search_by(|v| v.cmp(&0)) == Err(0));
|
||||||
let b = [1i, 2, 4, 5, 6, 8];
|
let b = [1i, 2, 4, 5, 6, 8];
|
||||||
assert!(b.binary_search(|v| v.cmp(&9)) == NotFound(6));
|
assert!(b.binary_search_by(|v| v.cmp(&9)) == Err(6));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -578,7 +578,7 @@ pub fn getopts(args: &[String], optgrps: &[OptGroup]) -> Result {
|
||||||
|
|
||||||
fn f(_x: uint) -> Vec<Optval> { return Vec::new(); }
|
fn f(_x: uint) -> Vec<Optval> { return Vec::new(); }
|
||||||
|
|
||||||
let mut vals = Vec::from_fn(n_opts, f);
|
let mut vals: Vec<_> = range(0, n_opts).map(f).collect();
|
||||||
let mut free: Vec<String> = Vec::new();
|
let mut free: Vec<String> = Vec::new();
|
||||||
let l = args.len();
|
let l = args.len();
|
||||||
let mut i = 0;
|
let mut i = 0;
|
||||||
|
|
|
@ -361,7 +361,7 @@ impl Isaac64Rng {
|
||||||
const MP_VEC: [(uint, uint), .. 2] = [(0,MIDPOINT), (MIDPOINT, 0)];
|
const MP_VEC: [(uint, uint), .. 2] = [(0,MIDPOINT), (MIDPOINT, 0)];
|
||||||
macro_rules! ind (
|
macro_rules! ind (
|
||||||
($x:expr) => {
|
($x:expr) => {
|
||||||
*self.mem.unsafe_get(($x as uint >> 3) & (RAND_SIZE_64 - 1))
|
*self.mem.get_unchecked(($x as uint >> 3) & (RAND_SIZE_64 - 1))
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -375,13 +375,13 @@ impl Isaac64Rng {
|
||||||
let mix = if $j == 0 {!mix} else {mix};
|
let mix = if $j == 0 {!mix} else {mix};
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
let x = *self.mem.unsafe_get(base + mr_offset);
|
let x = *self.mem.get_unchecked(base + mr_offset);
|
||||||
a = mix + *self.mem.unsafe_get(base + m2_offset);
|
a = mix + *self.mem.get_unchecked(base + m2_offset);
|
||||||
let y = ind!(x) + a + b;
|
let y = ind!(x) + a + b;
|
||||||
*self.mem.unsafe_mut(base + mr_offset) = y;
|
*self.mem.get_unchecked_mut(base + mr_offset) = y;
|
||||||
|
|
||||||
b = ind!(y >> RAND_SIZE_64_LEN) + x;
|
b = ind!(y >> RAND_SIZE_64_LEN) + x;
|
||||||
*self.rsl.unsafe_mut(base + mr_offset) = b;
|
*self.rsl.get_unchecked_mut(base + mr_offset) = b;
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
);
|
);
|
||||||
|
@ -392,13 +392,13 @@ impl Isaac64Rng {
|
||||||
let mix = if $j == 0 {!mix} else {mix};
|
let mix = if $j == 0 {!mix} else {mix};
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
let x = *self.mem.unsafe_get(base + mr_offset);
|
let x = *self.mem.get_unchecked(base + mr_offset);
|
||||||
a = mix + *self.mem.unsafe_get(base + m2_offset);
|
a = mix + *self.mem.get_unchecked(base + m2_offset);
|
||||||
let y = ind!(x) + a + b;
|
let y = ind!(x) + a + b;
|
||||||
*self.mem.unsafe_mut(base + mr_offset) = y;
|
*self.mem.get_unchecked_mut(base + mr_offset) = y;
|
||||||
|
|
||||||
b = ind!(y >> RAND_SIZE_64_LEN) + x;
|
b = ind!(y >> RAND_SIZE_64_LEN) + x;
|
||||||
*self.rsl.unsafe_mut(base + mr_offset) = b;
|
*self.rsl.get_unchecked_mut(base + mr_offset) = b;
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
);
|
);
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
use std::io::{IoError, IoResult, SeekStyle};
|
use std::io::{IoError, IoResult, SeekStyle};
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::slice;
|
use std::slice;
|
||||||
|
use std::iter::repeat;
|
||||||
|
|
||||||
static BUF_CAPACITY: uint = 128;
|
static BUF_CAPACITY: uint = 128;
|
||||||
|
|
||||||
|
@ -87,7 +88,7 @@ impl Writer for SeekableMemWriter {
|
||||||
// currently are
|
// currently are
|
||||||
let difference = self.pos as i64 - self.buf.len() as i64;
|
let difference = self.pos as i64 - self.buf.len() as i64;
|
||||||
if difference > 0 {
|
if difference > 0 {
|
||||||
self.buf.grow(difference as uint, 0);
|
self.buf.extend(repeat(0).take(difference as uint));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Figure out what bytes will be used to overwrite what's currently
|
// Figure out what bytes will be used to overwrite what's currently
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
pub use self::Inst::*;
|
pub use self::Inst::*;
|
||||||
|
|
||||||
use std::cmp;
|
use std::cmp;
|
||||||
|
use std::iter::repeat;
|
||||||
use parse;
|
use parse;
|
||||||
use parse::{
|
use parse::{
|
||||||
Flags, FLAG_EMPTY,
|
Flags, FLAG_EMPTY,
|
||||||
|
@ -157,7 +158,7 @@ impl<'r> Compiler<'r> {
|
||||||
Capture(cap, name, x) => {
|
Capture(cap, name, x) => {
|
||||||
let len = self.names.len();
|
let len = self.names.len();
|
||||||
if cap >= len {
|
if cap >= len {
|
||||||
self.names.grow(10 + cap - len, None)
|
self.names.extend(repeat(None).take(10 + cap - len))
|
||||||
}
|
}
|
||||||
self.names[cap] = name;
|
self.names[cap] = name;
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,6 @@ use std::cmp;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::iter;
|
use std::iter;
|
||||||
use std::num;
|
use std::num;
|
||||||
use std::slice::BinarySearchResult;
|
|
||||||
|
|
||||||
/// Static data containing Unicode ranges for general categories and scripts.
|
/// Static data containing Unicode ranges for general categories and scripts.
|
||||||
use unicode::regex::{UNICODE_CLASSES, PERLD, PERLS, PERLW};
|
use unicode::regex::{UNICODE_CLASSES, PERLD, PERLS, PERLW};
|
||||||
|
@ -1028,9 +1027,9 @@ fn is_valid_cap(c: char) -> bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn find_class(classes: NamedClasses, name: &str) -> Option<Vec<(char, char)>> {
|
fn find_class(classes: NamedClasses, name: &str) -> Option<Vec<(char, char)>> {
|
||||||
match classes.binary_search(|&(s, _)| s.cmp(name)) {
|
match classes.binary_search_by(|&(s, _)| s.cmp(name)) {
|
||||||
BinarySearchResult::Found(i) => Some(classes[i].1.to_vec()),
|
Ok(i) => Some(classes[i].1.to_vec()),
|
||||||
BinarySearchResult::NotFound(_) => None,
|
Err(_) => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,6 +38,7 @@ pub use self::StepState::*;
|
||||||
|
|
||||||
use std::cmp;
|
use std::cmp;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
|
use std::iter::repeat;
|
||||||
use std::slice::SliceExt;
|
use std::slice::SliceExt;
|
||||||
use compile::{
|
use compile::{
|
||||||
Program,
|
Program,
|
||||||
|
@ -121,7 +122,7 @@ impl<'r, 't> Nfa<'r, 't> {
|
||||||
let mut clist = &mut Threads::new(self.which, ninsts, ncaps);
|
let mut clist = &mut Threads::new(self.which, ninsts, ncaps);
|
||||||
let mut nlist = &mut Threads::new(self.which, ninsts, ncaps);
|
let mut nlist = &mut Threads::new(self.which, ninsts, ncaps);
|
||||||
|
|
||||||
let mut groups = Vec::from_elem(ncaps * 2, None);
|
let mut groups: Vec<_> = repeat(None).take(ncaps * 2).collect();
|
||||||
|
|
||||||
// Determine if the expression starts with a '^' so we can avoid
|
// Determine if the expression starts with a '^' so we can avoid
|
||||||
// simulating .*?
|
// simulating .*?
|
||||||
|
@ -227,8 +228,7 @@ impl<'r, 't> Nfa<'r, 't> {
|
||||||
let negate = flags & FLAG_NEGATED > 0;
|
let negate = flags & FLAG_NEGATED > 0;
|
||||||
let casei = flags & FLAG_NOCASE > 0;
|
let casei = flags & FLAG_NOCASE > 0;
|
||||||
let found = ranges.as_slice();
|
let found = ranges.as_slice();
|
||||||
let found = found.binary_search(|&rc| class_cmp(casei, c, rc))
|
let found = found.binary_search_by(|&rc| class_cmp(casei, c, rc)).is_ok();
|
||||||
.found().is_some();
|
|
||||||
if found ^ negate {
|
if found ^ negate {
|
||||||
self.add(nlist, pc+1, caps);
|
self.add(nlist, pc+1, caps);
|
||||||
}
|
}
|
||||||
|
@ -457,10 +457,10 @@ impl Threads {
|
||||||
fn new(which: MatchKind, num_insts: uint, ncaps: uint) -> Threads {
|
fn new(which: MatchKind, num_insts: uint, ncaps: uint) -> Threads {
|
||||||
Threads {
|
Threads {
|
||||||
which: which,
|
which: which,
|
||||||
queue: Vec::from_fn(num_insts, |_| {
|
queue: range(0, num_insts).map(|_| {
|
||||||
Thread { pc: 0, groups: Vec::from_elem(ncaps * 2, None) }
|
Thread { pc: 0, groups: repeat(None).take(ncaps * 2).collect() }
|
||||||
}),
|
}).collect(),
|
||||||
sparse: Vec::from_elem(num_insts, 0u),
|
sparse: repeat(0u).take(num_insts).collect(),
|
||||||
size: 0,
|
size: 0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -518,7 +518,7 @@ pub fn is_word(c: Option<char>) -> bool {
|
||||||
// Try the common ASCII case before invoking binary search.
|
// Try the common ASCII case before invoking binary search.
|
||||||
match c {
|
match c {
|
||||||
'_' | '0' ... '9' | 'a' ... 'z' | 'A' ... 'Z' => true,
|
'_' | '0' ... '9' | 'a' ... 'z' | 'A' ... 'Z' => true,
|
||||||
_ => PERLW.binary_search(|&(start, end)| {
|
_ => PERLW.binary_search_by(|&(start, end)| {
|
||||||
if c >= start && c <= end {
|
if c >= start && c <= end {
|
||||||
Equal
|
Equal
|
||||||
} else if start > c {
|
} else if start > c {
|
||||||
|
@ -526,7 +526,7 @@ pub fn is_word(c: Option<char>) -> bool {
|
||||||
} else {
|
} else {
|
||||||
Less
|
Less
|
||||||
}
|
}
|
||||||
}).found().is_some()
|
}).is_ok()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1599,7 +1599,7 @@ fn encode_index<T, F>(rbml_w: &mut Encoder, index: Vec<entry<T>>, mut write_fn:
|
||||||
F: FnMut(&mut SeekableMemWriter, &T),
|
F: FnMut(&mut SeekableMemWriter, &T),
|
||||||
T: Hash,
|
T: Hash,
|
||||||
{
|
{
|
||||||
let mut buckets: Vec<Vec<entry<T>>> = Vec::from_fn(256, |_| Vec::new());
|
let mut buckets: Vec<Vec<entry<T>>> = range(0, 256u16).map(|_| Vec::new()).collect();
|
||||||
for elt in index.into_iter() {
|
for elt in index.into_iter() {
|
||||||
let h = hash::hash(&elt.val) as uint;
|
let h = hash::hash(&elt.val) as uint;
|
||||||
buckets[h % 256].push(elt);
|
buckets[h % 256].push(elt);
|
||||||
|
|
|
@ -611,9 +611,9 @@ fn is_useful(cx: &MatchCheckCtxt,
|
||||||
let arity = constructor_arity(cx, &c, left_ty);
|
let arity = constructor_arity(cx, &c, left_ty);
|
||||||
let mut result = {
|
let mut result = {
|
||||||
let pat_slice = pats[];
|
let pat_slice = pats[];
|
||||||
let subpats = Vec::from_fn(arity, |i| {
|
let subpats: Vec<_> = range(0, arity).map(|i| {
|
||||||
pat_slice.get(i).map_or(DUMMY_WILD_PAT, |p| &**p)
|
pat_slice.get(i).map_or(DUMMY_WILD_PAT, |p| &**p)
|
||||||
});
|
}).collect();
|
||||||
vec![construct_witness(cx, &c, subpats, left_ty)]
|
vec![construct_witness(cx, &c, subpats, left_ty)]
|
||||||
};
|
};
|
||||||
result.extend(pats.into_iter().skip(arity));
|
result.extend(pats.into_iter().skip(arity));
|
||||||
|
@ -635,7 +635,7 @@ fn is_useful(cx: &MatchCheckCtxt,
|
||||||
match is_useful(cx, &matrix, v.tail(), witness) {
|
match is_useful(cx, &matrix, v.tail(), witness) {
|
||||||
UsefulWithWitness(pats) => {
|
UsefulWithWitness(pats) => {
|
||||||
let arity = constructor_arity(cx, &constructor, left_ty);
|
let arity = constructor_arity(cx, &constructor, left_ty);
|
||||||
let wild_pats = Vec::from_elem(arity, DUMMY_WILD_PAT);
|
let wild_pats: Vec<_> = repeat(DUMMY_WILD_PAT).take(arity).collect();
|
||||||
let enum_pat = construct_witness(cx, &constructor, wild_pats, left_ty);
|
let enum_pat = construct_witness(cx, &constructor, wild_pats, left_ty);
|
||||||
let mut new_pats = vec![enum_pat];
|
let mut new_pats = vec![enum_pat];
|
||||||
new_pats.extend(pats.into_iter());
|
new_pats.extend(pats.into_iter());
|
||||||
|
@ -788,7 +788,7 @@ pub fn specialize<'a>(cx: &MatchCheckCtxt, r: &[&'a Pat],
|
||||||
} = raw_pat(r[col]);
|
} = raw_pat(r[col]);
|
||||||
let head: Option<Vec<&Pat>> = match *node {
|
let head: Option<Vec<&Pat>> = match *node {
|
||||||
ast::PatWild(_) =>
|
ast::PatWild(_) =>
|
||||||
Some(Vec::from_elem(arity, DUMMY_WILD_PAT)),
|
Some(repeat(DUMMY_WILD_PAT).take(arity).collect()),
|
||||||
|
|
||||||
ast::PatIdent(_, _, _) => {
|
ast::PatIdent(_, _, _) => {
|
||||||
let opt_def = cx.tcx.def_map.borrow().get(&pat_id).cloned();
|
let opt_def = cx.tcx.def_map.borrow().get(&pat_id).cloned();
|
||||||
|
@ -801,7 +801,7 @@ pub fn specialize<'a>(cx: &MatchCheckCtxt, r: &[&'a Pat],
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
},
|
},
|
||||||
_ => Some(Vec::from_elem(arity, DUMMY_WILD_PAT))
|
_ => Some(repeat(DUMMY_WILD_PAT).take(arity).collect())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -815,7 +815,7 @@ pub fn specialize<'a>(cx: &MatchCheckCtxt, r: &[&'a Pat],
|
||||||
DefVariant(..) | DefStruct(..) => {
|
DefVariant(..) | DefStruct(..) => {
|
||||||
Some(match args {
|
Some(match args {
|
||||||
&Some(ref args) => args.iter().map(|p| &**p).collect(),
|
&Some(ref args) => args.iter().map(|p| &**p).collect(),
|
||||||
&None => Vec::from_elem(arity, DUMMY_WILD_PAT)
|
&None => repeat(DUMMY_WILD_PAT).take(arity).collect(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
_ => None
|
_ => None
|
||||||
|
@ -894,13 +894,13 @@ pub fn specialize<'a>(cx: &MatchCheckCtxt, r: &[&'a Pat],
|
||||||
// Fixed-length vectors.
|
// Fixed-length vectors.
|
||||||
Single => {
|
Single => {
|
||||||
let mut pats: Vec<&Pat> = before.iter().map(|p| &**p).collect();
|
let mut pats: Vec<&Pat> = before.iter().map(|p| &**p).collect();
|
||||||
pats.grow_fn(arity - before.len() - after.len(), |_| DUMMY_WILD_PAT);
|
pats.extend(repeat(DUMMY_WILD_PAT).take(arity - before.len() - after.len()));
|
||||||
pats.extend(after.iter().map(|p| &**p));
|
pats.extend(after.iter().map(|p| &**p));
|
||||||
Some(pats)
|
Some(pats)
|
||||||
},
|
},
|
||||||
Slice(length) if before.len() + after.len() <= length && slice.is_some() => {
|
Slice(length) if before.len() + after.len() <= length && slice.is_some() => {
|
||||||
let mut pats: Vec<&Pat> = before.iter().map(|p| &**p).collect();
|
let mut pats: Vec<&Pat> = before.iter().map(|p| &**p).collect();
|
||||||
pats.grow_fn(arity - before.len() - after.len(), |_| DUMMY_WILD_PAT);
|
pats.extend(repeat(DUMMY_WILD_PAT).take(arity - before.len() - after.len()));
|
||||||
pats.extend(after.iter().map(|p| &**p));
|
pats.extend(after.iter().map(|p| &**p));
|
||||||
Some(pats)
|
Some(pats)
|
||||||
},
|
},
|
||||||
|
|
|
@ -21,6 +21,7 @@ use middle::cfg::CFGIndex;
|
||||||
use middle::ty;
|
use middle::ty;
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::uint;
|
use std::uint;
|
||||||
|
use std::iter::repeat;
|
||||||
use syntax::ast;
|
use syntax::ast;
|
||||||
use syntax::ast_util::IdRange;
|
use syntax::ast_util::IdRange;
|
||||||
use syntax::visit;
|
use syntax::visit;
|
||||||
|
@ -203,9 +204,9 @@ impl<'a, 'tcx, O:DataFlowOperator> DataFlowContext<'a, 'tcx, O> {
|
||||||
|
|
||||||
let entry = if oper.initial_value() { uint::MAX } else {0};
|
let entry = if oper.initial_value() { uint::MAX } else {0};
|
||||||
|
|
||||||
let gens = Vec::from_elem(num_nodes * words_per_id, 0);
|
let gens: Vec<_> = repeat(0).take(num_nodes * words_per_id).collect();
|
||||||
let kills = Vec::from_elem(num_nodes * words_per_id, 0);
|
let kills: Vec<_> = repeat(0).take(num_nodes * words_per_id).collect();
|
||||||
let on_entry = Vec::from_elem(num_nodes * words_per_id, entry);
|
let on_entry: Vec<_> = repeat(entry).take(num_nodes * words_per_id).collect();
|
||||||
|
|
||||||
let nodeid_to_index = build_nodeid_to_index(decl, cfg);
|
let nodeid_to_index = build_nodeid_to_index(decl, cfg);
|
||||||
|
|
||||||
|
@ -446,7 +447,7 @@ impl<'a, 'tcx, O:DataFlowOperator+Clone+'static> DataFlowContext<'a, 'tcx, O> {
|
||||||
changed: true
|
changed: true
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut temp = Vec::from_elem(words_per_id, 0u);
|
let mut temp: Vec<_> = repeat(0u).take(words_per_id).collect();
|
||||||
while propcx.changed {
|
while propcx.changed {
|
||||||
propcx.changed = false;
|
propcx.changed = false;
|
||||||
propcx.reset(temp.as_mut_slice());
|
propcx.reset(temp.as_mut_slice());
|
||||||
|
|
|
@ -1187,7 +1187,7 @@ impl<'a, 'tcx> Rebuilder<'a, 'tcx> {
|
||||||
let mut new_ty = P(ty.clone());
|
let mut new_ty = P(ty.clone());
|
||||||
let mut ty_queue = vec!(ty);
|
let mut ty_queue = vec!(ty);
|
||||||
while !ty_queue.is_empty() {
|
while !ty_queue.is_empty() {
|
||||||
let cur_ty = ty_queue.remove(0).unwrap();
|
let cur_ty = ty_queue.remove(0);
|
||||||
match cur_ty.node {
|
match cur_ty.node {
|
||||||
ast::TyRptr(lt_opt, ref mut_ty) => {
|
ast::TyRptr(lt_opt, ref mut_ty) => {
|
||||||
let rebuild = match lt_opt {
|
let rebuild = match lt_opt {
|
||||||
|
|
|
@ -799,7 +799,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn next_ty_vars(&self, n: uint) -> Vec<Ty<'tcx>> {
|
pub fn next_ty_vars(&self, n: uint) -> Vec<Ty<'tcx>> {
|
||||||
Vec::from_fn(n, |_i| self.next_ty_var())
|
range(0, n).map(|_i| self.next_ty_var()).collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn next_int_var_id(&self) -> IntVid {
|
pub fn next_int_var_id(&self) -> IntVid {
|
||||||
|
|
|
@ -34,6 +34,7 @@ use util::ppaux::Repr;
|
||||||
|
|
||||||
use std::cell::{Cell, RefCell};
|
use std::cell::{Cell, RefCell};
|
||||||
use std::u32;
|
use std::u32;
|
||||||
|
use std::iter::repeat;
|
||||||
use syntax::ast;
|
use syntax::ast;
|
||||||
|
|
||||||
mod doc;
|
mod doc;
|
||||||
|
@ -975,7 +976,7 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn construct_var_data(&self) -> Vec<VarData> {
|
fn construct_var_data(&self) -> Vec<VarData> {
|
||||||
Vec::from_fn(self.num_vars() as uint, |_| {
|
range(0, self.num_vars() as uint).map(|_| {
|
||||||
VarData {
|
VarData {
|
||||||
// All nodes are initially classified as contracting; during
|
// All nodes are initially classified as contracting; during
|
||||||
// the expansion phase, we will shift the classification for
|
// the expansion phase, we will shift the classification for
|
||||||
|
@ -984,7 +985,7 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> {
|
||||||
classification: Contracting,
|
classification: Contracting,
|
||||||
value: NoValue,
|
value: NoValue,
|
||||||
}
|
}
|
||||||
})
|
}).collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dump_constraints(&self) {
|
fn dump_constraints(&self) {
|
||||||
|
@ -1247,7 +1248,7 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> {
|
||||||
// idea is to report errors that derive from independent
|
// idea is to report errors that derive from independent
|
||||||
// regions of the graph, but not those that derive from
|
// regions of the graph, but not those that derive from
|
||||||
// overlapping locations.
|
// overlapping locations.
|
||||||
let mut dup_vec = Vec::from_elem(self.num_vars() as uint, u32::MAX);
|
let mut dup_vec: Vec<_> = repeat(u32::MAX).take(self.num_vars() as uint).collect();
|
||||||
|
|
||||||
let mut opt_graph = None;
|
let mut opt_graph = None;
|
||||||
|
|
||||||
|
@ -1308,7 +1309,7 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Vec::from_fn(self.num_vars() as uint, |idx| var_data[idx].value)
|
range(0, self.num_vars() as uint).map(|idx| var_data[idx].value).collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn construct_graph(&self) -> RegionGraph {
|
fn construct_graph(&self) -> RegionGraph {
|
||||||
|
|
|
@ -117,6 +117,7 @@ use util::nodemap::NodeMap;
|
||||||
|
|
||||||
use std::{fmt, io, uint};
|
use std::{fmt, io, uint};
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
use std::iter::repeat;
|
||||||
use syntax::ast::{mod, NodeId, Expr};
|
use syntax::ast::{mod, NodeId, Expr};
|
||||||
use syntax::codemap::{BytePos, original_sp, Span};
|
use syntax::codemap::{BytePos, original_sp, Span};
|
||||||
use syntax::parse::token::{mod, special_idents};
|
use syntax::parse::token::{mod, special_idents};
|
||||||
|
@ -575,8 +576,8 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
|
||||||
Liveness {
|
Liveness {
|
||||||
ir: ir,
|
ir: ir,
|
||||||
s: specials,
|
s: specials,
|
||||||
successors: Vec::from_elem(num_live_nodes, invalid_node()),
|
successors: repeat(invalid_node()).take(num_live_nodes).collect(),
|
||||||
users: Vec::from_elem(num_live_nodes * num_vars, invalid_users()),
|
users: repeat(invalid_users()).take(num_live_nodes * num_vars).collect(),
|
||||||
loop_scope: Vec::new(),
|
loop_scope: Vec::new(),
|
||||||
break_ln: NodeMap::new(),
|
break_ln: NodeMap::new(),
|
||||||
cont_ln: NodeMap::new(),
|
cont_ln: NodeMap::new(),
|
||||||
|
@ -1068,7 +1069,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
|
||||||
// the same bindings, and we also consider the first pattern to be
|
// the same bindings, and we also consider the first pattern to be
|
||||||
// the "authoritative" set of ids
|
// the "authoritative" set of ids
|
||||||
let arm_succ =
|
let arm_succ =
|
||||||
self.define_bindings_in_arm_pats(arm.pats.head().map(|p| &**p),
|
self.define_bindings_in_arm_pats(arm.pats.first().map(|p| &**p),
|
||||||
guard_succ);
|
guard_succ);
|
||||||
self.merge_from_succ(ln, arm_succ, first_merge);
|
self.merge_from_succ(ln, arm_succ, first_merge);
|
||||||
first_merge = false;
|
first_merge = false;
|
||||||
|
@ -1436,7 +1437,7 @@ fn check_arm(this: &mut Liveness, arm: &ast::Arm) {
|
||||||
// only consider the first pattern; any later patterns must have
|
// only consider the first pattern; any later patterns must have
|
||||||
// the same bindings, and we also consider the first pattern to be
|
// the same bindings, and we also consider the first pattern to be
|
||||||
// the "authoritative" set of ids
|
// the "authoritative" set of ids
|
||||||
this.arm_pats_bindings(arm.pats.head().map(|p| &**p), |this, ln, var, sp, id| {
|
this.arm_pats_bindings(arm.pats.first().map(|p| &**p), |this, ln, var, sp, id| {
|
||||||
this.warn_about_unused(sp, id, ln, var);
|
this.warn_about_unused(sp, id, ln, var);
|
||||||
});
|
});
|
||||||
visit::walk_arm(this, arm);
|
visit::walk_arm(this, arm);
|
||||||
|
@ -1542,7 +1543,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
|
||||||
} else {
|
} else {
|
||||||
let ends_with_stmt = match body.expr {
|
let ends_with_stmt = match body.expr {
|
||||||
None if body.stmts.len() > 0 =>
|
None if body.stmts.len() > 0 =>
|
||||||
match body.stmts.last().unwrap().node {
|
match body.stmts.first().unwrap().node {
|
||||||
ast::StmtSemi(ref e, _) => {
|
ast::StmtSemi(ref e, _) => {
|
||||||
ty::expr_ty(self.ir.tcx, &**e) == t_ret
|
ty::expr_ty(self.ir.tcx, &**e) == t_ret
|
||||||
},
|
},
|
||||||
|
@ -1553,7 +1554,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
|
||||||
self.ir.tcx.sess.span_err(
|
self.ir.tcx.sess.span_err(
|
||||||
sp, "not all control paths return a value");
|
sp, "not all control paths return a value");
|
||||||
if ends_with_stmt {
|
if ends_with_stmt {
|
||||||
let last_stmt = body.stmts.last().unwrap();
|
let last_stmt = body.stmts.first().unwrap();
|
||||||
let original_span = original_sp(self.ir.tcx.sess.codemap(),
|
let original_span = original_sp(self.ir.tcx.sess.codemap(),
|
||||||
last_stmt.span, sp);
|
last_stmt.span, sp);
|
||||||
let span_semicolon = Span {
|
let span_semicolon = Span {
|
||||||
|
|
|
@ -751,10 +751,7 @@ impl<'a, 'tcx> PrivacyVisitor<'a, 'tcx> {
|
||||||
let orig_def = self.tcx.def_map.borrow()[path_id].clone();
|
let orig_def = self.tcx.def_map.borrow()[path_id].clone();
|
||||||
let ck = |tyname: &str| {
|
let ck = |tyname: &str| {
|
||||||
let ck_public = |def: ast::DefId| {
|
let ck_public = |def: ast::DefId| {
|
||||||
let name = token::get_ident(path.segments
|
let name = token::get_ident(path.segments.last().unwrap().identifier);
|
||||||
.last()
|
|
||||||
.unwrap()
|
|
||||||
.identifier);
|
|
||||||
let origdid = orig_def.def_id();
|
let origdid = orig_def.def_id();
|
||||||
self.ensure_public(span,
|
self.ensure_public(span,
|
||||||
def,
|
def,
|
||||||
|
|
|
@ -296,7 +296,7 @@ impl<'a> LifetimeContext<'a> {
|
||||||
debug!("visit_early_late: referenced_idents={}",
|
debug!("visit_early_late: referenced_idents={}",
|
||||||
referenced_idents);
|
referenced_idents);
|
||||||
|
|
||||||
let (early, late) = generics.lifetimes.clone().partition(
|
let (early, late): (Vec<_>, _) = generics.lifetimes.iter().cloned().partition(
|
||||||
|l| referenced_idents.iter().any(|&i| i == l.lifetime.name));
|
|l| referenced_idents.iter().any(|&i| i == l.lifetime.name));
|
||||||
|
|
||||||
self.with(EarlyScope(early_space, &early, self.scope), move |old_scope, this| {
|
self.with(EarlyScope(early_space, &early, self.scope), move |old_scope, this| {
|
||||||
|
|
|
@ -323,7 +323,11 @@ impl<T> VecPerParamSpace<T> {
|
||||||
SelfSpace => { self.self_limit -= 1; }
|
SelfSpace => { self.self_limit -= 1; }
|
||||||
FnSpace => {}
|
FnSpace => {}
|
||||||
}
|
}
|
||||||
self.content.remove(limit - 1)
|
if self.content.is_empty() {
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
Some(self.content.remove(limit - 1))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ pub fn lev_distance(me: &str, t: &str) -> uint {
|
||||||
if me.is_empty() { return t.chars().count(); }
|
if me.is_empty() { return t.chars().count(); }
|
||||||
if t.is_empty() { return me.chars().count(); }
|
if t.is_empty() { return me.chars().count(); }
|
||||||
|
|
||||||
let mut dcol = Vec::from_fn(t.len() + 1, |x| x);
|
let mut dcol: Vec<_> = range(0, t.len() + 1).collect();
|
||||||
let mut t_last = 0;
|
let mut t_last = 0;
|
||||||
|
|
||||||
for (i, sc) in me.chars().enumerate() {
|
for (i, sc) in me.chars().enumerate() {
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
|
|
||||||
#![allow(deprecated)] // to_be32
|
#![allow(deprecated)] // to_be32
|
||||||
|
|
||||||
use std::iter::range_step;
|
use std::iter::{range_step, repeat};
|
||||||
use std::num::Int;
|
use std::num::Int;
|
||||||
use std::slice::bytes::{MutableByteVector, copy_memory};
|
use std::slice::bytes::{MutableByteVector, copy_memory};
|
||||||
use serialize::hex::ToHex;
|
use serialize::hex::ToHex;
|
||||||
|
@ -258,7 +258,7 @@ pub trait Digest {
|
||||||
/// Convenience function that retrieves the result of a digest as a
|
/// Convenience function that retrieves the result of a digest as a
|
||||||
/// newly allocated vec of bytes.
|
/// newly allocated vec of bytes.
|
||||||
fn result_bytes(&mut self) -> Vec<u8> {
|
fn result_bytes(&mut self) -> Vec<u8> {
|
||||||
let mut buf = Vec::from_elem((self.output_bits()+7)/8, 0u8);
|
let mut buf: Vec<u8> = repeat(0u8).take((self.output_bits()+7)/8).collect();
|
||||||
self.result(buf.as_mut_slice());
|
self.result(buf.as_mut_slice());
|
||||||
buf
|
buf
|
||||||
}
|
}
|
||||||
|
@ -612,7 +612,7 @@ mod tests {
|
||||||
/// correct.
|
/// correct.
|
||||||
fn test_digest_1million_random<D: Digest>(digest: &mut D, blocksize: uint, expected: &str) {
|
fn test_digest_1million_random<D: Digest>(digest: &mut D, blocksize: uint, expected: &str) {
|
||||||
let total_size = 1000000;
|
let total_size = 1000000;
|
||||||
let buffer = Vec::from_elem(blocksize * 2, 'a' as u8);
|
let buffer: Vec<u8> = repeat('a' as u8).take(blocksize * 2).collect();
|
||||||
let mut rng = IsaacRng::new_unseeded();
|
let mut rng = IsaacRng::new_unseeded();
|
||||||
let mut count = 0;
|
let mut count = 0;
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,6 @@ use rustc::middle::mem_categorization as mc;
|
||||||
use rustc::util::ppaux::{Repr, UserString};
|
use rustc::util::ppaux::{Repr, UserString};
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use std::slice;
|
|
||||||
use syntax::ast;
|
use syntax::ast;
|
||||||
use syntax::ast_map;
|
use syntax::ast_map;
|
||||||
use syntax::attr::AttrMetaMethods;
|
use syntax::attr::AttrMetaMethods;
|
||||||
|
@ -268,9 +267,9 @@ pub fn fixup_fragment_sets<'tcx>(this: &MoveData<'tcx>, tcx: &ty::ctxt<'tcx>) {
|
||||||
return;
|
return;
|
||||||
|
|
||||||
fn non_member(elem: MovePathIndex, set: &[MovePathIndex]) -> bool {
|
fn non_member(elem: MovePathIndex, set: &[MovePathIndex]) -> bool {
|
||||||
match set.binary_search_elem(&elem) {
|
match set.binary_search(&elem) {
|
||||||
slice::BinarySearchResult::Found(_) => false,
|
Ok(_) => false,
|
||||||
slice::BinarySearchResult::NotFound(_) => true,
|
Err(_) => true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,4 +37,3 @@ pub use borrowck::FnPartsWithCFG;
|
||||||
mod borrowck;
|
mod borrowck;
|
||||||
|
|
||||||
pub mod graphviz;
|
pub mod graphviz;
|
||||||
|
|
||||||
|
|
|
@ -265,11 +265,13 @@ Available lint options:
|
||||||
lints
|
lints
|
||||||
}
|
}
|
||||||
|
|
||||||
let (plugin, builtin) = lint_store.get_lints().partitioned(|&(_, p)| p);
|
let (plugin, builtin): (Vec<_>, _) = lint_store.get_lints()
|
||||||
|
.iter().cloned().partition(|&(_, p)| p);
|
||||||
let plugin = sort_lints(plugin);
|
let plugin = sort_lints(plugin);
|
||||||
let builtin = sort_lints(builtin);
|
let builtin = sort_lints(builtin);
|
||||||
|
|
||||||
let (plugin_groups, builtin_groups) = lint_store.get_lint_groups().partitioned(|&(_, _, p)| p);
|
let (plugin_groups, builtin_groups): (Vec<_>, _) = lint_store.get_lint_groups()
|
||||||
|
.iter().cloned().partition(|&(_, _, p)| p);
|
||||||
let plugin_groups = sort_lint_groups(plugin_groups);
|
let plugin_groups = sort_lint_groups(plugin_groups);
|
||||||
let builtin_groups = sort_lint_groups(builtin_groups);
|
let builtin_groups = sort_lint_groups(builtin_groups);
|
||||||
|
|
||||||
|
@ -377,7 +379,7 @@ fn describe_codegen_flags() {
|
||||||
/// returns None.
|
/// returns None.
|
||||||
pub fn handle_options(mut args: Vec<String>) -> Option<getopts::Matches> {
|
pub fn handle_options(mut args: Vec<String>) -> Option<getopts::Matches> {
|
||||||
// Throw away the first argument, the name of the binary
|
// Throw away the first argument, the name of the binary
|
||||||
let _binary = args.remove(0).unwrap();
|
let _binary = args.remove(0);
|
||||||
|
|
||||||
if args.is_empty() {
|
if args.is_empty() {
|
||||||
// user did not write `-v` nor `-Z unstable-options`, so do not
|
// user did not write `-v` nor `-Z unstable-options`, so do not
|
||||||
|
|
|
@ -3554,9 +3554,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
Some(def) => {
|
Some(def) => {
|
||||||
debug!("(resolving type) resolved `{}` to \
|
debug!("(resolving type) resolved `{}` to \
|
||||||
type {}",
|
type {}",
|
||||||
token::get_ident(path.segments
|
token::get_ident(path.segments.last().unwrap() .identifier),
|
||||||
.last().unwrap()
|
|
||||||
.identifier),
|
|
||||||
def);
|
def);
|
||||||
result_def = Some(def);
|
result_def = Some(def);
|
||||||
}
|
}
|
||||||
|
@ -3747,19 +3745,13 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
self.resolve_error(path.span,
|
self.resolve_error(path.span,
|
||||||
format!("`{}` is not an enum variant, struct or const",
|
format!("`{}` is not an enum variant, struct or const",
|
||||||
token::get_ident(
|
token::get_ident(
|
||||||
path.segments
|
path.segments.last().unwrap().identifier))[]);
|
||||||
.last()
|
|
||||||
.unwrap()
|
|
||||||
.identifier))[]);
|
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
self.resolve_error(path.span,
|
self.resolve_error(path.span,
|
||||||
format!("unresolved enum variant, struct or const `{}`",
|
format!("unresolved enum variant, struct or const `{}`",
|
||||||
token::get_ident(
|
token::get_ident(
|
||||||
path.segments
|
path.segments.last().unwrap().identifier))[]);
|
||||||
.last()
|
|
||||||
.unwrap()
|
|
||||||
.identifier))[]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3913,9 +3905,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
|
|
||||||
// Try to find a path to an item in a module.
|
// Try to find a path to an item in a module.
|
||||||
let unqualified_def =
|
let unqualified_def =
|
||||||
self.resolve_identifier(path.segments
|
self.resolve_identifier(path.segments.last().unwrap().identifier,
|
||||||
.last().unwrap()
|
|
||||||
.identifier,
|
|
||||||
namespace,
|
namespace,
|
||||||
check_ribs,
|
check_ribs,
|
||||||
path.span);
|
path.span);
|
||||||
|
|
|
@ -606,9 +606,9 @@ fn extract_variant_args<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
|
||||||
val: ValueRef)
|
val: ValueRef)
|
||||||
-> ExtractedBlock<'blk, 'tcx> {
|
-> ExtractedBlock<'blk, 'tcx> {
|
||||||
let _icx = push_ctxt("match::extract_variant_args");
|
let _icx = push_ctxt("match::extract_variant_args");
|
||||||
let args = Vec::from_fn(adt::num_args(repr, disr_val), |i| {
|
let args = range(0, adt::num_args(repr, disr_val)).map(|i| {
|
||||||
adt::trans_field_ptr(bcx, repr, val, disr_val, i)
|
adt::trans_field_ptr(bcx, repr, val, disr_val, i)
|
||||||
});
|
}).collect();
|
||||||
|
|
||||||
ExtractedBlock { vals: args, bcx: bcx }
|
ExtractedBlock { vals: args, bcx: bcx }
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@ use trans::context::CrateContext;
|
||||||
use trans::type_::Type;
|
use trans::type_::Type;
|
||||||
|
|
||||||
use std::cmp;
|
use std::cmp;
|
||||||
|
use std::iter::repeat;
|
||||||
|
|
||||||
#[deriving(Clone, Copy, PartialEq)]
|
#[deriving(Clone, Copy, PartialEq)]
|
||||||
enum RegClass {
|
enum RegClass {
|
||||||
|
@ -286,7 +287,7 @@ fn classify_ty(ty: Type) -> Vec<RegClass> {
|
||||||
}
|
}
|
||||||
|
|
||||||
let words = (ty_size(ty) + 7) / 8;
|
let words = (ty_size(ty) + 7) / 8;
|
||||||
let mut cls = Vec::from_elem(words, NoClass);
|
let mut cls: Vec<_> = repeat(NoClass).take(words).collect();
|
||||||
if words > 4 {
|
if words > 4 {
|
||||||
all_mem(cls.as_mut_slice());
|
all_mem(cls.as_mut_slice());
|
||||||
return cls;
|
return cls;
|
||||||
|
|
|
@ -25,6 +25,7 @@ use middle::ty::{mod, Ty};
|
||||||
use util::ppaux::{Repr, ty_to_string};
|
use util::ppaux::{Repr, ty_to_string};
|
||||||
|
|
||||||
use std::c_str::ToCStr;
|
use std::c_str::ToCStr;
|
||||||
|
use std::iter::repeat;
|
||||||
use libc::c_uint;
|
use libc::c_uint;
|
||||||
use syntax::{ast, ast_util};
|
use syntax::{ast, ast_util};
|
||||||
use syntax::ptr::P;
|
use syntax::ptr::P;
|
||||||
|
@ -608,7 +609,7 @@ fn const_expr_unadjusted(cx: &CrateContext, e: &ast::Expr) -> ValueRef {
|
||||||
const_eval::const_uint(i) => i as uint,
|
const_eval::const_uint(i) => i as uint,
|
||||||
_ => cx.sess().span_bug(count.span, "count must be integral const expression.")
|
_ => cx.sess().span_bug(count.span, "count must be integral const expression.")
|
||||||
};
|
};
|
||||||
let vs = Vec::from_elem(n, const_expr(cx, &**elem).0);
|
let vs: Vec<_> = repeat(const_expr(cx, &**elem).0).take(n).collect();
|
||||||
if vs.iter().any(|vi| val_ty(*vi) != llunitty) {
|
if vs.iter().any(|vi| val_ty(*vi) != llunitty) {
|
||||||
C_struct(cx, vs[], false)
|
C_struct(cx, vs[], false)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -3405,10 +3405,7 @@ fn create_scope_map(cx: &CrateContext,
|
||||||
if need_new_scope {
|
if need_new_scope {
|
||||||
// Create a new lexical scope and push it onto the stack
|
// Create a new lexical scope and push it onto the stack
|
||||||
let loc = cx.sess().codemap().lookup_char_pos(pat.span.lo);
|
let loc = cx.sess().codemap().lookup_char_pos(pat.span.lo);
|
||||||
let file_metadata = file_metadata(cx,
|
let file_metadata = file_metadata(cx, loc.file.name[]);
|
||||||
loc.file
|
|
||||||
.name
|
|
||||||
[]);
|
|
||||||
let parent_scope = scope_stack.last().unwrap().scope_metadata;
|
let parent_scope = scope_stack.last().unwrap().scope_metadata;
|
||||||
|
|
||||||
let scope_metadata = unsafe {
|
let scope_metadata = unsafe {
|
||||||
|
|
|
@ -68,6 +68,7 @@ use syntax::print::pprust::{expr_to_string};
|
||||||
use syntax::ptr::P;
|
use syntax::ptr::P;
|
||||||
use syntax::parse::token;
|
use syntax::parse::token;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
use std::iter::repeat;
|
||||||
|
|
||||||
// Destinations
|
// Destinations
|
||||||
|
|
||||||
|
@ -1413,7 +1414,7 @@ fn trans_struct<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
|
||||||
|
|
||||||
let tcx = bcx.tcx();
|
let tcx = bcx.tcx();
|
||||||
with_field_tys(tcx, ty, Some(expr_id), |discr, field_tys| {
|
with_field_tys(tcx, ty, Some(expr_id), |discr, field_tys| {
|
||||||
let mut need_base = Vec::from_elem(field_tys.len(), true);
|
let mut need_base: Vec<_> = repeat(true).take(field_tys.len()).collect();
|
||||||
|
|
||||||
let numbered_fields = fields.iter().map(|field| {
|
let numbered_fields = fields.iter().map(|field| {
|
||||||
let opt_pos =
|
let opt_pos =
|
||||||
|
|
|
@ -22,6 +22,7 @@ use syntax::ast;
|
||||||
use std::c_str::ToCStr;
|
use std::c_str::ToCStr;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
|
use std::iter::repeat;
|
||||||
|
|
||||||
use libc::c_uint;
|
use libc::c_uint;
|
||||||
|
|
||||||
|
@ -282,7 +283,7 @@ impl Type {
|
||||||
if n_elts == 0 {
|
if n_elts == 0 {
|
||||||
return Vec::new();
|
return Vec::new();
|
||||||
}
|
}
|
||||||
let mut elts = Vec::from_elem(n_elts, Type { rf: 0 as TypeRef });
|
let mut elts: Vec<_> = repeat(Type { rf: 0 as TypeRef }).take(n_elts).collect();
|
||||||
llvm::LLVMGetStructElementTypes(self.to_ref(),
|
llvm::LLVMGetStructElementTypes(self.to_ref(),
|
||||||
elts.as_mut_ptr() as *mut TypeRef);
|
elts.as_mut_ptr() as *mut TypeRef);
|
||||||
elts
|
elts
|
||||||
|
@ -296,7 +297,7 @@ impl Type {
|
||||||
pub fn func_params(&self) -> Vec<Type> {
|
pub fn func_params(&self) -> Vec<Type> {
|
||||||
unsafe {
|
unsafe {
|
||||||
let n_args = llvm::LLVMCountParamTypes(self.to_ref()) as uint;
|
let n_args = llvm::LLVMCountParamTypes(self.to_ref()) as uint;
|
||||||
let mut args = Vec::from_elem(n_args, Type { rf: 0 as TypeRef });
|
let mut args: Vec<_> = repeat(Type { rf: 0 as TypeRef }).take(n_args).collect();
|
||||||
llvm::LLVMGetParamTypes(self.to_ref(),
|
llvm::LLVMGetParamTypes(self.to_ref(),
|
||||||
args.as_mut_ptr() as *mut TypeRef);
|
args.as_mut_ptr() as *mut TypeRef);
|
||||||
args
|
args
|
||||||
|
|
|
@ -62,7 +62,7 @@ use util::nodemap::DefIdMap;
|
||||||
use util::ppaux::{mod, Repr, UserString};
|
use util::ppaux::{mod, Repr, UserString};
|
||||||
|
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use std::iter::AdditiveIterator;
|
use std::iter::{repeat, AdditiveIterator};
|
||||||
use syntax::{abi, ast, ast_util};
|
use syntax::{abi, ast, ast_util};
|
||||||
use syntax::codemap::Span;
|
use syntax::codemap::Span;
|
||||||
use syntax::parse::token;
|
use syntax::parse::token;
|
||||||
|
@ -317,8 +317,8 @@ fn create_substs_for_ast_path<'tcx,AC,RS>(
|
||||||
|
|
||||||
match anon_regions {
|
match anon_regions {
|
||||||
Ok(v) => v.into_iter().collect(),
|
Ok(v) => v.into_iter().collect(),
|
||||||
Err(_) => Vec::from_fn(expected_num_region_params,
|
Err(_) => range(0, expected_num_region_params)
|
||||||
|_| ty::ReStatic) // hokey
|
.map(|_| ty::ReStatic).collect() // hokey
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -500,7 +500,7 @@ fn convert_parenthesized_parameters<'tcx,AC>(this: &AC,
|
||||||
.map(|a_t| ast_ty_to_ty(this, &binding_rscope, &**a_t))
|
.map(|a_t| ast_ty_to_ty(this, &binding_rscope, &**a_t))
|
||||||
.collect::<Vec<Ty<'tcx>>>();
|
.collect::<Vec<Ty<'tcx>>>();
|
||||||
|
|
||||||
let input_params = Vec::from_elem(inputs.len(), String::new());
|
let input_params: Vec<_> = repeat(String::new()).take(inputs.len()).collect();
|
||||||
let (implied_output_region,
|
let (implied_output_region,
|
||||||
params_lifetimes) = find_implied_output_region(&*inputs, input_params);
|
params_lifetimes) = find_implied_output_region(&*inputs, input_params);
|
||||||
|
|
||||||
|
@ -734,8 +734,8 @@ pub fn ast_path_to_ty_relaxed<'tcx,AC,RS>(
|
||||||
path.segments.iter().all(|s| s.parameters.is_empty());
|
path.segments.iter().all(|s| s.parameters.is_empty());
|
||||||
|
|
||||||
let substs = if needs_defaults {
|
let substs = if needs_defaults {
|
||||||
let type_params = Vec::from_fn(generics.types.len(TypeSpace),
|
let type_params: Vec<_> = range(0, generics.types.len(TypeSpace))
|
||||||
|_| this.ty_infer(path.span));
|
.map(|_| this.ty_infer(path.span)).collect();
|
||||||
let region_params =
|
let region_params =
|
||||||
rscope.anon_regions(path.span, generics.regions.len(TypeSpace))
|
rscope.anon_regions(path.span, generics.regions.len(TypeSpace))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
@ -1528,21 +1528,18 @@ fn conv_ty_poly_trait_ref<'tcx, AC, RS>(
|
||||||
let mut partitioned_bounds = partition_bounds(this.tcx(), span, ast_bounds[]);
|
let mut partitioned_bounds = partition_bounds(this.tcx(), span, ast_bounds[]);
|
||||||
|
|
||||||
let mut projection_bounds = Vec::new();
|
let mut projection_bounds = Vec::new();
|
||||||
let main_trait_bound = match partitioned_bounds.trait_bounds.remove(0) {
|
let main_trait_bound = if !partitioned_bounds.trait_bounds.is_empty() {
|
||||||
Some(trait_bound) => {
|
let trait_bound = partitioned_bounds.trait_bounds.remove(0);
|
||||||
let ptr = instantiate_poly_trait_ref(this,
|
Some(instantiate_poly_trait_ref(this,
|
||||||
rscope,
|
rscope,
|
||||||
trait_bound,
|
trait_bound,
|
||||||
None,
|
None,
|
||||||
&mut projection_bounds);
|
&mut projection_bounds))
|
||||||
Some(ptr)
|
} else {
|
||||||
}
|
this.tcx().sess.span_err(
|
||||||
None => {
|
span,
|
||||||
this.tcx().sess.span_err(
|
"at least one non-builtin trait is required for an object type");
|
||||||
span,
|
None
|
||||||
"at least one non-builtin trait is required for an object type");
|
|
||||||
None
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let bounds =
|
let bounds =
|
||||||
|
|
|
@ -124,7 +124,8 @@ pub fn check_pat<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>,
|
||||||
check_pat_struct(pcx, pat, path, fields.as_slice(), etc, expected);
|
check_pat_struct(pcx, pat, path, fields.as_slice(), etc, expected);
|
||||||
}
|
}
|
||||||
ast::PatTup(ref elements) => {
|
ast::PatTup(ref elements) => {
|
||||||
let element_tys = Vec::from_fn(elements.len(), |_| fcx.infcx().next_ty_var());
|
let element_tys: Vec<_> = range(0, elements.len()).map(|_| fcx.infcx()
|
||||||
|
.next_ty_var()).collect();
|
||||||
let pat_ty = ty::mk_tup(tcx, element_tys.clone());
|
let pat_ty = ty::mk_tup(tcx, element_tys.clone());
|
||||||
fcx.write_ty(pat.id, pat_ty);
|
fcx.write_ty(pat.id, pat_ty);
|
||||||
demand::eqtype(fcx, pat.span, expected, pat_ty);
|
demand::eqtype(fcx, pat.span, expected, pat_ty);
|
||||||
|
|
|
@ -24,6 +24,7 @@ use syntax::ast;
|
||||||
use syntax::codemap::Span;
|
use syntax::codemap::Span;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
|
use std::iter::repeat;
|
||||||
use util::ppaux::Repr;
|
use util::ppaux::Repr;
|
||||||
|
|
||||||
struct ConfirmContext<'a, 'tcx:'a> {
|
struct ConfirmContext<'a, 'tcx:'a> {
|
||||||
|
@ -339,7 +340,7 @@ impl<'a,'tcx> ConfirmContext<'a,'tcx> {
|
||||||
} else if num_supplied_types != num_method_types {
|
} else if num_supplied_types != num_method_types {
|
||||||
span_err!(self.tcx().sess, self.span, E0036,
|
span_err!(self.tcx().sess, self.span, E0036,
|
||||||
"incorrect number of type parameters given for this method");
|
"incorrect number of type parameters given for this method");
|
||||||
Vec::from_elem(num_method_types, self.tcx().types.err)
|
repeat(self.tcx().types.err).take(num_method_types).collect()
|
||||||
} else {
|
} else {
|
||||||
supplied_method_types
|
supplied_method_types
|
||||||
}
|
}
|
||||||
|
|
|
@ -110,6 +110,7 @@ use util::nodemap::{DefIdMap, FnvHashMap, NodeMap};
|
||||||
use std::cell::{Cell, Ref, RefCell};
|
use std::cell::{Cell, Ref, RefCell};
|
||||||
use std::mem::replace;
|
use std::mem::replace;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
use std::iter::repeat;
|
||||||
use syntax::{mod, abi, attr};
|
use syntax::{mod, abi, attr};
|
||||||
use syntax::ast::{mod, ProvidedMethod, RequiredMethod, TypeTraitItem, DefId};
|
use syntax::ast::{mod, ProvidedMethod, RequiredMethod, TypeTraitItem, DefId};
|
||||||
use syntax::ast_util::{mod, local_def, PostExpansionMethod};
|
use syntax::ast_util::{mod, local_def, PostExpansionMethod};
|
||||||
|
@ -2130,9 +2131,9 @@ impl<'a, 'tcx> RegionScope for FnCtxt<'a, 'tcx> {
|
||||||
|
|
||||||
fn anon_regions(&self, span: Span, count: uint)
|
fn anon_regions(&self, span: Span, count: uint)
|
||||||
-> Result<Vec<ty::Region>, Option<Vec<(String, uint)>>> {
|
-> Result<Vec<ty::Region>, Option<Vec<(String, uint)>>> {
|
||||||
Ok(Vec::from_fn(count, |_| {
|
Ok(range(0, count).map(|_| {
|
||||||
self.infcx().next_region_var(infer::MiscVariable(span))
|
self.infcx().next_region_var(infer::MiscVariable(span))
|
||||||
}))
|
}).collect())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2810,7 +2811,7 @@ fn check_argument_types<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
|
||||||
|
|
||||||
// FIXME(#17596) Ty<'tcx> is incorrectly invariant w.r.t 'tcx.
|
// FIXME(#17596) Ty<'tcx> is incorrectly invariant w.r.t 'tcx.
|
||||||
fn err_args<'tcx>(tcx: &ty::ctxt<'tcx>, len: uint) -> Vec<Ty<'tcx>> {
|
fn err_args<'tcx>(tcx: &ty::ctxt<'tcx>, len: uint) -> Vec<Ty<'tcx>> {
|
||||||
Vec::from_fn(len, |_| tcx.types.err)
|
range(0, len).map(|_| tcx.types.err).collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn write_call<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
|
fn write_call<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
|
||||||
|
@ -5166,7 +5167,7 @@ pub fn instantiate_path<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
|
||||||
// The first step then is to categorize the segments appropriately.
|
// The first step then is to categorize the segments appropriately.
|
||||||
|
|
||||||
assert!(path.segments.len() >= 1);
|
assert!(path.segments.len() >= 1);
|
||||||
let mut segment_spaces;
|
let mut segment_spaces: Vec<_>;
|
||||||
match def {
|
match def {
|
||||||
// Case 1 and 1b. Reference to a *type* or *enum variant*.
|
// Case 1 and 1b. Reference to a *type* or *enum variant*.
|
||||||
def::DefSelfTy(..) |
|
def::DefSelfTy(..) |
|
||||||
|
@ -5181,7 +5182,7 @@ pub fn instantiate_path<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
|
||||||
def::DefTyParam(..) => {
|
def::DefTyParam(..) => {
|
||||||
// Everything but the final segment should have no
|
// Everything but the final segment should have no
|
||||||
// parameters at all.
|
// parameters at all.
|
||||||
segment_spaces = Vec::from_elem(path.segments.len() - 1, None);
|
segment_spaces = repeat(None).take(path.segments.len() - 1).collect();
|
||||||
segment_spaces.push(Some(subst::TypeSpace));
|
segment_spaces.push(Some(subst::TypeSpace));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5189,7 +5190,7 @@ pub fn instantiate_path<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
|
||||||
def::DefFn(..) |
|
def::DefFn(..) |
|
||||||
def::DefConst(..) |
|
def::DefConst(..) |
|
||||||
def::DefStatic(..) => {
|
def::DefStatic(..) => {
|
||||||
segment_spaces = Vec::from_elem(path.segments.len() - 1, None);
|
segment_spaces = repeat(None).take(path.segments.len() - 1).collect();
|
||||||
segment_spaces.push(Some(subst::FnSpace));
|
segment_spaces.push(Some(subst::FnSpace));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5205,7 +5206,7 @@ pub fn instantiate_path<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
|
||||||
def::FromImpl(_) => {}
|
def::FromImpl(_) => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
segment_spaces = Vec::from_elem(path.segments.len() - 2, None);
|
segment_spaces = repeat(None).take(path.segments.len() - 2).collect();
|
||||||
segment_spaces.push(Some(subst::TypeSpace));
|
segment_spaces.push(Some(subst::TypeSpace));
|
||||||
segment_spaces.push(Some(subst::FnSpace));
|
segment_spaces.push(Some(subst::FnSpace));
|
||||||
}
|
}
|
||||||
|
@ -5220,7 +5221,7 @@ pub fn instantiate_path<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
|
||||||
def::DefRegion(..) |
|
def::DefRegion(..) |
|
||||||
def::DefLabel(..) |
|
def::DefLabel(..) |
|
||||||
def::DefUpvar(..) => {
|
def::DefUpvar(..) => {
|
||||||
segment_spaces = Vec::from_elem(path.segments.len(), None);
|
segment_spaces = repeat(None).take(path.segments.len()).collect();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assert_eq!(segment_spaces.len(), path.segments.len());
|
assert_eq!(segment_spaces.len(), path.segments.len());
|
||||||
|
@ -5489,8 +5490,7 @@ pub fn instantiate_path<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
|
||||||
"too few type parameters provided: expected {}{} parameter(s) \
|
"too few type parameters provided: expected {}{} parameter(s) \
|
||||||
, found {} parameter(s)",
|
, found {} parameter(s)",
|
||||||
qualifier, required_len, provided_len);
|
qualifier, required_len, provided_len);
|
||||||
substs.types.replace(space,
|
substs.types.replace(space, repeat(fcx.tcx().types.err).take(desired.len()).collect());
|
||||||
Vec::from_elem(desired.len(), fcx.tcx().types.err));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5614,7 +5614,7 @@ pub fn check_bounds_are_used<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
|
||||||
|
|
||||||
// make a vector of booleans initially false, set to true when used
|
// make a vector of booleans initially false, set to true when used
|
||||||
if tps.len() == 0u { return; }
|
if tps.len() == 0u { return; }
|
||||||
let mut tps_used = Vec::from_elem(tps.len(), false);
|
let mut tps_used: Vec<_> = repeat(false).take(tps.len()).collect();
|
||||||
|
|
||||||
ty::walk_ty(ty, |t| {
|
ty::walk_ty(ty, |t| {
|
||||||
match t.sty {
|
match t.sty {
|
||||||
|
|
|
@ -409,4 +409,3 @@ impl<'tcx> Repr<'tcx> for WfConstraint<'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,7 @@ use middle::ty;
|
||||||
use middle::ty_fold;
|
use middle::ty_fold;
|
||||||
|
|
||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
|
use std::iter::repeat;
|
||||||
use syntax::codemap::Span;
|
use syntax::codemap::Span;
|
||||||
|
|
||||||
/// Defines strategies for handling regions that are omitted. For
|
/// Defines strategies for handling regions that are omitted. For
|
||||||
|
@ -99,7 +100,7 @@ impl RegionScope for SpecificRscope {
|
||||||
count: uint)
|
count: uint)
|
||||||
-> Result<Vec<ty::Region>, Option<Vec<(String, uint)>>>
|
-> Result<Vec<ty::Region>, Option<Vec<(String, uint)>>>
|
||||||
{
|
{
|
||||||
Ok(Vec::from_elem(count, self.default))
|
Ok(repeat(self.default).take(count).collect())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,7 +135,7 @@ impl RegionScope for BindingRscope {
|
||||||
count: uint)
|
count: uint)
|
||||||
-> Result<Vec<ty::Region>, Option<Vec<(String, uint)>>>
|
-> Result<Vec<ty::Region>, Option<Vec<(String, uint)>>>
|
||||||
{
|
{
|
||||||
Ok(Vec::from_fn(count, |_| self.next_region()))
|
Ok(range(0, count).map(|_| self.next_region()).collect())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -199,6 +199,7 @@ use middle::subst::{ParamSpace, FnSpace, TypeSpace, SelfSpace, VecPerParamSpace}
|
||||||
use middle::ty::{mod, Ty};
|
use middle::ty::{mod, Ty};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
use std::iter::repeat;
|
||||||
use syntax::ast;
|
use syntax::ast;
|
||||||
use syntax::ast_map;
|
use syntax::ast_map;
|
||||||
use syntax::ast_util;
|
use syntax::ast_util;
|
||||||
|
@ -971,7 +972,7 @@ struct SolveContext<'a, 'tcx: 'a> {
|
||||||
|
|
||||||
fn solve_constraints(constraints_cx: ConstraintContext) {
|
fn solve_constraints(constraints_cx: ConstraintContext) {
|
||||||
let ConstraintContext { terms_cx, constraints, .. } = constraints_cx;
|
let ConstraintContext { terms_cx, constraints, .. } = constraints_cx;
|
||||||
let solutions = Vec::from_elem(terms_cx.num_inferred(), ty::Bivariant);
|
let solutions: Vec<_> = repeat(ty::Bivariant).take(terms_cx.num_inferred()).collect();
|
||||||
let mut solutions_cx = SolveContext {
|
let mut solutions_cx = SolveContext {
|
||||||
terms_cx: terms_cx,
|
terms_cx: terms_cx,
|
||||||
constraints: constraints,
|
constraints: constraints,
|
||||||
|
|
|
@ -398,7 +398,7 @@ fn primitive_link(f: &mut fmt::Formatter,
|
||||||
Some(root) => {
|
Some(root) => {
|
||||||
try!(write!(f, "<a href='{}{}/primitive.{}.html'>",
|
try!(write!(f, "<a href='{}{}/primitive.{}.html'>",
|
||||||
root,
|
root,
|
||||||
path.0.head().unwrap(),
|
path.0.first().unwrap(),
|
||||||
prim.to_url_str()));
|
prim.to_url_str()));
|
||||||
needs_termination = true;
|
needs_termination = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1799,7 +1799,7 @@ fn item_trait(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
|
||||||
try!(write!(w, r#"<script type="text/javascript" async
|
try!(write!(w, r#"<script type="text/javascript" async
|
||||||
src="{root_path}/implementors/{path}/{ty}.{name}.js">
|
src="{root_path}/implementors/{path}/{ty}.{name}.js">
|
||||||
</script>"#,
|
</script>"#,
|
||||||
root_path = Vec::from_elem(cx.current.len(), "..").connect("/"),
|
root_path = repeat("..").take(cx.current.len()).collect::<Vec<_>>().connect("/"),
|
||||||
path = if ast_util::is_local(it.def_id) {
|
path = if ast_util::is_local(it.def_id) {
|
||||||
cx.current.connect("/")
|
cx.current.connect("/")
|
||||||
} else {
|
} else {
|
||||||
|
@ -2055,7 +2055,8 @@ fn render_struct(w: &mut fmt::Formatter, it: &clean::Item,
|
||||||
fn render_methods(w: &mut fmt::Formatter, it: &clean::Item) -> fmt::Result {
|
fn render_methods(w: &mut fmt::Formatter, it: &clean::Item) -> fmt::Result {
|
||||||
match cache().impls.get(&it.def_id) {
|
match cache().impls.get(&it.def_id) {
|
||||||
Some(v) => {
|
Some(v) => {
|
||||||
let (non_trait, traits) = v.partitioned(|i| i.impl_.trait_.is_none());
|
let (non_trait, traits): (Vec<_>, _) = v.iter().cloned()
|
||||||
|
.partition(|i| i.impl_.trait_.is_none());
|
||||||
if non_trait.len() > 0 {
|
if non_trait.len() > 0 {
|
||||||
try!(write!(w, "<h2 id='methods'>Methods</h2>"));
|
try!(write!(w, "<h2 id='methods'>Methods</h2>"));
|
||||||
for i in non_trait.iter() {
|
for i in non_trait.iter() {
|
||||||
|
@ -2065,7 +2066,8 @@ fn render_methods(w: &mut fmt::Formatter, it: &clean::Item) -> fmt::Result {
|
||||||
if traits.len() > 0 {
|
if traits.len() > 0 {
|
||||||
try!(write!(w, "<h2 id='implementations'>Trait \
|
try!(write!(w, "<h2 id='implementations'>Trait \
|
||||||
Implementations</h2>"));
|
Implementations</h2>"));
|
||||||
let (derived, manual) = traits.partition(|i| i.impl_.derived);
|
let (derived, manual): (Vec<_>, _) = traits.into_iter()
|
||||||
|
.partition(|i| i.impl_.derived);
|
||||||
for i in manual.iter() {
|
for i in manual.iter() {
|
||||||
try!(render_impl(w, i));
|
try!(render_impl(w, i));
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,7 +74,7 @@ use fmt;
|
||||||
use hash;
|
use hash;
|
||||||
use mem;
|
use mem;
|
||||||
use ptr;
|
use ptr;
|
||||||
use slice::{mod, ImmutableIntSlice};
|
use slice::{mod, IntSliceExt};
|
||||||
use str;
|
use str;
|
||||||
use string::String;
|
use string::String;
|
||||||
use core::kinds::marker;
|
use core::kinds::marker;
|
||||||
|
|
|
@ -148,7 +148,7 @@ impl<T: Send> Packet<T> {
|
||||||
tail: 0 as *mut Node,
|
tail: 0 as *mut Node,
|
||||||
},
|
},
|
||||||
buf: Buffer {
|
buf: Buffer {
|
||||||
buf: Vec::from_fn(cap + if cap == 0 {1} else {0}, |_| None),
|
buf: range(0, cap + if cap == 0 {1} else {0}).map(|_| None).collect(),
|
||||||
start: 0,
|
start: 0,
|
||||||
size: 0,
|
size: 0,
|
||||||
},
|
},
|
||||||
|
|
|
@ -439,9 +439,10 @@ mod test {
|
||||||
|
|
||||||
impl Reader for ShortReader {
|
impl Reader for ShortReader {
|
||||||
fn read(&mut self, _: &mut [u8]) -> io::IoResult<uint> {
|
fn read(&mut self, _: &mut [u8]) -> io::IoResult<uint> {
|
||||||
match self.lengths.remove(0) {
|
if self.lengths.is_empty() {
|
||||||
Some(i) => Ok(i),
|
Err(io::standard_error(io::EndOfFile))
|
||||||
None => Err(io::standard_error(io::EndOfFile))
|
} else {
|
||||||
|
Ok(self.lengths.remove(0))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -158,6 +158,7 @@ pub use alloc::rc;
|
||||||
pub use core_collections::slice;
|
pub use core_collections::slice;
|
||||||
pub use core_collections::str;
|
pub use core_collections::str;
|
||||||
pub use core_collections::string;
|
pub use core_collections::string;
|
||||||
|
#[stable]
|
||||||
pub use core_collections::vec;
|
pub use core_collections::vec;
|
||||||
|
|
||||||
pub use unicode::char;
|
pub use unicode::char;
|
||||||
|
|
|
@ -620,10 +620,11 @@ pub fn get_exit_status() -> int {
|
||||||
unsafe fn load_argc_and_argv(argc: int,
|
unsafe fn load_argc_and_argv(argc: int,
|
||||||
argv: *const *const c_char) -> Vec<Vec<u8>> {
|
argv: *const *const c_char) -> Vec<Vec<u8>> {
|
||||||
use c_str::CString;
|
use c_str::CString;
|
||||||
|
use iter::range;
|
||||||
|
|
||||||
Vec::from_fn(argc as uint, |i| {
|
range(0, argc as uint).map(|i| {
|
||||||
CString::new(*argv.offset(i as int), false).as_bytes_no_nul().to_vec()
|
CString::new(*argv.offset(i as int), false).as_bytes_no_nul().to_vec()
|
||||||
})
|
}).collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the command line arguments
|
/// Returns the command line arguments
|
||||||
|
@ -721,7 +722,7 @@ fn real_args() -> Vec<String> {
|
||||||
let lpCmdLine = unsafe { GetCommandLineW() };
|
let lpCmdLine = unsafe { GetCommandLineW() };
|
||||||
let szArgList = unsafe { CommandLineToArgvW(lpCmdLine, lpArgCount) };
|
let szArgList = unsafe { CommandLineToArgvW(lpCmdLine, lpArgCount) };
|
||||||
|
|
||||||
let args = Vec::from_fn(nArgs as uint, |i| unsafe {
|
let args: Vec<_> = range(0, nArgs as uint).map(|i| unsafe {
|
||||||
// Determine the length of this argument.
|
// Determine the length of this argument.
|
||||||
let ptr = *szArgList.offset(i as int);
|
let ptr = *szArgList.offset(i as int);
|
||||||
let mut len = 0;
|
let mut len = 0;
|
||||||
|
@ -732,7 +733,7 @@ fn real_args() -> Vec<String> {
|
||||||
let buf = slice::from_raw_buf(&ptr, len);
|
let buf = slice::from_raw_buf(&ptr, len);
|
||||||
let opt_s = String::from_utf16(sys::os::truncate_utf16_at_nul(buf));
|
let opt_s = String::from_utf16(sys::os::truncate_utf16_at_nul(buf));
|
||||||
opt_s.ok().expect("CommandLineToArgvW returned invalid UTF-16")
|
opt_s.ok().expect("CommandLineToArgvW returned invalid UTF-16")
|
||||||
});
|
}).collect();
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
LocalFree(szArgList as *mut c_void);
|
LocalFree(szArgList as *mut c_void);
|
||||||
|
|
|
@ -22,14 +22,14 @@ use option::Option::{None, Some};
|
||||||
use kinds::Sized;
|
use kinds::Sized;
|
||||||
use str::{FromStr, Str};
|
use str::{FromStr, Str};
|
||||||
use str;
|
use str;
|
||||||
use slice::{CloneSliceExt, Splits, AsSlice, VectorVector,
|
use slice::{CloneSliceExt, Split, AsSlice, SliceConcatExt,
|
||||||
PartialEqSliceExt, SliceExt};
|
PartialEqSliceExt, SliceExt};
|
||||||
use vec::Vec;
|
use vec::Vec;
|
||||||
|
|
||||||
use super::{BytesContainer, GenericPath, GenericPathUnsafe};
|
use super::{BytesContainer, GenericPath, GenericPathUnsafe};
|
||||||
|
|
||||||
/// Iterator that yields successive components of a Path as &[u8]
|
/// Iterator that yields successive components of a Path as &[u8]
|
||||||
pub type Components<'a> = Splits<'a, u8, fn(&u8) -> bool>;
|
pub type Components<'a> = Split<'a, u8, fn(&u8) -> bool>;
|
||||||
|
|
||||||
/// Iterator that yields successive components of a Path as Option<&str>
|
/// Iterator that yields successive components of a Path as Option<&str>
|
||||||
pub type StrComponents<'a> =
|
pub type StrComponents<'a> =
|
||||||
|
@ -306,7 +306,7 @@ impl GenericPath for Path {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Some(Path::new(comps.connect_vec(&SEP_BYTE)))
|
Some(Path::new(comps.as_slice().connect(&SEP_BYTE)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,8 +25,8 @@ use iter::{Iterator, IteratorExt, Map, repeat};
|
||||||
use mem;
|
use mem;
|
||||||
use option::Option;
|
use option::Option;
|
||||||
use option::Option::{Some, None};
|
use option::Option::{Some, None};
|
||||||
use slice::SliceExt;
|
use slice::{SliceExt, SliceConcatExt};
|
||||||
use str::{SplitTerminator, FromStr, StrVector, StrExt};
|
use str::{SplitTerminator, FromStr, StrExt};
|
||||||
use string::{String, ToString};
|
use string::{String, ToString};
|
||||||
use unicode::char::UnicodeChar;
|
use unicode::char::UnicodeChar;
|
||||||
use vec::Vec;
|
use vec::Vec;
|
||||||
|
|
|
@ -66,7 +66,7 @@
|
||||||
#[doc(no_inline)] pub use iter::{FromIterator, Extend, ExactSizeIterator};
|
#[doc(no_inline)] pub use iter::{FromIterator, Extend, ExactSizeIterator};
|
||||||
#[doc(no_inline)] pub use iter::{Iterator, IteratorExt, DoubleEndedIterator};
|
#[doc(no_inline)] pub use iter::{Iterator, IteratorExt, DoubleEndedIterator};
|
||||||
#[doc(no_inline)] pub use iter::{DoubleEndedIteratorExt, CloneIteratorExt};
|
#[doc(no_inline)] pub use iter::{DoubleEndedIteratorExt, CloneIteratorExt};
|
||||||
#[doc(no_inline)] pub use iter::{RandomAccessIterator, IteratorCloneExt};
|
#[doc(no_inline)] pub use iter::{RandomAccessIterator, IteratorCloneExt, IteratorPairExt};
|
||||||
#[doc(no_inline)] pub use iter::{IteratorOrdExt, MutableDoubleEndedIterator};
|
#[doc(no_inline)] pub use iter::{IteratorOrdExt, MutableDoubleEndedIterator};
|
||||||
#[doc(no_inline)] pub use num::{ToPrimitive, FromPrimitive};
|
#[doc(no_inline)] pub use num::{ToPrimitive, FromPrimitive};
|
||||||
#[doc(no_inline)] pub use boxed::Box;
|
#[doc(no_inline)] pub use boxed::Box;
|
||||||
|
@ -80,10 +80,9 @@
|
||||||
#[doc(no_inline)] pub use core::prelude::{Tuple1, Tuple2, Tuple3, Tuple4};
|
#[doc(no_inline)] pub use core::prelude::{Tuple1, Tuple2, Tuple3, Tuple4};
|
||||||
#[doc(no_inline)] pub use core::prelude::{Tuple5, Tuple6, Tuple7, Tuple8};
|
#[doc(no_inline)] pub use core::prelude::{Tuple5, Tuple6, Tuple7, Tuple8};
|
||||||
#[doc(no_inline)] pub use core::prelude::{Tuple9, Tuple10, Tuple11, Tuple12};
|
#[doc(no_inline)] pub use core::prelude::{Tuple9, Tuple10, Tuple11, Tuple12};
|
||||||
#[doc(no_inline)] pub use str::{Str, StrVector};
|
#[doc(no_inline)] pub use str::{Str, StrExt};
|
||||||
#[doc(no_inline)] pub use str::StrExt;
|
|
||||||
#[doc(no_inline)] pub use slice::AsSlice;
|
#[doc(no_inline)] pub use slice::AsSlice;
|
||||||
#[doc(no_inline)] pub use slice::{VectorVector, PartialEqSliceExt};
|
#[doc(no_inline)] pub use slice::{SliceConcatExt, PartialEqSliceExt};
|
||||||
#[doc(no_inline)] pub use slice::{CloneSliceExt, OrdSliceExt, SliceExt};
|
#[doc(no_inline)] pub use slice::{CloneSliceExt, OrdSliceExt, SliceExt};
|
||||||
#[doc(no_inline)] pub use slice::{BoxedSliceExt};
|
#[doc(no_inline)] pub use slice::{BoxedSliceExt};
|
||||||
#[doc(no_inline)] pub use string::{IntoString, String, ToString};
|
#[doc(no_inline)] pub use string::{IntoString, String, ToString};
|
||||||
|
|
|
@ -95,14 +95,14 @@ mod imp {
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe fn load_argc_and_argv(argc: int, argv: *const *const u8) -> Vec<Vec<u8>> {
|
unsafe fn load_argc_and_argv(argc: int, argv: *const *const u8) -> Vec<Vec<u8>> {
|
||||||
Vec::from_fn(argc as uint, |i| {
|
range(0, argc as uint).map(|i| {
|
||||||
let arg = *argv.offset(i as int);
|
let arg = *argv.offset(i as int);
|
||||||
let mut len = 0u;
|
let mut len = 0u;
|
||||||
while *arg.offset(len as int) != 0 {
|
while *arg.offset(len as int) != 0 {
|
||||||
len += 1u;
|
len += 1u;
|
||||||
}
|
}
|
||||||
slice::from_raw_buf(&arg, len).to_vec()
|
slice::from_raw_buf(&arg, len).to_vec()
|
||||||
})
|
}).collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
|
@ -120,9 +120,9 @@ fn helper(input: libc::c_int, messages: Receiver<Req>, _: ()) {
|
||||||
// signals the first requests in the queue, possible re-enqueueing it.
|
// signals the first requests in the queue, possible re-enqueueing it.
|
||||||
fn signal(active: &mut Vec<Box<Inner>>,
|
fn signal(active: &mut Vec<Box<Inner>>,
|
||||||
dead: &mut Vec<(uint, Box<Inner>)>) {
|
dead: &mut Vec<(uint, Box<Inner>)>) {
|
||||||
let mut timer = match active.remove(0) {
|
if active.is_empty() { return }
|
||||||
Some(timer) => timer, None => return
|
|
||||||
};
|
let mut timer = active.remove(0);
|
||||||
let mut cb = timer.cb.take().unwrap();
|
let mut cb = timer.cb.take().unwrap();
|
||||||
cb.call();
|
cb.call();
|
||||||
if timer.repeat {
|
if timer.repeat {
|
||||||
|
@ -185,7 +185,7 @@ fn helper(input: libc::c_int, messages: Receiver<Req>, _: ()) {
|
||||||
Ok(RemoveTimer(id, ack)) => {
|
Ok(RemoveTimer(id, ack)) => {
|
||||||
match dead.iter().position(|&(i, _)| id == i) {
|
match dead.iter().position(|&(i, _)| id == i) {
|
||||||
Some(i) => {
|
Some(i) => {
|
||||||
let (_, i) = dead.remove(i).unwrap();
|
let (_, i) = dead.remove(i);
|
||||||
ack.send(i);
|
ack.send(i);
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -193,7 +193,7 @@ fn helper(input: libc::c_int, messages: Receiver<Req>, _: ()) {
|
||||||
}
|
}
|
||||||
let i = active.iter().position(|i| i.id == id);
|
let i = active.iter().position(|i| i.id == id);
|
||||||
let i = i.expect("no timer found");
|
let i = i.expect("no timer found");
|
||||||
let t = active.remove(i).unwrap();
|
let t = active.remove(i);
|
||||||
ack.send(t);
|
ack.send(t);
|
||||||
}
|
}
|
||||||
Err(..) => break
|
Err(..) => break
|
||||||
|
|
|
@ -16,13 +16,14 @@
|
||||||
use prelude::*;
|
use prelude::*;
|
||||||
|
|
||||||
use io::{IoResult, IoError};
|
use io::{IoResult, IoError};
|
||||||
|
use iter::repeat;
|
||||||
use libc::{c_int, c_void};
|
use libc::{c_int, c_void};
|
||||||
use libc;
|
use libc;
|
||||||
use os;
|
use os;
|
||||||
use path::BytesContainer;
|
use path::BytesContainer;
|
||||||
use ptr;
|
use ptr;
|
||||||
use sys::fs::FileDesc;
|
|
||||||
use slice;
|
use slice;
|
||||||
|
use sys::fs::FileDesc;
|
||||||
|
|
||||||
use os::TMPBUF_SZ;
|
use os::TMPBUF_SZ;
|
||||||
use libc::types::os::arch::extra::DWORD;
|
use libc::types::os::arch::extra::DWORD;
|
||||||
|
@ -128,7 +129,7 @@ pub fn fill_utf16_buf_and_decode(f: |*mut u16, DWORD| -> DWORD) -> Option<String
|
||||||
let mut res = None;
|
let mut res = None;
|
||||||
let mut done = false;
|
let mut done = false;
|
||||||
while !done {
|
while !done {
|
||||||
let mut buf = Vec::from_elem(n as uint, 0u16);
|
let mut buf: Vec<u16> = repeat(0u16).take(n).collect();
|
||||||
let k = f(buf.as_mut_ptr(), n);
|
let k = f(buf.as_mut_ptr(), n);
|
||||||
if k == (0 as DWORD) {
|
if k == (0 as DWORD) {
|
||||||
done = true;
|
done = true;
|
||||||
|
|
|
@ -33,6 +33,7 @@ use libc::{c_int, HANDLE, LPDWORD, DWORD, LPVOID};
|
||||||
use libc::{get_osfhandle, CloseHandle};
|
use libc::{get_osfhandle, CloseHandle};
|
||||||
use libc::types::os::arch::extra::LPCVOID;
|
use libc::types::os::arch::extra::LPCVOID;
|
||||||
use io::{mod, IoError, IoResult, MemReader};
|
use io::{mod, IoError, IoResult, MemReader};
|
||||||
|
use iter::repeat;
|
||||||
use prelude::*;
|
use prelude::*;
|
||||||
use ptr;
|
use ptr;
|
||||||
use str::from_utf8;
|
use str::from_utf8;
|
||||||
|
@ -90,7 +91,7 @@ impl TTY {
|
||||||
pub fn read(&mut self, buf: &mut [u8]) -> IoResult<uint> {
|
pub fn read(&mut self, buf: &mut [u8]) -> IoResult<uint> {
|
||||||
// Read more if the buffer is empty
|
// Read more if the buffer is empty
|
||||||
if self.utf8.eof() {
|
if self.utf8.eof() {
|
||||||
let mut utf16 = Vec::from_elem(0x1000, 0u16);
|
let mut utf16: Vec<u16> = repeat(0u16).take(0x1000).collect();
|
||||||
let mut num: DWORD = 0;
|
let mut num: DWORD = 0;
|
||||||
match unsafe { ReadConsoleW(self.handle,
|
match unsafe { ReadConsoleW(self.handle,
|
||||||
utf16.as_mut_ptr() as LPVOID,
|
utf16.as_mut_ptr() as LPVOID,
|
||||||
|
|
|
@ -26,7 +26,7 @@ use arena::TypedArena;
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::io::IoResult;
|
use std::io::IoResult;
|
||||||
use std::iter;
|
use std::iter::{mod, repeat};
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use std::slice;
|
use std::slice;
|
||||||
|
|
||||||
|
@ -726,7 +726,7 @@ impl<'ast> NodeCollector<'ast> {
|
||||||
debug!("ast_map: {} => {}", id, entry);
|
debug!("ast_map: {} => {}", id, entry);
|
||||||
let len = self.map.len();
|
let len = self.map.len();
|
||||||
if id as uint >= len {
|
if id as uint >= len {
|
||||||
self.map.grow(id as uint - len + 1, NotPresent);
|
self.map.extend(repeat(NotPresent).take(id as uint - len + 1));
|
||||||
}
|
}
|
||||||
self.map[id as uint] = entry;
|
self.map[id as uint] = entry;
|
||||||
}
|
}
|
||||||
|
|
|
@ -470,7 +470,7 @@ pub fn expand_item(it: P<ast::Item>, fld: &mut MacroExpander)
|
||||||
fn expand_item_modifiers(mut it: P<ast::Item>, fld: &mut MacroExpander)
|
fn expand_item_modifiers(mut it: P<ast::Item>, fld: &mut MacroExpander)
|
||||||
-> P<ast::Item> {
|
-> P<ast::Item> {
|
||||||
// partition the attributes into ItemModifiers and others
|
// partition the attributes into ItemModifiers and others
|
||||||
let (modifiers, other_attrs) = it.attrs.partitioned(|attr| {
|
let (modifiers, other_attrs): (Vec<_>, _) = it.attrs.iter().cloned().partition(|attr| {
|
||||||
match fld.cx.syntax_env.find(&intern(attr.name().get())) {
|
match fld.cx.syntax_env.find(&intern(attr.name().get())) {
|
||||||
Some(rc) => match *rc { Modifier(_) => true, _ => false },
|
Some(rc) => match *rc { Modifier(_) => true, _ => false },
|
||||||
_ => false
|
_ => false
|
||||||
|
|
|
@ -22,6 +22,7 @@ use parse::token;
|
||||||
use ptr::P;
|
use ptr::P;
|
||||||
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
use std::iter::repeat;
|
||||||
|
|
||||||
#[deriving(PartialEq)]
|
#[deriving(PartialEq)]
|
||||||
enum ArgumentType {
|
enum ArgumentType {
|
||||||
|
@ -477,7 +478,7 @@ impl<'a, 'b> Context<'a, 'b> {
|
||||||
/// to
|
/// to
|
||||||
fn into_expr(mut self) -> P<ast::Expr> {
|
fn into_expr(mut self) -> P<ast::Expr> {
|
||||||
let mut locals = Vec::new();
|
let mut locals = Vec::new();
|
||||||
let mut names = Vec::from_fn(self.name_positions.len(), |_| None);
|
let mut names: Vec<_> = repeat(None).take(self.name_positions.len()).collect();
|
||||||
let mut pats = Vec::new();
|
let mut pats = Vec::new();
|
||||||
let mut heads = Vec::new();
|
let mut heads = Vec::new();
|
||||||
|
|
||||||
|
@ -664,7 +665,7 @@ pub fn expand_preparsed_format_args(ecx: &mut ExtCtxt, sp: Span,
|
||||||
name_ordering: Vec<String>,
|
name_ordering: Vec<String>,
|
||||||
names: HashMap<String, P<ast::Expr>>)
|
names: HashMap<String, P<ast::Expr>>)
|
||||||
-> P<ast::Expr> {
|
-> P<ast::Expr> {
|
||||||
let arg_types = Vec::from_fn(args.len(), |_| None);
|
let arg_types: Vec<_> = range(0, args.len()).map(|_| None).collect();
|
||||||
let mut cx = Context {
|
let mut cx = Context {
|
||||||
ecx: ecx,
|
ecx: ecx,
|
||||||
args: args,
|
args: args,
|
||||||
|
@ -707,13 +708,10 @@ pub fn expand_preparsed_format_args(ecx: &mut ExtCtxt, sp: Span,
|
||||||
None => break
|
None => break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
match parser.errors.remove(0) {
|
if !parser.errors.is_empty() {
|
||||||
Some(error) => {
|
cx.ecx.span_err(cx.fmtsp, format!("invalid format string: {}",
|
||||||
cx.ecx.span_err(cx.fmtsp,
|
parser.errors.remove(0))[]);
|
||||||
format!("invalid format string: {}", error)[]);
|
return DummyResult::raw_expr(sp);
|
||||||
return DummyResult::raw_expr(sp);
|
|
||||||
}
|
|
||||||
None => {}
|
|
||||||
}
|
}
|
||||||
if !cx.literal.is_empty() {
|
if !cx.literal.is_empty() {
|
||||||
let s = cx.trans_literal_string();
|
let s = cx.trans_literal_string();
|
||||||
|
|
|
@ -166,7 +166,7 @@ pub fn count_names(ms: &[TokenTree]) -> uint {
|
||||||
pub fn initial_matcher_pos(ms: Rc<Vec<TokenTree>>, sep: Option<Token>, lo: BytePos)
|
pub fn initial_matcher_pos(ms: Rc<Vec<TokenTree>>, sep: Option<Token>, lo: BytePos)
|
||||||
-> Box<MatcherPos> {
|
-> Box<MatcherPos> {
|
||||||
let match_idx_hi = count_names(ms[]);
|
let match_idx_hi = count_names(ms[]);
|
||||||
let matches = Vec::from_fn(match_idx_hi, |_i| Vec::new());
|
let matches: Vec<_> = range(0, match_idx_hi).map(|_| Vec::new()).collect();
|
||||||
box MatcherPos {
|
box MatcherPos {
|
||||||
stack: vec![],
|
stack: vec![],
|
||||||
top_elts: TtSeq(ms),
|
top_elts: TtSeq(ms),
|
||||||
|
@ -392,7 +392,8 @@ pub fn parse(sess: &ParseSess,
|
||||||
cur_eis.push(new_ei);
|
cur_eis.push(new_ei);
|
||||||
}
|
}
|
||||||
|
|
||||||
let matches = Vec::from_elem(ei.matches.len(), Vec::new());
|
let matches: Vec<_> = range(0, ei.matches.len())
|
||||||
|
.map(|_| Vec::new()).collect();
|
||||||
let ei_t = ei;
|
let ei_t = ei;
|
||||||
cur_eis.push(box MatcherPos {
|
cur_eis.push(box MatcherPos {
|
||||||
stack: vec![],
|
stack: vec![],
|
||||||
|
|
|
@ -65,6 +65,7 @@ pub use self::Token::*;
|
||||||
|
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::string;
|
use std::string;
|
||||||
|
use std::iter::repeat;
|
||||||
|
|
||||||
#[deriving(Clone, Copy, PartialEq)]
|
#[deriving(Clone, Copy, PartialEq)]
|
||||||
pub enum Breaks {
|
pub enum Breaks {
|
||||||
|
@ -166,9 +167,9 @@ pub fn mk_printer(out: Box<io::Writer+'static>, linewidth: uint) -> Printer {
|
||||||
// fall behind.
|
// fall behind.
|
||||||
let n: uint = 3 * linewidth;
|
let n: uint = 3 * linewidth;
|
||||||
debug!("mk_printer {}", linewidth);
|
debug!("mk_printer {}", linewidth);
|
||||||
let token: Vec<Token> = Vec::from_elem(n, Eof);
|
let token: Vec<Token> = repeat(Eof).take(n).collect();
|
||||||
let size: Vec<int> = Vec::from_elem(n, 0i);
|
let size: Vec<int> = repeat(0i).take(n).collect();
|
||||||
let scan_stack: Vec<uint> = Vec::from_elem(n, 0u);
|
let scan_stack: Vec<uint> = repeat(0u).take(n).collect();
|
||||||
Printer {
|
Printer {
|
||||||
out: out,
|
out: out,
|
||||||
buf_len: n,
|
buf_len: n,
|
||||||
|
|
|
@ -163,7 +163,7 @@ impl<'a> fold::Folder for PreludeInjector<'a> {
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
|
|
||||||
let (crates, uses) = view_items.partitioned(|x| {
|
let (crates, uses): (Vec<_>, _) = view_items.iter().cloned().partition(|x| {
|
||||||
match x.node {
|
match x.node {
|
||||||
ast::ViewItemExternCrate(..) => true,
|
ast::ViewItemExternCrate(..) => true,
|
||||||
_ => false,
|
_ => false,
|
||||||
|
|
|
@ -16,6 +16,7 @@ use self::FormatState::*;
|
||||||
use self::FormatOp::*;
|
use self::FormatOp::*;
|
||||||
use std::ascii::OwnedAsciiExt;
|
use std::ascii::OwnedAsciiExt;
|
||||||
use std::mem::replace;
|
use std::mem::replace;
|
||||||
|
use std::iter::repeat;
|
||||||
|
|
||||||
#[deriving(Copy, PartialEq)]
|
#[deriving(Copy, PartialEq)]
|
||||||
enum States {
|
enum States {
|
||||||
|
@ -508,7 +509,7 @@ fn format(val: Param, op: FormatOp, flags: Flags) -> Result<Vec<u8> ,String> {
|
||||||
if flags.precision > s.len() {
|
if flags.precision > s.len() {
|
||||||
let mut s_ = Vec::with_capacity(flags.precision);
|
let mut s_ = Vec::with_capacity(flags.precision);
|
||||||
let n = flags.precision - s.len();
|
let n = flags.precision - s.len();
|
||||||
s_.grow(n, b'0');
|
s_.extend(repeat(b'0').take(n));
|
||||||
s_.extend(s.into_iter());
|
s_.extend(s.into_iter());
|
||||||
s = s_;
|
s = s_;
|
||||||
}
|
}
|
||||||
|
@ -560,10 +561,10 @@ fn format(val: Param, op: FormatOp, flags: Flags) -> Result<Vec<u8> ,String> {
|
||||||
if flags.width > s.len() {
|
if flags.width > s.len() {
|
||||||
let n = flags.width - s.len();
|
let n = flags.width - s.len();
|
||||||
if flags.left {
|
if flags.left {
|
||||||
s.grow(n, b' ');
|
s.extend(repeat(b' ').take(n));
|
||||||
} else {
|
} else {
|
||||||
let mut s_ = Vec::with_capacity(flags.width);
|
let mut s_ = Vec::with_capacity(flags.width);
|
||||||
s_.grow(n, b' ');
|
s_.extend(repeat(b' ').take(n));
|
||||||
s_.extend(s.into_iter());
|
s_.extend(s.into_iter());
|
||||||
s = s_;
|
s = s_;
|
||||||
}
|
}
|
||||||
|
|
|
@ -990,8 +990,8 @@ fn run_tests<F>(opts: &TestOpts,
|
||||||
|
|
||||||
try!(callback(TeFiltered(filtered_descs)));
|
try!(callback(TeFiltered(filtered_descs)));
|
||||||
|
|
||||||
let (filtered_tests, filtered_benchs_and_metrics) =
|
let (filtered_tests, filtered_benchs_and_metrics): (Vec<_>, _) =
|
||||||
filtered_tests.partition(|e| {
|
filtered_tests.into_iter().partition(|e| {
|
||||||
match e.testfn {
|
match e.testfn {
|
||||||
StaticTestFn(_) | DynTestFn(_) => true,
|
StaticTestFn(_) | DynTestFn(_) => true,
|
||||||
_ => false
|
_ => false
|
||||||
|
|
|
@ -13,21 +13,21 @@
|
||||||
use core::cmp::Ordering::{Equal, Less, Greater};
|
use core::cmp::Ordering::{Equal, Less, Greater};
|
||||||
use core::option::Option;
|
use core::option::Option;
|
||||||
use core::option::Option::{Some, None};
|
use core::option::Option::{Some, None};
|
||||||
use core::slice;
|
|
||||||
use core::slice::SliceExt;
|
use core::slice::SliceExt;
|
||||||
|
use core::result::Result::{Ok, Err};
|
||||||
use tables::normalization::{canonical_table, compatibility_table, composition_table};
|
use tables::normalization::{canonical_table, compatibility_table, composition_table};
|
||||||
|
|
||||||
fn bsearch_table<T>(c: char, r: &'static [(char, &'static [T])]) -> Option<&'static [T]> {
|
fn bsearch_table<T>(c: char, r: &'static [(char, &'static [T])]) -> Option<&'static [T]> {
|
||||||
match r.binary_search(|&(val, _)| {
|
match r.binary_search_by(|&(val, _)| {
|
||||||
if c == val { Equal }
|
if c == val { Equal }
|
||||||
else if val < c { Less }
|
else if val < c { Less }
|
||||||
else { Greater }
|
else { Greater }
|
||||||
}) {
|
}) {
|
||||||
slice::BinarySearchResult::Found(idx) => {
|
Ok(idx) => {
|
||||||
let (_, result) = r[idx];
|
let (_, result) = r[idx];
|
||||||
Some(result)
|
Some(result)
|
||||||
}
|
}
|
||||||
slice::BinarySearchResult::NotFound(_) => None
|
Err(_) => None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,16 +81,16 @@ pub fn compose(a: char, b: char) -> Option<char> {
|
||||||
match bsearch_table(a, composition_table) {
|
match bsearch_table(a, composition_table) {
|
||||||
None => None,
|
None => None,
|
||||||
Some(candidates) => {
|
Some(candidates) => {
|
||||||
match candidates.binary_search(|&(val, _)| {
|
match candidates.binary_search_by(|&(val, _)| {
|
||||||
if b == val { Equal }
|
if b == val { Equal }
|
||||||
else if val < b { Less }
|
else if val < b { Less }
|
||||||
else { Greater }
|
else { Greater }
|
||||||
}) {
|
}) {
|
||||||
slice::BinarySearchResult::Found(idx) => {
|
Ok(idx) => {
|
||||||
let (_, result) = candidates[idx];
|
let (_, result) = candidates[idx];
|
||||||
Some(result)
|
Some(result)
|
||||||
}
|
}
|
||||||
slice::BinarySearchResult::NotFound(_) => None
|
Err(_) => None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,11 +19,11 @@ pub const UNICODE_VERSION: (uint, uint, uint) = (7, 0, 0);
|
||||||
fn bsearch_range_table(c: char, r: &'static [(char,char)]) -> bool {
|
fn bsearch_range_table(c: char, r: &'static [(char,char)]) -> bool {
|
||||||
use core::cmp::Ordering::{Equal, Less, Greater};
|
use core::cmp::Ordering::{Equal, Less, Greater};
|
||||||
use core::slice::SliceExt;
|
use core::slice::SliceExt;
|
||||||
r.binary_search(|&(lo,hi)| {
|
r.binary_search_by(|&(lo,hi)| {
|
||||||
if lo <= c && c <= hi { Equal }
|
if lo <= c && c <= hi { Equal }
|
||||||
else if hi < c { Less }
|
else if hi < c { Less }
|
||||||
else { Greater }
|
else { Greater }
|
||||||
}).found().is_some()
|
}).is_ok()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub mod general_category {
|
pub mod general_category {
|
||||||
|
@ -6826,17 +6826,17 @@ pub mod normalization {
|
||||||
fn bsearch_range_value_table(c: char, r: &'static [(char, char, u8)]) -> u8 {
|
fn bsearch_range_value_table(c: char, r: &'static [(char, char, u8)]) -> u8 {
|
||||||
use core::cmp::Ordering::{Equal, Less, Greater};
|
use core::cmp::Ordering::{Equal, Less, Greater};
|
||||||
use core::slice::SliceExt;
|
use core::slice::SliceExt;
|
||||||
use core::slice;
|
use core::result::Result::{Ok, Err};
|
||||||
match r.binary_search(|&(lo, hi, _)| {
|
match r.binary_search_by(|&(lo, hi, _)| {
|
||||||
if lo <= c && c <= hi { Equal }
|
if lo <= c && c <= hi { Equal }
|
||||||
else if hi < c { Less }
|
else if hi < c { Less }
|
||||||
else { Greater }
|
else { Greater }
|
||||||
}) {
|
}) {
|
||||||
slice::BinarySearchResult::Found(idx) => {
|
Ok(idx) => {
|
||||||
let (_, _, result) = r[idx];
|
let (_, _, result) = r[idx];
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
slice::BinarySearchResult::NotFound(_) => 0
|
Err(_) => 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6961,7 +6961,7 @@ pub mod conversions {
|
||||||
use core::slice::SliceExt;
|
use core::slice::SliceExt;
|
||||||
use core::option::Option;
|
use core::option::Option;
|
||||||
use core::option::Option::{Some, None};
|
use core::option::Option::{Some, None};
|
||||||
use core::slice;
|
use core::result::Result::{Ok, Err};
|
||||||
|
|
||||||
pub fn to_lower(c: char) -> char {
|
pub fn to_lower(c: char) -> char {
|
||||||
match bsearch_case_table(c, LuLl_table) {
|
match bsearch_case_table(c, LuLl_table) {
|
||||||
|
@ -6978,13 +6978,13 @@ pub mod conversions {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn bsearch_case_table(c: char, table: &'static [(char, char)]) -> Option<uint> {
|
fn bsearch_case_table(c: char, table: &'static [(char, char)]) -> Option<uint> {
|
||||||
match table.binary_search(|&(key, _)| {
|
match table.binary_search_by(|&(key, _)| {
|
||||||
if c == key { Equal }
|
if c == key { Equal }
|
||||||
else if key < c { Less }
|
else if key < c { Less }
|
||||||
else { Greater }
|
else { Greater }
|
||||||
}) {
|
}) {
|
||||||
slice::BinarySearchResult::Found(i) => Some(i),
|
Ok(i) => Some(i),
|
||||||
slice::BinarySearchResult::NotFound(_) => None,
|
Err(_) => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7596,20 +7596,20 @@ pub mod charwidth {
|
||||||
use core::option::Option;
|
use core::option::Option;
|
||||||
use core::option::Option::{Some, None};
|
use core::option::Option::{Some, None};
|
||||||
use core::slice::SliceExt;
|
use core::slice::SliceExt;
|
||||||
use core::slice;
|
use core::result::Result::{Ok, Err};
|
||||||
|
|
||||||
fn bsearch_range_value_table(c: char, is_cjk: bool, r: &'static [(char, char, u8, u8)]) -> u8 {
|
fn bsearch_range_value_table(c: char, is_cjk: bool, r: &'static [(char, char, u8, u8)]) -> u8 {
|
||||||
use core::cmp::Ordering::{Equal, Less, Greater};
|
use core::cmp::Ordering::{Equal, Less, Greater};
|
||||||
match r.binary_search(|&(lo, hi, _, _)| {
|
match r.binary_search_by(|&(lo, hi, _, _)| {
|
||||||
if lo <= c && c <= hi { Equal }
|
if lo <= c && c <= hi { Equal }
|
||||||
else if hi < c { Less }
|
else if hi < c { Less }
|
||||||
else { Greater }
|
else { Greater }
|
||||||
}) {
|
}) {
|
||||||
slice::BinarySearchResult::Found(idx) => {
|
Ok(idx) => {
|
||||||
let (_, _, r_ncjk, r_cjk) = r[idx];
|
let (_, _, r_ncjk, r_cjk) = r[idx];
|
||||||
if is_cjk { r_cjk } else { r_ncjk }
|
if is_cjk { r_cjk } else { r_ncjk }
|
||||||
}
|
}
|
||||||
slice::BinarySearchResult::NotFound(_) => 1
|
Err(_) => 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7804,7 +7804,7 @@ pub mod grapheme {
|
||||||
use core::kinds::Copy;
|
use core::kinds::Copy;
|
||||||
use core::slice::SliceExt;
|
use core::slice::SliceExt;
|
||||||
pub use self::GraphemeCat::*;
|
pub use self::GraphemeCat::*;
|
||||||
use core::slice;
|
use core::result::Result::{Ok, Err};
|
||||||
|
|
||||||
#[allow(non_camel_case_types)]
|
#[allow(non_camel_case_types)]
|
||||||
#[deriving(Clone)]
|
#[deriving(Clone)]
|
||||||
|
@ -7825,16 +7825,16 @@ pub mod grapheme {
|
||||||
|
|
||||||
fn bsearch_range_value_table(c: char, r: &'static [(char, char, GraphemeCat)]) -> GraphemeCat {
|
fn bsearch_range_value_table(c: char, r: &'static [(char, char, GraphemeCat)]) -> GraphemeCat {
|
||||||
use core::cmp::Ordering::{Equal, Less, Greater};
|
use core::cmp::Ordering::{Equal, Less, Greater};
|
||||||
match r.binary_search(|&(lo, hi, _)| {
|
match r.binary_search_by(|&(lo, hi, _)| {
|
||||||
if lo <= c && c <= hi { Equal }
|
if lo <= c && c <= hi { Equal }
|
||||||
else if hi < c { Less }
|
else if hi < c { Less }
|
||||||
else { Greater }
|
else { Greater }
|
||||||
}) {
|
}) {
|
||||||
slice::BinarySearchResult::Found(idx) => {
|
Ok(idx) => {
|
||||||
let (_, _, cat) = r[idx];
|
let (_, _, cat) = r[idx];
|
||||||
cat
|
cat
|
||||||
}
|
}
|
||||||
slice::BinarySearchResult::NotFound(_) => GC_Any
|
Err(_) => GC_Any
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -65,7 +65,7 @@ fn shift_push() {
|
||||||
let mut v2 = Vec::new();
|
let mut v2 = Vec::new();
|
||||||
|
|
||||||
while v1.len() > 0 {
|
while v1.len() > 0 {
|
||||||
v2.push(v1.remove(0).unwrap());
|
v2.push(v1.remove(0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -181,7 +181,7 @@ fn reverse_complement(seq: &mut [u8], tables: &Tables) {
|
||||||
unsafe {
|
unsafe {
|
||||||
copy_memory(seq.as_mut_ptr().offset((i - off + 1) as int),
|
copy_memory(seq.as_mut_ptr().offset((i - off + 1) as int),
|
||||||
seq.as_ptr().offset((i - off) as int), off);
|
seq.as_ptr().offset((i - off) as int), off);
|
||||||
*seq.unsafe_mut(i - off) = b'\n';
|
*seq.get_unchecked_mut(i - off) = b'\n';
|
||||||
}
|
}
|
||||||
i += LINE_LEN + 1;
|
i += LINE_LEN + 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,9 +9,9 @@
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
use std::slice::Chunks;
|
use std::slice::Chunks;
|
||||||
use std::slice::MutChunks;
|
use std::slice::ChunksMut;
|
||||||
|
|
||||||
fn dft_iter<'a, T>(arg1: Chunks<'a,T>, arg2: MutChunks<'a,T>)
|
fn dft_iter<'a, T>(arg1: Chunks<'a,T>, arg2: ChunksMut<'a,T>)
|
||||||
{
|
{
|
||||||
for
|
for
|
||||||
&something
|
&something
|
||||||
|
|
|
@ -15,4 +15,3 @@ struct Iter;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue