about summary refs log tree commit diff
path: root/src/liballoc
AgeCommit message (Collapse)AuthorLines
2018-04-12Auto merge of #49698 - SimonSapin:unicode-for-everyone, r=alexcrichtonbors-25/+36
Merge the std_unicode crate into the core crate [The standard library facade](https://github.com/rust-lang/rust/issues/27783) has historically contained a number of crates with different roles, but that number has decreased over time. `rand` and `libc` have moved to crates.io, and [`collections` was merged into `alloc`](https://github.com/rust-lang/rust/pull/42648). Today we have `core` that applies everywhere, `std` that expects a full operating system, and `alloc` in-between that only requires a memory allocator (which can be provided by users)… and `std_unicode`, which doesn’t really have a reason to be separate anymore. It contains functionality based on Unicode data tables that can be large, but as long as relevant functions are not called the tables should be removed from binaries by linkers. This deprecates the unstable `std_unicode` crate and moves all of its contents into `core`, replacing them with `pub use` reexports. The crate can be removed later. This also removes the `CharExt` trait (replaced with inherent methods in libcore) and `UnicodeStr` trait (merged into `StrExt`). There traits were both unstable and not intended to be used or named directly. A number of new items are newly-available in libcore and instantly stable there, but only if they were already stable in libstd. Fixes #49319.
2018-04-12Mark the rest of the `unicode` feature flag as perma-unstable.Simon Sapin-2/+1
2018-04-12Merge unstable Utf16Encoder into EncodeUtf16Simon Sapin-7/+23
2018-04-12Merge core::unicode::str into core::strSimon Sapin-9/+9
And the UnicodeStr trait into StrExt
2018-04-12Reexport from core::unicode::char in core::char rather than vice versaSimon Sapin-2/+2
2018-04-12Deprecate the std_unicode crateSimon Sapin-11/+7
2018-04-12Move Utf8Lossy decoder to libcoreSimon Sapin-1/+1
2018-04-11Rollup merge of #49525 - varkor:sort_by_cached_key-conversion, r=scottmcmkennytm-0/+1
Use sort_by_cached_key where appropriate A follow-up to https://github.com/rust-lang/rust/pull/48639, converting various slice sorting calls to `sort_by_cached_key` when the key functions are more expensive.
2018-04-09Add trivial early return for sort_by_cached_keyvarkor-0/+1
2018-04-08Move deny(warnings) into rustbuildMark Simulacrum-5/+0
This permits easier iteration without having to worry about warnings being denied. Fixes #49517
2018-04-07Auto merge of #49661 - alexcrichton:bump-bootstrap, r=nikomatsakisbors-4/+1
Bump the bootstrap compiler to 1.26.0 beta Holy cow that's a lot of `cfg(stage0)` removed and a lot of new stable language features!
2018-04-07Inject the `compiler_builtins` crate whenever the `core` crate is injectedOliver Schneider-0/+1
2018-04-05Rollup merge of #49621 - Nemo157:impl-unpin-for-pin, r=withoutboatsAlex Crichton-0/+3
2018-04-05impl Unpin for PinBoxWim Looman-0/+3
2018-04-05Bump the bootstrap compiler to 1.26.0 betaAlex Crichton-4/+1
Holy cow that's a lot of `cfg(stage0)` removed and a lot of new stable language features!
2018-04-05Auto merge of #49684 - kennytm:rollup, r=kennytmbors-26/+55
Rollup of 9 pull requests Successful merges: - #48658 (Add a generic CAS loop to std::sync::Atomic*) - #49253 (Take the original extra-filename passed to a crate into account when resolving it as a dependency) - #49345 (RFC 2008: Finishing Touches) - #49432 (Flush executables to disk after linkage) - #49496 (Add more vec![... ; n] optimizations) - #49563 (add a dist builder to build rust-std components for the THUMB targets) - #49654 (Host compiler documentation: Include private items) - #49667 (Add more features to rust_2018_preview) - #49674 (ci: Remove x86_64-gnu-incremental builder) Failed merges:
2018-04-05Rollup merge of #49496 - glandium:master, r=sfacklerkennytm-26/+55
Add more vec![... ; n] optimizations vec![0; n], via implementations of SpecFromElem, has an optimization that uses with_capacity_zeroed instead of with_capacity, which will use calloc instead of malloc, and avoid an extra memset. This PR adds the same optimization for ptr::null, ptr::null_mut, and None, when their in-memory representation is zeroes.
2018-04-05Auto merge of #48851 - petrochenkov:genparattr, r=nikomatsakisbors-1/+1
Stabilize attributes on generic parameters Closes https://github.com/rust-lang/rust/issues/48848
2018-04-05Stabilize attributes on generic parametersVadim Petrochenkov-1/+1
2018-04-04Rollup merge of #49607 - cuviper:stable-iter-1.27, r=alexcrichtonkennytm-1/+0
Stabilize iterator methods in 1.27 - Closes #39480, feature `iter_rfind` - `DoubleEndedIterator::rfind` - Closes #44705, feature `iter_rfold` - `DoubleEndedIterator::rfold` - Closes #45594, feature `iterator_try_fold` - `Iterator::try_fold` - `Iterator::try_for_each` - `DoubleEndedIterator::try_rfold`
2018-04-04Rollup merge of #49577 - tmccombs:string-splice-stabilize, r=TimNNkennytm-21/+20
Stabilize String::replace_range Fixes #44643
2018-04-04Rollup merge of #49559 - djc:resize-with, r=TimNNkennytm-7/+57
Introduce Vec::resize_with method (see #41758) In #41758, the libs team decided they preferred `Vec::resize_with` over `Vec::resize_default()`. Here is an implementation to get this moving forward. I don't know what the removal process for `Vec::resize_default()` should be, so I've left it in place for now. Would be happy to follow up with its removal.
2018-04-04Rollup merge of #49533 - scottmcm:more-must-use, r=nikomatsakiskennytm-0/+1
Add #[must_use] to a few standard library methods Chosen to start a precedent of using it on ones that are potentially-expensive and where using it for side effects is particularly discouraged. Discuss :) ```rust warning: unused return value of `std::iter::Iterator::collect` which must be used: if you really need to exhaust the iterator, consider `.for_each(drop)` instead --> $DIR/fn_must_use_stdlib.rs:19:5 | LL | "1 2 3".split_whitespace().collect::<Vec<_>>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ warning: unused return value of `std::borrow::ToOwned::to_owned` which must be used: cloning is often expensive and is not expected to have side effects --> $DIR/fn_must_use_stdlib.rs:21:5 | LL | "hello".to_owned(); | ^^^^^^^^^^^^^^^^^^^ warning: unused return value of `std::clone::Clone::clone` which must be used: cloning is often expensive and is not expected to have side effects --> $DIR/fn_must_use_stdlib.rs:23:5 | LL | String::from("world").clone(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ``` cc https://github.com/rust-lang/rust/issues/48926
2018-04-03Introduce Vec::resize_with method (see #41758)Dirkjan Ochtman-7/+57
2018-04-03Remove all unstable placement featuresAidan Hobson Sayers-680/+11
Closes #22181, #27779
2018-04-02Merge remote-tracking branch 'upstream/master' into string-splice-stabilizeThayne McCombs-5/+10
2018-04-02Stabilize iter_rfold in 1.27.0Josh Stone-1/+0
2018-04-02Use Alloc and Layout from core::heap.Mike Hommey-5/+10
94d1970bba87f2d2893f6e934e4c3f02ed50604d moved the alloc::allocator module to core::heap, moving e.g. Alloc and Layout out of the alloc crate. While alloc::heap reexports them, it's better to use them from where they really come from.
2018-04-01Stabilize String::replace_rangeThayne McCombs-21/+20
Fixes #44643
2018-04-02Add vec!['\0'; n] optimization, like vec![0; n]Mike Hommey-0/+2
Similarly to vec![ptr::null{,_mut}(); n] in previous change, this adds the optimization for vec!['\0'; n].
2018-04-02Add vec![ptr::null{,_mut}(); n] optimization, like vec![0; n]Mike Hommey-26/+53
vec![0; n], via implementations of SpecFromElem, has an optimization that uses with_capacity_zeroed instead of with_capacity, which will use calloc instead of malloc, and avoid an extra memset. This adds the same optimization for vec![ptr::null(); n] and vec![ptr::null_mut(); n], assuming their bit value is 0 (which is true on all currently supported platforms). This does so by adding an intermediate trait IsZero, which looks very much like nonzero::Zeroable, but that one is on the way out, and doesn't apply to pointers anyways. Adding such a trait allows to avoid repeating the logic using with_capacity_zeroed or with_capacity, or making the macro more complex to support generics.
2018-03-31Auto merge of #49481 - SimonSapin:core-heap, r=alexcrichtonbors-1086/+5
Move the alloc::allocator module to core::heap This is the `Alloc` trait and its dependencies.
2018-03-30Add #[must_use] to a few standard library methodsScott McMurray-0/+1
Chosen to start a precedent of using it on ones that are potentially-expensive and where using it for side effects is particularly discouraged. Discuss :)
2018-03-30Rollup merge of #49468 - glandium:cleanup, r=pnkfelixkennytm-2/+2
Remove unnecessary use core::hash in liballoc/boxed.rs It' only used for hash::Hasher, but Hasher is also imported.
2018-03-30Rollup merge of #49466 - glandium:master, r=rkruppekennytm-2/+2
Use f{32,64}::to_bits for is_zero test in vec::SpecFromElem vec::SpecFromElem provides an optimization to use calloc to fill a Vec when the element given to fill the Vec is represented by 0. For floats, the test for that currently used is `x == 0. && x.is_sign_positive()`. When compiled in a standalone function, rustc generates the following assembly: ``` xorps xmm1, xmm1 ucomisd xmm0, xmm1 setnp al sete cl and cl, al movq rax, xmm0 test rax, rax setns al and al, cl ret ``` A simpler test telling us whether the value is represented by 0, is `x.to_bits() == 0`, which rustc compiles to: ``` movq rax, xmm0 test rax, rax sete al ret ``` Not that the test is hot in any way, but it also makes it clearer what the intent in the rust code is.
2018-03-29Move the alloc::allocator module to core::heapSimon Sapin-1086/+5
This is the `Alloc` trait and its dependencies.
2018-03-29Move RangeArguments to {core::std}::ops and rename to RangeBoundsSimon Sapin-171/+15
These unstable items are deprecated: * The `std::collections::range::RangeArgument` reexport * The `std::collections::range` module.
2018-03-29Move alloc::Bound to {core,std}::opsSimon Sapin-59/+8
The stable reexport `std::collections::Bound` is now deprecated. Another deprecated reexport could be added in `alloc`, but that crate is unstable.
2018-03-29Remove unnecessary use core::hash in liballoc/boxed.rsMike Hommey-2/+2
It' only used for hash::Hasher, but Hasher is also imported.
2018-03-29Use f{32,64}::to_bits for is_zero test in vec::SpecFromElemMike Hommey-2/+2
vec::SpecFromElem provides an optimization to use calloc to fill a Vec when the element given to fill the Vec is represented by 0. For floats, the test for that currently used is `x == 0. && x.is_sign_positive()`. When compiled in a standalone function, rustc generates the following assembly: ``` xorps xmm1, xmm1 ucomisd xmm0, xmm1 setnp al sete cl and cl, al movq rax, xmm0 test rax, rax setns al and al, cl ret ``` A simpler test telling us whether the value is represented by 0, is `x.to_bits() == 0`, which rustc compiles to: ``` movq rax, xmm0 test rax, rax sete al ret ``` Not that the test is hot in any way, but it also makes it clearer what the intent in the rust code is.
2018-03-28Rollup merge of #49452 - frewsxcv:frewsxcv-vec-cap-len, r=dtolnaykennytm-3/+4
Clarify "length" wording in `Vec::with_capacity`. Fixes https://github.com/rust-lang/rust/issues/49448.
2018-03-28Rollup merge of #49400 - Diggsey:shrink-to, r=joshtriplettkennytm-2/+113
Implement `shrink_to` method on collections Fixes #49385
2018-03-28Rollup merge of #49243 - murarth:stabilize-retain, r=BurntSushikennytm-3/+1
Stabilize method `String::retain` Closes #43874
2018-03-28Clarify "length" wording in `Vec::with_capacity`.Corey Farwell-3/+4
2018-03-27Rollup merge of #49401 - alercah:format, r=cramertjkennytm-7/+8
Add missing '?' to format grammar.
2018-03-27Rollup merge of #49381 - withoutboats:str_unicode, r=SimonSapinkennytm-0/+42
Add is_whitespace and is_alphanumeric to str. The other methods from `UnicodeStr` are already stable inherent methods on str, but these have not been included. r? @SimonSapin
2018-03-27Rollup merge of #48639 - varkor:sort_by_key-cached, r=blusskennytm-13/+111
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-26Add missing '?' to format grammar.Alexis Hunt-7/+8
2018-03-27Implement `shrink_to` method on collectionsDiggory Blake-2/+113
2018-03-26Remove mentions of unstable sort_by_cached key from stable documentationvarkor-8/+0