From 062747b9c969d18544e4a376077499613394e757 Mon Sep 17 00:00:00 2001 From: Daniel Micay Date: Tue, 13 Aug 2013 20:37:05 -0400 Subject: ptr: inline the Clone implementation --- src/libstd/ptr.rs | 1 + 1 file changed, 1 insertion(+) (limited to 'src/libstd') diff --git a/src/libstd/ptr.rs b/src/libstd/ptr.rs index b13d46d540d..50c25a2f722 100644 --- a/src/libstd/ptr.rs +++ b/src/libstd/ptr.rs @@ -47,6 +47,7 @@ pub unsafe fn buf_len(buf: **T) -> uint { } impl Clone for *T { + #[inline] fn clone(&self) -> *T { *self } -- cgit 1.4.1-3-g733a5 From af9ddd7563d2eb66147a9de126453034938af46a Mon Sep 17 00:00:00 2001 From: Daniel Micay Date: Tue, 13 Aug 2013 20:46:50 -0400 Subject: kinds: update documentation --- src/libstd/kinds.rs | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/kinds.rs b/src/libstd/kinds.rs index 6b45ddddf7e..6a48e18a3cc 100644 --- a/src/libstd/kinds.rs +++ b/src/libstd/kinds.rs @@ -18,27 +18,21 @@ intrinsic properties of the type. These classifications, often called They cannot be implemented by user code, but are instead implemented by the compiler automatically for the types to which they apply. -The 2 kinds are - -* Send - owned types and types containing owned types. These types - may be transferred across task boundaries. - -* Freeze - types that are deeply immutable. - */ -#[allow(missing_doc)]; - +/// Types able to be transferred across task boundaries. #[lang="send"] pub trait Send { // empty. } +/// Types that are either immutable or have inherited mutability. #[lang="freeze"] pub trait Freeze { // empty. } +/// Types with a constant size known at compile-time. #[lang="sized"] pub trait Sized { // Empty. -- cgit 1.4.1-3-g733a5 From 1f89eb867a33b25c3df0078eb2ec18d1fc00bc43 Mon Sep 17 00:00:00 2001 From: Daniel Micay Date: Tue, 13 Aug 2013 21:00:58 -0400 Subject: tuple: remove obsolete ExtendedTupleOps replaced by iterators (generic composable `map` and `zip` adaptors) --- src/libstd/prelude.rs | 2 +- src/libstd/tuple.rs | 52 --------------------------------------------------- 2 files changed, 1 insertion(+), 53 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/prelude.rs b/src/libstd/prelude.rs index deee49bc472..63f73002009 100644 --- a/src/libstd/prelude.rs +++ b/src/libstd/prelude.rs @@ -69,7 +69,7 @@ pub use str::{Str, StrVector, StrSlice, OwnedStr}; pub use from_str::FromStr; pub use to_bytes::IterBytes; pub use to_str::{ToStr, ToStrConsume}; -pub use tuple::{CopyableTuple, ImmutableTuple, ExtendedTupleOps}; +pub use tuple::{CopyableTuple, ImmutableTuple}; pub use tuple::{CloneableTuple1, ImmutableTuple1}; pub use tuple::{CloneableTuple2, CloneableTuple3, CloneableTuple4, CloneableTuple5}; pub use tuple::{CloneableTuple6, CloneableTuple7, CloneableTuple8, CloneableTuple9}; diff --git a/src/libstd/tuple.rs b/src/libstd/tuple.rs index 8a3c024ede5..12073a1f4f0 100644 --- a/src/libstd/tuple.rs +++ b/src/libstd/tuple.rs @@ -13,9 +13,6 @@ #[allow(missing_doc)]; use clone::Clone; -use vec; -use vec::ImmutableVector; -use iterator::Iterator; pub use self::inner::*; @@ -79,55 +76,6 @@ impl ImmutableTuple for (T, U) { } } -pub trait ExtendedTupleOps { - fn zip(&self) -> ~[(A, B)]; - fn map(&self, f: &fn(a: &A, b: &B) -> C) -> ~[C]; -} - -impl<'self, - A:Clone, - B:Clone> - ExtendedTupleOps for - (&'self [A], &'self [B]) { - #[inline] - fn zip(&self) -> ~[(A, B)] { - match *self { - (ref a, ref b) => { - vec::zip_slice(*a, *b) - } - } - } - - #[inline] - fn map(&self, f: &fn(a: &A, b: &B) -> C) -> ~[C] { - match *self { - (ref a, ref b) => { - a.iter().zip(b.iter()).map(|(aa, bb)| f(aa, bb)).collect() - } - } - } -} - -impl ExtendedTupleOps for (~[A], ~[B]) { - #[inline] - fn zip(&self) -> ~[(A, B)] { - match *self { - (ref a, ref b) => { - vec::zip_slice(*a, *b) - } - } - } - - #[inline] - fn map(&self, f: &fn(a: &A, b: &B) -> C) -> ~[C] { - match *self { - (ref a, ref b) => { - a.iter().zip(b.iter()).map(|(aa, bb)| f(aa, bb)).collect() - } - } - } -} - // macro for implementing n-ary tuple functions and operations macro_rules! tuple_impls { -- cgit 1.4.1-3-g733a5 From 45426c3b4c20b69b51e7f1866f3e893be273f34c Mon Sep 17 00:00:00 2001 From: Daniel Micay Date: Tue, 13 Aug 2013 21:29:16 -0400 Subject: vec: rm obsolete zip and zip_slice These are obsoleted by the generic iterator `zip` adaptor. Unlike these, it does not clone the elements or allocate a new vector by default. --- src/libextra/sort.rs | 7 +----- src/libextra/test.rs | 11 ++------- src/libstd/vec.rs | 42 +--------------------------------- src/test/run-pass/zip-same-length.rs | 44 ------------------------------------ 4 files changed, 4 insertions(+), 100 deletions(-) delete mode 100644 src/test/run-pass/zip-same-length.rs (limited to 'src/libstd') diff --git a/src/libextra/sort.rs b/src/libextra/sort.rs index c7920e72708..bea7868fd32 100644 --- a/src/libextra/sort.rs +++ b/src/libextra/sort.rs @@ -782,11 +782,8 @@ mod test_qsort3 { #[cfg(test)] mod test_qsort { - use sort::*; - use std::vec; - fn check_sort(v1: &mut [int], v2: &mut [int]) { let len = v1.len(); fn leual(a: &int, b: &int) -> bool { *a <= *b } @@ -835,9 +832,7 @@ mod test_qsort { let immut_names = names; - let pairs = vec::zip_slice(expected, immut_names); - for p in pairs.iter() { - let (a, b) = *p; + for (&a, &b) in expected.iter().zip(immut_names.iter()) { debug!("%d %d", a, b); assert_eq!(a, b); } diff --git a/src/libextra/test.rs b/src/libextra/test.rs index a9c3bf98cb6..9778248f005 100644 --- a/src/libextra/test.rs +++ b/src/libextra/test.rs @@ -1121,7 +1121,6 @@ mod tests { use std::either; use std::comm::{stream, SharedChan}; - use std::vec; use tempfile; use std::os; @@ -1309,14 +1308,8 @@ mod tests { ~"test::parse_ignored_flag", ~"test::sort_tests"]; - let pairs = vec::zip(expected, filtered); - - for p in pairs.iter() { - match *p { - (ref a, ref b) => { - assert!(*a == b.desc.name.to_str()); - } - } + for (a, b) in expected.iter().zip(filtered.iter()) { + assert!(*a == b.desc.name.to_str()); } } diff --git a/src/libstd/vec.rs b/src/libstd/vec.rs index a605ea4373f..996b00096a2 100644 --- a/src/libstd/vec.rs +++ b/src/libstd/vec.rs @@ -390,39 +390,6 @@ pub fn unzip(v: ~[(T, U)]) -> (~[T], ~[U]) { (ts, us) } -/** - * Convert two vectors to a vector of pairs, by reference. As zip(). - */ -pub fn zip_slice(v: &[T], u: &[U]) -> ~[(T, U)] { - let mut zipped = ~[]; - let sz = v.len(); - let mut i = 0u; - assert_eq!(sz, u.len()); - while i < sz { - zipped.push((v[i].clone(), u[i].clone())); - i += 1u; - } - zipped -} - -/** - * Convert two vectors to a vector of pairs. - * - * Returns a vector of tuples, where the i-th tuple contains the - * i-th elements from each of the input vectors. - */ -pub fn zip(mut v: ~[T], mut u: ~[U]) -> ~[(T, U)] { - let mut i = v.len(); - assert_eq!(i, u.len()); - let mut w = with_capacity(i); - while i > 0 { - w.push((v.pop(),u.pop())); - i -= 1; - } - w.reverse(); - w -} - /** * Iterate over all permutations of vector `v`. * @@ -2865,14 +2832,7 @@ mod tests { #[test] fn test_zip_unzip() { - let v1 = ~[1, 2, 3]; - let v2 = ~[4, 5, 6]; - - let z1 = zip(v1, v2); - - assert_eq!((1, 4), z1[0]); - assert_eq!((2, 5), z1[1]); - assert_eq!((3, 6), z1[2]); + let z1 = ~[(1, 4), (2, 5), (3, 6)]; let (left, right) = unzip(z1); diff --git a/src/test/run-pass/zip-same-length.rs b/src/test/run-pass/zip-same-length.rs deleted file mode 100644 index d97148746d0..00000000000 --- a/src/test/run-pass/zip-same-length.rs +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// In this case, the code should compile and should -// succeed at runtime - -use std::vec; - -fn enum_chars(start: u8, end: u8) -> ~[char] { - assert!(start < end); - let mut i = start; - let mut r = ~[]; - while i <= end { r.push(i as char); i += 1u as u8; } - return r; -} - -fn enum_uints(start: uint, end: uint) -> ~[uint] { - assert!(start < end); - let mut i = start; - let mut r = ~[]; - while i <= end { r.push(i); i += 1u; } - return r; -} - -pub fn main() { - let a = 'a' as u8; - let j = 'j' as u8; - let k = 1u; - let l = 10u; - let chars = enum_chars(a, j); - let ints = enum_uints(k, l); - - let ps = vec::zip(chars, ints); - - assert_eq!(ps.head(), &('a', 1u)); - assert_eq!(ps.last(), &(j as char, 10u)); -} -- cgit 1.4.1-3-g733a5 From fe047e07ba52279dfba23992d3d1e1aafba78d10 Mon Sep 17 00:00:00 2001 From: Daniel Micay Date: Tue, 13 Aug 2013 21:41:50 -0400 Subject: iterator: cleanup --- src/libstd/iterator.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/iterator.rs b/src/libstd/iterator.rs index 1a5e364542b..34bbe9292a5 100644 --- a/src/libstd/iterator.rs +++ b/src/libstd/iterator.rs @@ -174,6 +174,7 @@ pub trait Iterator { /// assert!(it.peek().is_none()); /// assert!(it.next().is_none()); /// ~~~ + #[inline] fn peekable(self) -> Peekable { Peekable{iter: self, peeked: None} } @@ -931,8 +932,7 @@ impl<'self, A, B, T: Iterator> Iterator for Map<'self, A, B, T> { } } -impl<'self, A, B, T: DoubleEndedIterator> DoubleEndedIterator -for Map<'self, A, B, T> { +impl<'self, A, B, T: DoubleEndedIterator> DoubleEndedIterator for Map<'self, A, B, T> { #[inline] fn next_back(&mut self) -> Option { let next = self.iter.next_back(); @@ -940,8 +940,7 @@ for Map<'self, A, B, T> { } } -impl<'self, A, B, T: RandomAccessIterator> RandomAccessIterator -for Map<'self, A, B, T> { +impl<'self, A, B, T: RandomAccessIterator> RandomAccessIterator for Map<'self, A, B, T> { #[inline] fn indexable(&self) -> uint { self.iter.indexable() -- cgit 1.4.1-3-g733a5 From 486501963a85a4f593bb0a0b98a412b58b9a200b Mon Sep 17 00:00:00 2001 From: Daniel Micay Date: Tue, 13 Aug 2013 22:06:10 -0400 Subject: vec: rm redundant is_empty implementations --- src/libstd/vec.rs | 12 ------------ 1 file changed, 12 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/vec.rs b/src/libstd/vec.rs index 996b00096a2..7748c040a1d 100644 --- a/src/libstd/vec.rs +++ b/src/libstd/vec.rs @@ -691,12 +691,6 @@ impl Vector for @[T] { } impl<'self, T> Container for &'self [T] { - /// Returns true if a vector contains no elements - #[inline] - fn is_empty(&self) -> bool { - self.as_imm_buf(|_p, len| len == 0u) - } - /// Returns the length of a vector #[inline] fn len(&self) -> uint { @@ -705,12 +699,6 @@ impl<'self, T> Container for &'self [T] { } impl Container for ~[T] { - /// Returns true if a vector contains no elements - #[inline] - fn is_empty(&self) -> bool { - self.as_imm_buf(|_p, len| len == 0u) - } - /// Returns the length of a vector #[inline] fn len(&self) -> uint { -- cgit 1.4.1-3-g733a5