Daniel Micay
6655b3c462
repr: remove trailing {} from unit-like structs
2013-08-31 03:54:15 -04:00
Daniel Micay
874611b348
repr: print the name of structs
2013-08-31 03:54:13 -04:00
Alex Crichton
e3662b1880
Remove offset_inbounds for an unsafe offset function
2013-08-27 23:22:52 -07:00
Patrick Walton
5c3504799d
librustc: Remove &const
and *const
from the language.
...
They are still present as part of the borrow check.
2013-08-27 18:46:51 -07:00
Daniel Micay
20567a0c3c
vec: implement DeepClone
2013-08-27 13:47:15 -04:00
Brian Anderson
063d9ca928
std: Make vec::from_elem failure-safe
2013-08-26 18:17:56 -07:00
Brian Anderson
8dc13ac345
std: Make vec::from_fn failure-safe
2013-08-26 13:29:33 -07:00
bors
da08b0244a
auto merge of #8701 : brson/rust/issue-8698, r=thestinger
2013-08-24 20:31:15 -07:00
Brian Anderson
2690b51350
std: Make vec::push_all_move call reserve_at_least
...
vec::unshift uses this to add elements, scheduler queues use unshift,
and this was causing a lot of reallocation
2013-08-24 15:46:04 -07:00
Brian Anderson
4c5f62539b
Fix some vector function failure tests. Closes #8698
2013-08-23 14:49:17 -07:00
Vadim Chugunov
651f38258d
Disabled broken tests in std::vec.
2013-08-22 20:02:20 -07:00
Vadim Chugunov
12ecdb6381
Enabled unit tests in std and extra.
2013-08-22 20:02:20 -07:00
bors
bf90634087
auto merge of #8604 : kballard/rust/iter-size-hint, r=graydon
...
Implement `size_hint()` on the new std::vec Iterators.
Add or update `size_hint()` on std::iterator Iterators where appropriate.
r? @thestinger
2013-08-21 08:01:44 -07:00
Daniel Micay
25bac776d9
vec: add shrink_to_fit
...
Closes #4960
2013-08-20 22:05:03 -04:00
Kevin Ballard
c64f96361e
Implement .size_hint() on new vec iterators
2013-08-18 21:58:56 -07:00
Huon Wilson
abe94f9b4d
doc: correct spelling in documentation.
2013-08-16 15:41:28 +10:00
Daniel Micay
486501963a
vec: rm redundant is_empty implementations
2013-08-15 21:12:35 -04:00
Daniel Micay
45426c3b4c
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.
2013-08-15 21:12:34 -04:00
bors
790e6bb397
auto merge of #8490 : huonw/rust/fromiterator-extendable, r=catamorphism
...
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-15 02:56:08 -07:00
Huon Wilson
53487a0246
std: Move the iterator param on FromIterator and Extendable to the method.
...
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-15 01:10:45 +10:00
Marvin Löbel
a00becd0eb
Methodyfied the string ascii extionsion functions
...
Added into_owned() method for vectors
Added DoubleEnded Iterator impl to Option
Renamed nil.rs to unit.rs
2013-08-14 14:48:25 +02:00
Alex Crichton
930885d5e5
Forbid pub/priv where it has no effect
...
Closes #5495
2013-08-12 23:20:46 -07:00
bors
35040275b3
auto merge of #8400 : blake2-ppc/rust/seq-ord, r=cmr
...
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-12 11:53:18 -07:00
Daniel Micay
2afed31ecc
vec: optimize the Add implementation
...
before:
test add ... bench: 164 ns/iter (+/- 1)
after:
test add ... bench: 113 ns/iter (+/- 2)
2013-08-11 03:14:35 -04:00
Erick Tryzelaar
68f40d215e
std: Rename Iterator.transform -> .map
...
cc #5898
2013-08-10 07:33:21 -07:00
Erick Tryzelaar
fad7857c7b
Mass rename of .consume{,_iter}() to .move_iter()
...
cc #7887
2013-08-10 07:01:07 -07:00
blake2-ppc
06783ce831
std::vec: Fix typo in fn ne
2013-08-08 23:07:24 +02:00
blake2-ppc
9cac4ccc90
std::vec: Use iterator::order functions for Eq, Ord, TotalOrd, TotalEq
2013-08-08 22:07:21 +02:00
blake2-ppc
40bdbf0f5d
std: Fix for-range loops that can use iterators
...
Fix inappropriate for-range loops to use for-iterator constructs (or
other appropriate solution) instead.
2013-08-07 22:39:57 -04:00
Daniel Micay
55f3d04101
vec: use offset_inbounds
for iterators
...
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-06 23:54:24 -04:00
Daniel Micay
f23fb19ee5
vec: avoid ptrtoint
/inttoptr
in the iterators
...
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-06 23:41:20 -04:00
blake2-ppc
45085b9f8d
std: Fix bug in ChunkIter::idx
...
ChunkIter .idx() didn't handle overflow correctly, even though it tried.
2013-08-06 04:05:08 +02:00
blake2-ppc
a05a9a1c02
std: Improve vec::ChunkIter
...
Implement clone, bidirectionality and random access for this iterator
2013-08-06 04:05:07 +02:00
Marvin Löbel
0ac7a219f0
Updated std::Option, std::Either and std::Result
...
- 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-05 22:42:21 +02:00
Daniel Micay
1008945528
remove obsolete foreach
keyword
...
this has been replaced by `for`
2013-08-03 22:48:02 -04:00
Huon Wilson
1992765dd3
std: add benchmark for vec.mut_iter.
2013-08-03 03:13:13 -04:00
Huon Wilson
fbb7cd32c3
std: use ptr.offset where possible in the vec iterator.
...
Closes #8212 .
2013-08-03 03:13:11 -04:00
Daniel Micay
234acad404
replace range
with an external iterator
2013-08-02 00:51:14 -04:00
blake2-ppc
b18bd785ec
std: Replace for
with do { .. }
expr where internal iterators are used
2013-08-01 16:54:22 +02:00
Daniel Micay
1fc4db2d08
migrate many for
loops to foreach
2013-08-01 05:34:55 -04:00
bors
576f395ddf
auto merge of #8121 : thestinger/rust/offset, r=alexcrichton
...
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-30 07:01:19 -07:00
Daniel Micay
ef870d37a5
implement pointer arithmetic with GEP
...
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-30 02:50:31 -04:00
bors
8695bc74a0
auto merge of #7223 : steveklabnik/rust/vec_initial_docs, r=pcwalton
...
Let's explain more of what this module is about, not just 'vectors.'
2013-07-29 23:49:23 -07:00
blake2-ppc
99490ad5ba
std: Remove macro in vec that's only used once
2013-07-30 02:52:01 +02:00
blake2-ppc
2ff84124f0
std: Remove RandomAccessIterator impl for VecMutIterator
...
The RandomAccessIterator implementation is not sound for the mutable vec
iterator, and makes it easy to duplicate &mut element pointers.
2013-07-30 01:48:17 +02:00
Steve Klabnik
538fbc38c9
Adding an initial description to vec.rs.
...
Let's explain more of what this module is about, not just 'vectors.'
2013-07-29 16:18:41 -04:00
blake2-ppc
4b45f47881
std: Rename Iterator adaptor types to drop the -Iterator suffix
...
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-29 04:20:56 +02:00
jmgrosen
a0f0f3012e
Refactored vec and str iterators to remove prefixes
2013-07-28 13:37:35 -07:00
Steven Stewart-Gallus
d0b7515aed
Change concurrency primitives to standard naming conventions
...
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-27 22:06:29 -07:00
Daniel Micay
fe955e7b06
iterator: add an Extendable trait
2013-07-27 17:42:10 -04:00