summary refs log tree commit diff
path: root/src/libcollections
AgeCommit message (Collapse)AuthorLines
2016-11-05Rollup merge of #37587 - ollie27:to_mut, r=alexcrichtonAlex Crichton-1/+4
Remove recursive call from Cow::to_mut It seems to prevent it from being inlined.
2016-11-05Rollup merge of #37585 - leodasvacas:change_into_to_from, r=alexcrichtonAlex Crichton-4/+4
Change `Into<Vec<u8>> for String` and `Into<OsString> for PathBuf` to From Fixes #37561. First contribution, happy with any and all feedback!
2016-11-05Rollup merge of #37574 - ollie27:cow_add, r=alexcrichtonAlex Crichton-24/+37
Fix issues with the Add/AddAssign impls for Cow<str> * Correct the stability attributes. * Make Add and AddAssign actually behave the same. * Use String::with_capacity when allocating a new string. * Fix the tests.
2016-11-04Remove recursive call from Cow::to_mutOliver Middleton-1/+4
It seems to prevent it from being inlined.
2016-11-04Change Into<Vec<u8>> for String and Into<OsString> for PathBuf to From implsleonardo.yvens-4/+4
2016-11-04Auto merge of #37306 - bluss:trusted-len, r=alexcrichtonbors-57/+44
Add Iterator trait TrustedLen to enable better FromIterator / Extend This trait attempts to improve FromIterator / Extend code by enabling it to trust the iterator to produce an exact number of elements, which means that reallocation needs to happen only once and is moved out of the loop. `TrustedLen` differs from `ExactSizeIterator` in that it attempts to include _more_ iterators by allowing for the case that the iterator's len does not fit in `usize`. Consumers must check for this case (for example they could panic, since they can't allocate a collection of that size). For example, chain can be TrustedLen and all numerical ranges can be TrustedLen. All they need to do is to report an exact size if it fits in `usize`, and `None` as the upper bound otherwise. The trait describes its contract like this: ``` An iterator that reports an accurate length using size_hint. The iterator reports a size hint where it is either exact (lower bound is equal to upper bound), or the upper bound is `None`. The upper bound must only be `None` if the actual iterator length is larger than `usize::MAX`. The iterator must produce exactly the number of elements it reported. This trait must only be implemented when the contract is upheld. Consumers of this trait must inspect `.size_hint()`’s upper bound. ``` Fixes #37232
2016-11-04Fix issues with the Add/AddAssign impls for Cow<str>Oliver Middleton-24/+37
* Correct the stability attributes. * Make Add and AddAssign actually behave the same. * Use String::with_capacity when allocating a new string. * Fix the tests.
2016-11-04Link the tracking issue for TrustedLenUlrik Sverdrup-1/+1
2016-10-31Changed most vec! invocations to use square bracesiirelu-4/+4
Most of the Rust community agrees that the vec! macro is clearer when called using square brackets [] instead of regular brackets (). Most of these ocurrences are from before macros allowed using different types of brackets. There is one left unchanged in a pretty-print test, as the pretty printer still wants it to have regular brackets.
2016-10-27vec: Remove the Vec specialization for .extend()Ulrik Sverdrup-13/+0
This now produces as good code (with optimizations) using the TrustedLen codepath.
2016-10-27impl TrustedLen for vec::IntoIterUlrik Sverdrup-0/+3
2016-10-26Auto merge of #37419 - GuillaumeGomez:rollup, r=GuillaumeGomezbors-22/+22
Rollup of 7 pull requests - Successful merges: #36206, #37144, #37391, #37394, #37396, #37398, #37414 - Failed merges:
2016-10-26Auto merge of #37315 - bluss:fold-more, r=alexcrichtonbors-20/+54
Implement Iterator::fold for .chain(), .cloned(), .map() and the VecDeque iterators. Chain can do something interesting here where it passes on the fold into its inner iterators. The lets the underlying iterator's custom fold() be used, and skips the regular chain logic in next. Also implement .fold() specifically for .map() and .cloned() so that any inner fold improvements are available through map and cloned. The same way, a VecDeque iterator fold can be turned into two slice folds. These changes lend the power of the slice iterator's loop codegen to VecDeque, and to chains of slice iterators, and so on. It's an improvement for .sum() and .product(), and other uses of fold.
2016-10-26Vec docs: fix broken links and make quoting consistentDuncan-22/+22
2016-10-25Special case .fold() for VecDeque's iteratorsUlrik Sverdrup-20/+54
2016-10-22Auto merge of #37327 - aidanhs:aphs-bytes-iter-doc, r=alexcrichtonbors-2/+2
`as_bytes` is not the iterator on String, `bytes` is r? @steveklabnik
2016-10-22Auto merge of #37326 - SimonSapin:from-cow, r=alexcrichtonbors-0/+14
Implement `From<Cow<str>> for String` and `From<Cow<[T]>> for Vec<T>`. Motivation: the `selectors` crate is generic over a string type, in order to support all of `String`, `string_cache::Atom`, and `gecko_string_cache::Atom`. Multiple trait bounds are used for the various operations done with these strings. One of these operations is creating a string (as efficiently as possible, re-using an existing memory allocation if possible) from `Cow<str>`. The `std::convert::From` trait seems natural for this, but the relevant implementation was missing before this PR. To work around this I’ve added a `FromCowStr` trait in `selectors`, but with trait coherence that means one of `selectors` or `string_cache` needs to depend on the other to implement this trait. Using a trait from `std` would solve this. The `Vec<T>` implementation is just added for consistency. I also tried a more general `impl<'a, O, B: ?Sized + ToOwned<Owned=O>> From<Cow<'a, B>> for O`, but (the compiler thinks?) it conflicts with `From<T> for T` the impl (after moving all of `collections::borrow` into `core::borrow` to work around trait coherence).
2016-10-22Rollup merge of #37043 - GuillaumeGomez:vec_urls, r=frewsxcvGuillaume Gomez-52/+85
Add missing urls on Vec docs r? @steveklabnik
2016-10-21`as_bytes` is not the iterator, `bytes` isAidan Hobson Sayers-2/+2
2016-10-21vec: Add a debug assertion where TrustedLen is usedUlrik Sverdrup-1/+7
2016-10-21Implement `From<Cow<str>> for String` and `From<Cow<[T]>> for Vec<T>`.Simon Sapin-0/+14
Motivation: the `selectors` crate is generic over a string type, in order to support all of `String`, `string_cache::Atom`, and `gecko_string_cache::Atom`. Multiple trait bounds are used for the various operations done with these strings. One of these operations is creating a string (as efficiently as possible, re-using an existing memory allocation if possible) from `Cow<str>`. The `std::convert::From` trait seems natural for this, but the relevant implementation was missing before this PR. To work around this I’ve added a `FromCowStr` trait in `selectors`, but with trait coherence that means one of `selectors` or `string_cache` needs to depend on the other to implement this trait. Using a trait from `std` would solve this. The `Vec<T>` implementation is just added for consistency. I also tried a more general `impl<'a, O, B: ?Sized + ToOwned<Owned=O>> From<Cow<'a, B>> for O`, but (the compiler thinks?) it conflicts with `From<T> for T` the impl (after moving all of `collections::borrow` into `core::borrow` to work around trait coherence).
2016-10-21vec: Use Vec::extend specializations in extend_from_slice and moreUlrik Sverdrup-38/+2
The new Vec::extend covers the duties of .extend_from_slice() and some previous specializations.
2016-10-20Use TrustedLen for Vec's FromIterator and ExtendUlrik Sverdrup-10/+37
2016-10-20Add missing urls on Vec docsGuillaume Gomez-52/+85
2016-10-19Rollup merge of #37187 - frewsxcv:cow-doc-example, r=kmcallisterGuillaume Gomez-2/+15
Improve doc example for `std::borrow::Cow`. None
2016-10-16Update comment in Vec::dedup_byFlorian Diebold-1/+1
2016-10-15Auto merge of #37094 - fhartwig:spec-extend-from-slice, r=alexcrichtonbors-1/+18
Specialize Vec::extend to Vec::extend_from_slice I tried using the existing `SpecExtend` as a helper trait for this, but the instances would always conflict with the instances higher up in the file, so I created a new helper trait. Benchmarking `extend` vs `extend_from_slice` with an slice of 1000 `u64`s gives the following results: ``` before: running 2 tests test tests::bench_extend_from_slice ... bench: 166 ns/iter (+/- 78) test tests::bench_extend_trait ... bench: 1,187 ns/iter (+/- 697) after: running 2 tests test tests::bench_extend_from_slice ... bench: 149 ns/iter (+/- 87) test tests::bench_extend_trait ... bench: 138 ns/iter (+/- 70) ```
2016-10-15Improve doc example for `std::borrow::Cow`.Corey Farwell-2/+15
2016-10-13Auto merge of #36743 - SimonSapin:dedup-by, r=alexcrichtonbors-83/+126
Add Vec::dedup_by and Vec::dedup_by_key
2016-10-11Specialize Vec::extend to Vec::extend_from_sliceFlorian Hartwig-1/+18
2016-10-11Rollup merge of #37081 - p512:master, r=sfacklerGuillaume Gomez-1/+1
Changed 0 into '0' Right now `0` is an undefined production rule. [Documentation following the grammar specification](https://doc.rust-lang.org/nightly/std/fmt/#sign0) strongly suggests `'0'` is meant as it is used as a character literal. r? @steveklabnik
2016-10-11Rollup merge of #37073 - GuillaumeGomez:string_url, r=steveklabnikGuillaume Gomez-3/+4
Add missing urls on String module r? @steveklabnik
2016-10-11Rollup merge of #36699 - bluss:repeat-str, r=alexcrichtonGuillaume Gomez-0/+20
Add method str::repeat(self, usize) -> String It is relatively simple to repeat a string n times: `(0..n).map(|_| s).collect::<String>()`. It becomes slightly more complicated to do it “right” (sizing the allocation up front), which warrants a method that does it for us. This method is useful in writing testcases, or when generating text. `format!()` can be used to repeat single characters, but not repeating strings like this.
2016-10-11Merge two `impl<T> Vec<T>` blocks.Simon Sapin-126/+124
The show up separately in rustdoc. This is a separate commit to keep the previous one’s diff shorter.
2016-10-11Add Vec::dedup_by and Vec::dedup_by_keySimon Sapin-1/+46
2016-10-11Changed 0 into '0'p512-1/+1
0 is not a production rule but a literal
2016-10-11Add method str::repeat(self, usize) -> StringUlrik Sverdrup-0/+20
It is relatively simple to repeat a string n times: `(0..n).map(|_| s).collect::<String>()`. It becomes slightly more complicated to do it “right” (sizing the allocation up front), which warrants a method that does it for us. This method is useful in writing testcases, or when generating text. `format!()` can be used to repeat single characters, but not repeating strings like this.
2016-10-10Add missing urls on String moduleGuillaume Gomez-3/+4
2016-10-09Auto merge of #36982 - GuillaumeGomez:slice_urls, r=frewsxcvbors-7/+19
Add missing urls in slice doc module r? @steveklabnik
2016-10-08Add missing urls in slice doc moduleGuillaume Gomez-7/+19
2016-10-07Fix documentation for `write!` on `std::fmt` pageWesley Wiser-2/+2
Fixes #36906
2016-10-06Rollup merge of #36930 - angelsl:issue-36202, r=frewsxcvJonathan Turner-10/+10
Clarify last element in str.{r,}splitn documentation An attempt at #36202. I'm not sure if my wording is actually clearer, to be honest...
2016-10-06Clarify last element in str.{r,}splitn documentationangelsl-10/+10
2016-10-04Rollup merge of #36902 - ollie27:stab_impls, r=alexcrichtonManish Goregaokar-16/+53
std: Correct stability attributes for some implementations These are displayed by rustdoc so should be correct.
2016-10-03Auto merge of #36815 - alexcrichton:stabilize-1.13, r=aturonbors-0/+4
std: Stabilize and deprecate APIs for 1.13 This commit is intended to be backported to the 1.13 branch, and works with the following APIs: Stabilized * `i32::checked_abs` * `i32::wrapping_abs` * `i32::overflowing_abs` * `RefCell::try_borrow` * `RefCell::try_borrow_mut` Deprecated * `BinaryHeap::push_pop` * `BinaryHeap::replace` * `SipHash13` * `SipHash24` * `SipHasher` - use `DefaultHasher` instead in the `std::collections::hash_map` module Closes #28147 Closes #34767 Closes #35057 Closes #35070
2016-10-03std: Stabilize and deprecate APIs for 1.13Alex Crichton-0/+4
This commit is intended to be backported to the 1.13 branch, and works with the following APIs: Stabilized * `i32::checked_abs` * `i32::wrapping_abs` * `i32::overflowing_abs` * `RefCell::try_borrow` * `RefCell::try_borrow_mut` * `DefaultHasher` * `DefaultHasher::new` * `DefaultHasher::default` Deprecated * `BinaryHeap::push_pop` * `BinaryHeap::replace` * `SipHash13` * `SipHash24` * `SipHasher` - use `DefaultHasher` instead in the `std::collections::hash_map` module Closes #28147 Closes #34767 Closes #35057 Closes #35070
2016-10-01std: Correct stability attributes for some implementationsOliver Middleton-16/+53
These are displayed by rustdoc so should be correct.
2016-09-30Auto merge of #36339 - brson:emscripten-new, r=alexcrichtonbors-0/+1
Working asmjs and wasm targets This patch set results in a working standard library for the asmjs-unknown-emscripten and wasm32-unknown-emscripten targets. It is based on the work of @badboy and @rschulman. It does a few things: - Updates LLVM with the emscripten [fastcomp](https://github.com/rust-lang/llvm/pull/50) patches, which include the pnacl IR legalizer and the asm.js backend. This patch is thought not to have any significant effect on existing targets. - Teaches rustbuild to correctly link C code with emscripten - Updates gcc-rs to work correctly with emscripten - Teaches rustbuild to run crate tests for emscripten with node - Modifies Thread::new to return an error on emscripten, to facilitate debugging a common failure mode - Modifies libtest to run in single-threaded mode for emscripten - Ignores a host of tests that don't work yet, mostly dealing with threads and I/O - Updates libc with wasm32 definitions (presently the same as asmjs) - Adds a wasm32-unknown-emscripten target that feeds the output of LLVM's asmjs backend through emcc to generate wasm Notes and caveats: - This is only known to work with `--enable-rustbuild`. - The wasm32 target can't be tested correctly yet because of issues in compiletest and limitations in node https://github.com/kripken/emscripten/issues/4542, but hello.rs does seem to work when run on node via the binaryen interpreter - This requires an up to date installation of the emscripten sdk from its incoming branch - Unwinding is very broken - When enabling the emscripten targets jemalloc is disabled for all targets, which results in test failures for the host Next steps are to fix the jemalloc issue, start building the two emscripten targets on the auto builders, then start producing nightlies. https://github.com/rust-lang/rust/issues/36317 tracks work on this. Fixes https://github.com/rust-lang/rust/issues/36515 Fixes https://github.com/rust-lang/rust/issues/36515 Fixes https://github.com/rust-lang/rust/issues/36356
2016-09-30Ignore lots and lots of std tests on emscriptenBrian Anderson-0/+1
2016-09-30Rollup merge of #36623 - GuillaumeGomez:doc_typos, r=steveklabnikSteve Klabnik-30/+32
Fix some typos and improve doc comments style r? @steveklabnik