about summary refs log tree commit diff
path: root/src/liballoc/tests/lib.rs
AgeCommit message (Collapse)AuthorLines
2018-04-08Move deny(warnings) into rustbuildMark Simulacrum-2/+0
This permits easier iteration without having to worry about warnings being denied. Fixes #49517
2018-04-05Bump the bootstrap compiler to 1.26.0 betaAlex Crichton-1/+0
Holy cow that's a lot of `cfg(stage0)` removed and a lot of new stable language features!
2018-04-03Remove all unstable placement featuresAidan Hobson Sayers-2/+0
Closes #22181, #27779
2018-03-27Rollup merge of #48639 - varkor:sort_by_key-cached, r=blusskennytm-0/+1
Add slice::sort_by_cached_key as a memoised sort_by_key At present, `slice::sort_by_key` calls its key function twice for each comparison that is made. When the key function is expensive (which can often be the case when `sort_by_key` is chosen over `sort_by`), this can lead to very suboptimal behaviour. To address this, I've introduced a new slice method, `sort_by_cached_key`, which has identical semantic behaviour to `sort_by_key`, except that it guarantees the key function will only be called once per element. Where there are `n` elements and the key function is `O(m)`: - `slice::sort_by_cached_key` time complexity is `O(m n log m n)`, compared to `slice::sort_by_key`'s `O(m n + n log n)`. - `slice::sort_by_cached_key` space complexity remains at `O(n + m)`. (Technically, it now reserves a slice of size `n`, whereas before it reserved a slice of size `n/2`.) `slice::sort_unstable_by_key` has not been given an analogue, as it is important that unstable sorts are in-place, which is not a property that is guaranteed here. However, this also means that `slice::sort_unstable_by_key` is likely to be slower than `slice::sort_by_cached_key` when the key function does not have negligible complexity. We might want to explore this trade-off further in the future. Benchmarks (for a vector of 100 `i32`s): ``` # Lexicographic: `|x| x.to_string()` test bench_sort_by_key ... bench: 112,638 ns/iter (+/- 19,563) test bench_sort_by_cached_key ... bench: 15,038 ns/iter (+/- 4,814) # Identity: `|x| *x` test bench_sort_by_key ... bench: 1,346 ns/iter (+/- 238) test bench_sort_by_cached_key ... bench: 1,839 ns/iter (+/- 765) # Power: `|x| x.pow(31)` test bench_sort_by_key ... bench: 3,624 ns/iter (+/- 738) test bench_sort_by_cached_key ... bench: 1,997 ns/iter (+/- 311) # Abs: `|x| x.abs()` test bench_sort_by_key ... bench: 1,546 ns/iter (+/- 174) test bench_sort_by_cached_key ... bench: 1,668 ns/iter (+/- 790) ``` (So it seems functions that are single operations do perform slightly worse with this method, but for pretty much any more complex key, you're better off with this optimisation.) I've definitely found myself using expensive keys in the past and wishing this optimisation was made (e.g. for https://github.com/rust-lang/rust/pull/47415). This feels like both desirable and expected behaviour, at the small cost of slightly more stack allocation and minute degradation in performance for extremely trivial keys. Resolves #34447.
2018-03-17Fix use of unstable feature in testvarkor-0/+1
2018-03-15Auto merge of #47813 - kennytm:stable-incl-range, r=nrcbors-1/+2
Stabilize inclusive range (`..=`) Stabilize the followings: * `inclusive_range` — The `std::ops::RangeInclusive` and `std::ops::RangeInclusiveTo` types, except its fields (tracked by #49022 separately). * `inclusive_range_syntax` — The `a..=b` and `..=b` expression syntax * `dotdoteq_in_patterns` — Using `a..=b` in a pattern cc #28237 r? @rust-lang/lang
2018-03-15Keep the fields of RangeInclusive unstable.kennytm-0/+1
2018-03-15Stabilize `inclusive_range_syntax` language feature.kennytm-1/+1
Stabilize the syntax `a..=b` and `..=b`.
2018-03-14implementing fallible allocation API (try_reserve) for Vec, String and HashMapsnf-0/+1
2018-02-22Stabilize [T]::rotate_{left,right}Corey Farwell-1/+0
https://github.com/rust-lang/rust/issues/41891
2018-01-23Stabilized `#[repr(align(x))]` attribute (RFC 1358)Cameron Hart-1/+0
2018-01-13Add unit tests for exact_chunks/exact_chunks_mutSebastian Dröge-0/+1
These are basically modified copies of the chunks/chunks_mut tests.
2017-11-20alloc_system: don’t assume MIN_ALIGN for small sizes, fix #45955Simon Sapin-0/+4
The GNU C library (glibc) is documented to always allocate with an alignment of at least 8 or 16 bytes, on 32-bit or 64-bit platforms: https://www.gnu.org/software/libc/manual/html_node/Aligned-Memory-Blocks.html This matches our use of `MIN_ALIGN` before this commit. However, even when libc is glibc, the program might be linked with another allocator that redefines the `malloc` symbol and friends. (The `alloc_jemalloc` crate does, in some cases.) So `alloc_system` doesn’t know which allocator it calls, and needs to be conservative in assumptions it makes. The C standard says: https://port70.net/%7Ensz/c/c11/n1570.html#7.22.3 > The pointer returned if the allocation succeeds is suitably aligned > so that it may be assigned to a pointer to any type of object > with a fundamental alignment requirement https://port70.net/~nsz/c/c11/n1570.html#6.2.8p2 > A fundamental alignment is represented by an alignment less than > or equal to the greatest alignment supported by the implementation > in all contexts, which is equal to `_Alignof (max_align_t)`. `_Alignof (max_align_t)` depends on the ABI and doesn’t seem to have a clear definition, but it seems to match our `MIN_ALIGN` in practice. However, the size of objects is rounded up to the next multiple of their alignment (since that size is also the stride used in arrays). Conversely, the alignment of a non-zero-size object is at most its size. So for example it seems ot be legal for `malloc(8)` to return a pointer that’s only 8-bytes-aligned, even if `_Alignof (max_align_t)` is 16.
2017-11-08std: Remove `rand` crate and moduleAlex Crichton-0/+1
This commit removes the `rand` crate from the standard library facade as well as the `__rand` module in the standard library. Neither of these were used in any meaningful way in the standard library itself. The only need for randomness in libstd is to initialize the thread-local keys of a `HashMap`, and that unconditionally used `OsRng` defined in the standard library anyway. The cruft of the `rand` crate and the extra `rand` support in the standard library makes libstd slightly more difficult to port to new platforms, namely WebAssembly which doesn't have any randomness at all (without interfacing with JS). The purpose of this commit is to clarify and streamline randomness in libstd, focusing on how it's only required in one location, hashmap seeds. Note that the `rand` crate out of tree has almost always been a drop-in replacement for the `rand` crate in-tree, so any usage (accidental or purposeful) of the crate in-tree should switch to the `rand` crate on crates.io. This then also has the further benefit of avoiding duplication (mostly) between the two crates!
2017-09-12Disable the new Hasher tests on Emscripten.kennytm-0/+3
2017-09-12impl Hasher for {&mut Hasher, Box<Hasher>}kennytm-0/+13
2017-08-27Move unused-extern-crate to late passTatsuyuki Ishi-5/+0
2017-08-15Auto merge of #43245 - Gankro:drain-filter, r=sfacklerbors-0/+1
Add Vec::drain_filter This implements the API proposed in #43244. So I spent like half a day figuring out how to implement this in some awesome super-optimized unsafe way, which had me very confident this was worth putting into the stdlib. Then I looked at the impl for `retain`, and was like "oh dang". I compared the two and they basically ended up being the same speed. And the `retain` impl probably translates to DoubleEndedIter a lot more cleanly if we ever want that. So now I'm not totally confident this needs to go in the stdlib, but I've got two implementations and an amazingly robust test suite, so I figured I might as well toss it over the fence for discussion.
2017-08-15Auto merge of #43500 - murarth:string-retain, r=alexcrichtonbors-0/+1
Add method `String::retain` Behaves like `Vec::retain`, accepting a predicate `FnMut(char) -> bool` and reducing the string to only characters for which the predicate returns `true`.
2017-08-14Add method `String::retain`Murarth-0/+1
Behaves like `Vec::retain`, accepting a predicate `FnMut(char) -> bool` and reducing the string to only characters for which the predicate returns `true`.
2017-07-25std: Stabilize `utf8_error_error_len` featureAlex Crichton-1/+0
Stabilizes: * `Utf8Error::error_len` Closes #40494
2017-07-25std: Stabilize `str_checked_slicing` featureAlex Crichton-1/+0
Stabilized * `<str>::get` * `<str>::get_mut` * `<str>::get_unchecked` * `<str>::get_unchecked_mut` Closes #39932
2017-07-19Add Vec::drain_filterAlexis Beingessner-0/+1
2017-06-13Merge crate `collections` into `alloc`Murarth-0/+57