about summary refs log tree commit diff
path: root/src/libstd/vec.rs
AgeCommit message (Collapse)AuthorLines
2013-08-15std: Move the iterator param on FromIterator and Extendable to the method.Huon Wilson-4/+4
If they are on the trait then it is extremely annoying to use them as generic parameters to a function, e.g. with the iterator param on the trait itself, if one was to pass an Extendable<int> to a function that filled it either from a Range or a Map<VecIterator>, one needs to write something like: fn foo<E: Extendable<int, Range<int>> + Extendable<int, Map<&'self int, int, VecIterator<int>>> (e: &mut E, ...) { ... } since using a generic, i.e. `foo<E: Extendable<int, I>, I: Iterator<int>>` means that `foo` takes 2 type parameters, and the caller has to specify them (which doesn't work anyway, as they'll mismatch with the iterators used in `foo` itself). This patch changes it to: fn foo<E: Extendable<int>>(e: &mut E, ...) { ... }
2013-08-14Methodyfied the string ascii extionsion functionsMarvin Löbel-3/+31
Added into_owned() method for vectors Added DoubleEnded Iterator impl to Option Renamed nil.rs to unit.rs
2013-08-12Forbid pub/priv where it has no effectAlex Crichton-8/+8
Closes #5495
2013-08-12auto merge of #8400 : blake2-ppc/rust/seq-ord, r=cmrbors-24/+22
Use Eq + Ord for lexicographical ordering of sequences. For each of <, <=, >= or > as R, use:: [x, ..xs] R [y, ..ys] = if x != y { x R y } else { xs R ys } Previous code using `a < b` and then `!(b < a)` for short-circuiting fails on cases such as [1.0, 2.0] < [0.0/0.0, 3.0], where the first element was effectively considered equal. Containers like &[T] did also implement only one comparison operator `<`, and derived the comparison results from this. This isn't correct either for Ord. Implement functions in `std::iterator::order::{lt,le,gt,ge,equal,cmp}` that all iterable containers can use for lexical order. We also visit tuple ordering, having the same problem and same solution (but differing implementation).
2013-08-11vec: optimize the Add implementationDaniel Micay-5/+14
before: test add ... bench: 164 ns/iter (+/- 1) after: test add ... bench: 113 ns/iter (+/- 2)
2013-08-10std: Rename Iterator.transform -> .mapErick Tryzelaar-3/+3
cc #5898
2013-08-10Mass rename of .consume{,_iter}() to .move_iter()Erick Tryzelaar-20/+20
cc #7887
2013-08-08std::vec: Fix typo in fn neblake2-ppc-1/+1
2013-08-08std::vec: Use iterator::order functions for Eq, Ord, TotalOrd, TotalEqblake2-ppc-24/+22
2013-08-07std: Fix for-range loops that can use iteratorsblake2-ppc-2/+2
Fix inappropriate for-range loops to use for-iterator constructs (or other appropriate solution) instead.
2013-08-06vec: use `offset_inbounds` for iteratorsDaniel Micay-4/+4
This allows LLVM to optimize vector iterators to an `getelementptr` and `icmp` pair, instead of `getelementptr` and *two* comparisons. Code snippet: ~~~ fn foo(xs: &mut [f64]) { for x in xs.mut_iter() { *x += 10.0; } } ~~~ LLVM IR at stage0: ~~~ ; Function Attrs: noinline uwtable define void @"_ZN3foo17_68e1b25bca131dba7_0$x2e0E"({ i64, %tydesc*, i8*, i8*, i8 }* nocapture, { double*, i64 }* nocapture) #1 { "function top level": %2 = getelementptr inbounds { double*, i64 }* %1, i64 0, i32 0 %3 = load double** %2, align 8 %4 = getelementptr inbounds { double*, i64 }* %1, i64 0, i32 1 %5 = load i64* %4, align 8 %6 = ptrtoint double* %3 to i64 %7 = and i64 %5, -8 %8 = add i64 %7, %6 %9 = inttoptr i64 %8 to double* %10 = icmp eq double* %3, %9 %11 = icmp eq double* %3, null %or.cond6 = or i1 %10, %11 br i1 %or.cond6, label %match_case, label %match_else match_else: ; preds = %"function top level", %match_else %12 = phi double* [ %13, %match_else ], [ %3, %"function top level" ] %13 = getelementptr double* %12, i64 1 %14 = load double* %12, align 8 %15 = fadd double %14, 1.000000e+01 store double %15, double* %12, align 8 %16 = icmp eq double* %13, %9 %17 = icmp eq double* %13, null %or.cond = or i1 %16, %17 br i1 %or.cond, label %match_case, label %match_else match_case: ; preds = %match_else, %"function top level" ret void } ~~~ Optimized LLVM IR at stage1/stage2: ~~~ ; Function Attrs: noinline uwtable define void @"_ZN3foo17_68e1b25bca131dba7_0$x2e0E"({ i64, %tydesc*, i8*, i8*, i8 }* nocapture, { double*, i64 }* nocapture) #1 { "function top level": %2 = getelementptr inbounds { double*, i64 }* %1, i64 0, i32 0 %3 = load double** %2, align 8 %4 = getelementptr inbounds { double*, i64 }* %1, i64 0, i32 1 %5 = load i64* %4, align 8 %6 = lshr i64 %5, 3 %7 = getelementptr inbounds double* %3, i64 %6 %8 = icmp eq i64 %6, 0 %9 = icmp eq double* %3, null %or.cond6 = or i1 %8, %9 br i1 %or.cond6, label %match_case, label %match_else match_else: ; preds = %"function top level", %match_else %.sroa.0.0.in7 = phi double* [ %10, %match_else ], [ %3, %"function top level" ] %10 = getelementptr inbounds double* %.sroa.0.0.in7, i64 1 %11 = load double* %.sroa.0.0.in7, align 8 %12 = fadd double %11, 1.000000e+01 store double %12, double* %.sroa.0.0.in7, align 8 %13 = icmp eq double* %10, %7 br i1 %13, label %match_case, label %match_else match_case: ; preds = %match_else, %"function top level" ret void } ~~~
2013-08-06vec: avoid `ptrtoint`/`inttoptr` in the iteratorsDaniel Micay-8/+18
This results in throwing away alias analysis information, because LLVM does *not* implement reasoning about these conversions yet. We specialize zero-size types since a `getelementptr` offset will return us the same pointer, making it broken as a simple counter.
2013-08-06std: Fix bug in ChunkIter::idxblake2-ppc-1/+4
ChunkIter .idx() didn't handle overflow correctly, even though it tried.
2013-08-06std: Improve vec::ChunkIterblake2-ppc-8/+51
Implement clone, bidirectionality and random access for this iterator
2013-08-05Updated std::Option, std::Either and std::ResultMarvin Löbel-4/+2
- Made naming schemes consistent between Option, Result and Either - Changed Options Add implementation to work like the maybe monad (return None if any of the inputs is None) - Removed duplicate Option::get and renamed all related functions to use the term `unwrap` instead
2013-08-03remove obsolete `foreach` keywordDaniel Micay-35/+35
this has been replaced by `for`
2013-08-03std: add benchmark for vec.mut_iter.Huon Wilson-0/+13
2013-08-03std: use ptr.offset where possible in the vec iterator.Huon Wilson-8/+38
Closes #8212.
2013-08-02replace `range` with an external iteratorDaniel Micay-4/+4
2013-08-01std: Replace `for` with `do { .. }` expr where internal iterators are usedblake2-ppc-14/+19
2013-08-01migrate many `for` loops to `foreach`Daniel Micay-29/+30
2013-07-30auto merge of #8121 : thestinger/rust/offset, r=alexcrichtonbors-16/+16
Closes #8118, #7136 ~~~rust extern mod extra; use std::vec; use std::ptr; fn bench_from_elem(b: &mut extra::test::BenchHarness) { do b.iter { let v: ~[u8] = vec::from_elem(1024, 0u8); } } fn bench_set_memory(b: &mut extra::test::BenchHarness) { do b.iter { let mut v: ~[u8] = vec::with_capacity(1024); unsafe { let vp = vec::raw::to_mut_ptr(v); ptr::set_memory(vp, 0, 1024); vec::raw::set_len(&mut v, 1024); } } } fn bench_vec_repeat(b: &mut extra::test::BenchHarness) { do b.iter { let v: ~[u8] = ~[0u8, ..1024]; } } ~~~ Before: test bench_from_elem ... bench: 415 ns/iter (+/- 17) test bench_set_memory ... bench: 85 ns/iter (+/- 4) test bench_vec_repeat ... bench: 83 ns/iter (+/- 3) After: test bench_from_elem ... bench: 84 ns/iter (+/- 2) test bench_set_memory ... bench: 84 ns/iter (+/- 5) test bench_vec_repeat ... bench: 84 ns/iter (+/- 3)
2013-07-30implement pointer arithmetic with GEPDaniel Micay-16/+16
Closes #8118, #7136 ~~~rust extern mod extra; use std::vec; use std::ptr; fn bench_from_elem(b: &mut extra::test::BenchHarness) { do b.iter { let v: ~[u8] = vec::from_elem(1024, 0u8); } } fn bench_set_memory(b: &mut extra::test::BenchHarness) { do b.iter { let mut v: ~[u8] = vec::with_capacity(1024); unsafe { let vp = vec::raw::to_mut_ptr(v); ptr::set_memory(vp, 0, 1024); vec::raw::set_len(&mut v, 1024); } } } fn bench_vec_repeat(b: &mut extra::test::BenchHarness) { do b.iter { let v: ~[u8] = ~[0u8, ..1024]; } } ~~~ Before: test bench_from_elem ... bench: 415 ns/iter (+/- 17) test bench_set_memory ... bench: 85 ns/iter (+/- 4) test bench_vec_repeat ... bench: 83 ns/iter (+/- 3) After: test bench_from_elem ... bench: 84 ns/iter (+/- 2) test bench_set_memory ... bench: 84 ns/iter (+/- 5) test bench_vec_repeat ... bench: 84 ns/iter (+/- 3)
2013-07-29auto merge of #7223 : steveklabnik/rust/vec_initial_docs, r=pcwaltonbors-1/+47
Let's explain more of what this module is about, not just 'vectors.'
2013-07-30std: Remove macro in vec that's only used onceblake2-ppc-17/+12
2013-07-30std: Remove RandomAccessIterator impl for VecMutIteratorblake2-ppc-4/+4
The RandomAccessIterator implementation is not sound for the mutable vec iterator, and makes it easy to duplicate &mut element pointers.
2013-07-29Adding an initial description to vec.rs.Steve Klabnik-1/+47
Let's explain more of what this module is about, not just 'vectors.'
2013-07-29std: Rename Iterator adaptor types to drop the -Iterator suffixblake2-ppc-2/+2
Drop the "Iterator" suffix for the the structs in std::iterator. Filter, Zip, Chain etc. are shorter type names for when iterator pipelines need their types written out in full in return value types, so it's easier to read and write. the iterator module already forms enough namespace.
2013-07-28Refactored vec and str iterators to remove prefixesjmgrosen-40/+40
2013-07-27Change concurrency primitives to standard naming conventionsSteven Stewart-Gallus-3/+3
To be more specific: `UPPERCASETYPE` was changed to `UppercaseType` `type_new` was changed to `Type::new` `type_function(value)` was changed to `value.method()`
2013-07-27iterator: add an Extendable traitDaniel Micay-1/+12
2013-07-27vec: replace some `as_mut_buf` with `to_mut_ptr`Daniel Micay-12/+10
2013-07-27Remove dummy type parameters from iterator adaptorsblake2-ppc-2/+2
With the recent fixes to method resolution, we can now remove the dummy type parameters used as crutches in the iterator module. For example, the zip adaptor type is just ZipIterator<T, U> now.
2013-07-27vec: add mut_slice_{to,from}Daniel Micay-0/+23
Closes #8066
2013-07-26Consolidate raw representations of rust valuesAlex Crichton-87/+58
This moves the raw struct layout of closures, vectors, boxes, and strings into a new `unstable::raw` module. This is meant to be a centralized location to find information for the layout of these values. As safe method, `repr`, is provided to convert a rust value to its raw representation. Unsafe methods to convert back are not provided because they are rarely used and too numerous to write an implementation for each (not much of a common pattern).
2013-07-24auto merge of #7996 : erickt/rust/cleanup-strs, r=ericktbors-7/+5
This is a cleanup pull request that does: * removes `os::as_c_charp` * moves `str::as_buf` and `str::as_c_str` into `StrSlice` * converts some functions from `StrSlice::as_buf` to `StrSlice::as_c_str` * renames `StrSlice::as_buf` to `StrSlice::as_imm_buf` (and adds `StrSlice::as_mut_buf` to match `vec.rs`. * renames `UniqueStr::as_bytes_with_null_consume` to `UniqueStr::to_bytes` * and other misc cleanups and minor optimizations
2013-07-24Change 'print(fmt!(...))' to printf!/printfln! in src/lib*Birunthan Mohanathas-2/+2
2013-07-24add a RandomAccessIterator traitDaniel Micay-2/+64
2013-07-23std: inline str::with_capacity and vec::with_capacityErick Tryzelaar-0/+1
2013-07-23std: simplify str::as_imm_buf and vec::as_{imm,mut}_bufErick Tryzelaar-7/+4
2013-07-22auto merge of #7943 : Dretch/rust/vec-slice-from-to, r=huonwbors-3/+47
2013-07-22new snapshotDaniel Micay-117/+0
2013-07-21Add slice_from and slice_to methods for vec, like theGareth Smith-3/+47
methods of the same names that already exist for strs.
2013-07-20std: Implement Clone for VecIterator and iterators using itblake2-ppc-0/+17
The theory is simple, the immutable iterators simply hold state variables (indicies or pointers) into frozen containers. We can freely clone these iterators, just like we can clone borrowed pointers. VecIterator needs a manual impl to handle the lifetime struct member.
2013-07-20Use Option .take() or .take_unwrap() instead of util::replace where possibleblake2-ppc-4/+2
2013-07-18Fix warnings in libstd and librusti testsblake2-ppc-1/+1
2013-07-17test: Fix tests.Patrick Walton-1/+1
2013-07-17test: Fix tests.Patrick Walton-2/+0
2013-07-17librustc: Remove all uses of "copy".Patrick Walton-39/+39
2013-07-15remove headers from unique vectorsDaniel Micay-8/+98