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
Daniel Micay
ffe549daf5
vec: replace some as_mut_buf
with to_mut_ptr
2013-07-27 17:30:29 -04:00
blake2-ppc
7ae17e0964
Remove dummy type parameters from iterator adaptors
...
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-27 14:37:55 -04:00
Daniel Micay
d7c9bb4b68
vec: add mut_slice_{to,from}
...
Closes #8066
2013-07-27 14:36:52 -04:00
Alex Crichton
5aaaca0c6a
Consolidate raw representations of rust values
...
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-26 09:53:03 -07:00
bors
330378d1a1
auto merge of #7996 : erickt/rust/cleanup-strs, r=erickt
...
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-24 13:25:36 -07:00
Birunthan Mohanathas
d047cf1ec6
Change 'print(fmt!(...))' to printf!/printfln! in src/lib*
2013-07-24 09:45:20 -04:00
Daniel Micay
626bb5a866
add a RandomAccessIterator trait
2013-07-24 09:45:20 -04:00
Erick Tryzelaar
bbedbc0450
std: inline str::with_capacity and vec::with_capacity
2013-07-23 16:57:00 -07:00
Erick Tryzelaar
cced3c9013
std: simplify str::as_imm_buf and vec::as_{imm,mut}_buf
2013-07-23 16:57:00 -07:00
bors
9ed82fbb43
auto merge of #7943 : Dretch/rust/vec-slice-from-to, r=huonw
2013-07-22 13:49:34 -07:00
Daniel Micay
ed67cdb73c
new snapshot
2013-07-22 01:09:48 -04:00
Gareth Smith
30f13e661a
Add slice_from and slice_to methods for vec, like the
...
methods of the same names that already exist for strs.
2013-07-21 14:39:01 +01:00
blake2-ppc
24b6901b26
std: Implement Clone for VecIterator and iterators using it
...
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-20 20:30:57 +02:00
blake2-ppc
980646a450
Use Option .take() or .take_unwrap() instead of util::replace where possible
2013-07-20 05:12:05 -04:00
blake2-ppc
ff9b75f26d
Fix warnings in libstd and librusti tests
2013-07-18 02:18:56 +02:00
Patrick Walton
dc4bf173f8
test: Fix tests.
2013-07-17 14:57:55 -07:00
Patrick Walton
2dbb3c3887
test: Fix tests.
2013-07-17 14:57:54 -07:00
Patrick Walton
99b33f7219
librustc: Remove all uses of "copy".
2013-07-17 14:57:51 -07:00
Daniel Micay
e118555ce6
remove headers from unique vectors
2013-07-15 23:57:27 -04:00
Alex Crichton
9b21bf45e9
Account for possible 0-sized elements in vector iterators
...
Closes #7733
2013-07-12 16:13:57 -04:00
Alex Crichton
1ec06e0124
Remove the global 'vec::to_owned' function
2013-07-12 16:13:51 -04:00
Daniel Micay
2b96408600
extend the iterator tutorial
...
documents conversion, size hints and double-ended iterators and adds
more of the traits to the prelude
2013-07-12 01:53:50 -04:00