about summary refs log tree commit diff
path: root/src/libcollections
AgeCommit message (Collapse)AuthorLines
2014-12-20auto merge of #19903 : cgaebel/rust/ringbuf-as-slice, r=Gankrobors-2/+111
See: https://github.com/rust-lang/rfcs/pull/509 Not sure if this is allowed to land before the RFC. Either way, it's here for review. r? @Gankro cc: @bfops
2014-12-20Merge String::push_with_ascii_fast_path into String::push.Simon Sapin-40/+0
2014-12-20Add String::push_with_ascii_fast_path, bench it against String::pushSimon Sapin-0/+80
`String::push(&mut self, ch: char)` currently has a single code path that calls `Char::encode_utf8`. Perhaps it could be faster for ASCII `char`s, which are represented as a single byte in UTF-8. This commit leaves the method unchanged, adds a copy of it with the fast path, and adds benchmarks to compare them. Results show that the fast path very significantly improves the performance of repeatedly pushing an ASCII `char`, but does not significantly affect the performance for a non-ASCII `char` (where the fast path is not taken). Output of `make check-stage1-collections NO_REBUILD=1 PLEASE_BENCH=1 TESTNAME=string::tests::bench_push` ``` test string::tests::bench_push_char_one_byte ... bench: 59552 ns/iter (+/- 2132) = 167 MB/s test string::tests::bench_push_char_one_byte_with_fast_path ... bench: 6563 ns/iter (+/- 658) = 1523 MB/s test string::tests::bench_push_char_two_bytes ... bench: 71520 ns/iter (+/- 3541) = 279 MB/s test string::tests::bench_push_char_two_bytes_with_slow_path ... bench: 71452 ns/iter (+/- 4202) = 279 MB/s test string::tests::bench_push_str ... bench: 24 ns/iter (+/- 2) test string::tests::bench_push_str_one_byte ... bench: 38910 ns/iter (+/- 2477) = 257 MB/s ``` A benchmark of pushing a one-byte-long `&str` is added for comparison, but its performance [has varied a lot lately]( https://github.com/rust-lang/rust/pull/19640#issuecomment-67741561). (When the input is fixed, `s.push_str("x")` could be used instead of `s.push('x')`.)
2014-12-20Change `Extend` and `FromIterator` functionality of `BitvSet`Tobias Bucher-17/+29
Also fix up some tests from last commit.
2014-12-20Add a new invariant to `Bitv`Tobias Bucher-70/+84
The length of the underlying vector must now be exactly as long as it needs to be.
2014-12-20bitv: Fix all() for nbits that are multiples of u32::BITSJosh Stone-8/+43
The old logic would be ok with *either* 0 or all 1s in the last word, because it didn't compute a proper mask for the case where nbits is an exact multiple of u32::BITS. Add mask_for_bits() to compute this properly, and use it in all(). Add all/none assertions to most of the tests. Note in particular, the all-zero bitv in test_32_elements() was incorrectly all()==true before this patch.
2014-12-20bitv: correct build failuresJosh Stone-7/+8
- Fix typos on Blocks and MutBlocks. - Use slice_to_mut() for creating blocks_mut(). - Deref the block parameter in get(). - Access nbits separately from mutating set in pop().
2014-12-20Conventions and cleanup for Bitv and BitvSetAlexis Beingessner-686/+855
Part of #18424 This commit changes the semantics of `reserve` and `capacity` for Bitv and BitvSet to match conventions. It also introduces the notion of `reserve_index` and `reserve_index_exact` for collections with maximum-index-based capacity semantics. Deprecates free function constructors in favour of functions on Bitv itself. Changes `Bitv::pop` to return an Option rather than panicking. Deprecates and renames several methods in favour of conventions. Marks several blessed methods as unstable. This commit also substantially refactors Bitv and BitvSet's implementations. The new implementation is simpler, cleaner, better documented, and more robust against overflows. It also reduces coupling between Bitv and BitvSet. Tests have been seperated into seperate submodules. Fixes #16958 [breaking-change]
2014-12-20Stabilize cloneAaron Turon-1/+5
This patch marks `clone` stable, as well as the `Clone` trait, but leaves `clone_from` unstable. The latter will be decided by the beta. The patch also marks most manual implementations of `Clone` as stable, except where the APIs are otherwise deprecated or where there is uncertainty about providing `Clone`.
2014-12-20Fix fallout of removing import_shadowing in tests.Eduard Burtescu-72/+80
2014-12-20Fix more import_shadowing fallout in collections.Eduard Burtescu-43/+56
2014-12-20Fix the fallout of removing feature(import_shadowing).Eduard Burtescu-2/+0
2014-12-20Remove feature(import_shadowing) from all crates.Eduard Burtescu-1/+1
2014-12-20auto merge of #19640 : aliblong/rust/power_of_two_reform, r=Gankrobors-14/+4
The `is_power_of_two()` method of the `UnsignedInt` trait currently returns `true` for `self == 0`. Zero is not a power of two, assuming an integral exponent `k >= 0`. I've therefore moved this functionality to the new method `is_power_of_two_or_zero()` and reformed `is_power_of_two()` to return false for `self == 0`. To illustrate the usefulness of the existence of both functions, consider `HashMap`. Its capacity must be zero or a power of two; conversely, it also requires a (non-zero) power of two for key and val alignment. Also, added a small amount of documentation regarding #18604.
2014-12-19Reform power_of_two methods for perf increase & semantic change to consider ↵Aaron Liblong-14/+4
0 not a power of 2. Vec panics when attempting to reserve capacity > int::MAX (uint::MAX / 2).
2014-12-19Implement resize for VecChase Southwood-0/+27
This commit adds `resize` to `Vec` in accordance with RFC 509.
2014-12-19Register new snapshotsAlex Crichton-169/+0
This does not yet start the movement to rustc-serialize. That detail is left to a future PR.
2014-12-19libcollections: use `#[deriving(Copy)]`Jorge Aparicio-13/+6
2014-12-19Add RingBuf::as_slices as per collections reform v2.Clark Gaebel-2/+111
See: https://github.com/rust-lang/rfcs/pull/509 Not sure if this is allowed to land before the RFC. Either way, it's here for review. r? @Gankro cc: @bfops
2014-12-19auto merge of #19884 : nikomatsakis/rust/issue-19730-perfect-forwarding, ↵bors-2/+2
r=pnkfelix Rewrite how the HRTB algorithm matches impls against obligations. Instead of impls providing higher-ranked trait-references, impls now once again only have early-bound regions. The skolemization checks are thus moved out into trait matching itself. This allows to implement "perfect forwarding" impls like those described in #19730. This PR builds on a previous PR that was already reviewed by @pnkfelix. r? @pnkfelix Fixes #19730
2014-12-19Work around #19982 by rewriting test impls to not use anonymousNiko Matsakis-2/+2
lifetimes. This currently causes an ICE; it should (ideally) work, but failing that at least give a structured error. For the purposes of this PR, though, workaround is fine.
2014-12-18Revise std::thread API to join by defaultAaron Turon-1/+5
This commit is part of a series that introduces a `std::thread` API to replace `std::task`. In the new API, `spawn` returns a `JoinGuard`, which by default will join the spawned thread when dropped. It can also be used to join explicitly at any time, returning the thread's result. Alternatively, the spawned thread can be explicitly detached (so no join takes place). As part of this change, Rust processes now terminate when the main thread exits, even if other detached threads are still running, moving Rust closer to standard threading models. This new behavior may break code that was relying on the previously implicit join-all. In addition to the above, the new thread API also offers some built-in support for building blocking abstractions in user space; see the module doc for details. Closes #18000 [breaking-change]
2014-12-18Remove rt::{mutex, exclusive}Aaron Turon-3/+1
2014-12-18libs: merge librustrt into libstdAaron Turon-7/+5
This commit merges the `rustrt` crate into `std`, undoing part of the facade. This merger continues the paring down of the runtime system. Code relying on the public API of `rustrt` will break; some of this API is now available through `std::rt`, but is likely to change and/or be removed very soon. [breaking-change]
2014-12-18[collections] Adds `drain`: a way to sneak out the elements while clearing.Clark Gaebel-8/+313
It is useful to move all the elements out of some collections without deallocating the underlying buffer. It came up in IRC, and this patch implements it as `drain`. This has been discussed as part of RFC 509. r? @Gankro cc: @frankmcsherry
2014-12-18remove TreeMap, TreeSet, TrieMap, TrieSet, LruCache. deprecate EnumSet's std ↵Alexis Beingessner-6185/+0
re-export
2014-12-18librustc: Always parse `macro!()`/`macro![]` as expressions if notPatrick Walton-49/+50
followed by a semicolon. This allows code like `vec![1i, 2, 3].len();` to work. This breaks code that uses macros as statements without putting semicolons after them, such as: fn main() { ... assert!(a == b) assert!(c == d) println(...); } It also breaks code that uses macros as items without semicolons: local_data_key!(foo) fn main() { println("hello world") } Add semicolons to fix this code. Those two examples can be fixed as follows: fn main() { ... assert!(a == b); assert!(c == d); println(...); } local_data_key!(foo); fn main() { println("hello world") } RFC #378. Closes #18635. [breaking-change]
2014-12-18Clean up `collections::binary_heap`Andrew Paseltiner-24/+28
2014-12-17Remove wrong `&str + String` and `&[T] + Vec<T>` implementationsJorge Aparicio-17/+0
2014-12-17rollup merge of #19943: steveklabnik/doc_std_vecAlex Crichton-74/+105
Random improvements to the `std::vec` docs.
2014-12-17rollup merge of #19902: alexcrichton/second-pass-memAlex Crichton-0/+24
This commit stabilizes the `mem` and `default` modules of std.
2014-12-17rollup merge of #19895: jbranchaud/add-string-add-doctestAlex Crichton-0/+10
2014-12-17rollup merge of #19885: alexcrichton/char-escapeAlex Crichton-13/+23
This changes the `escape_unicode` method on a `char` to use the new style of unicode escapes in the language. Closes #19811 Closes #19879
2014-12-17rollup merge of #19873: drewm1980/masterAlex Crichton-1/+1
In US english, "that" is used in restrictive clauses in place of "which", and often affects the meaning of sentences. In UK english and many dialects, no distinction is made. While Rust devs want to avoid unproductive pedanticism, it is worth at least being uniform in documentation such as: http://doc.rust-lang.org/std/iter/index.html and also in cases where correct usage of US english clarifies the sentence.
2014-12-17rollup merge of #19871: pczarn/ring_buf-removeAlex Crichton-50/+250
Includes a fix for a small mistake in `fn insert` which is caught by test_insert for len=15, but not len=7. Part of #18424 r? @Gankro @csherratt @huonw
2014-12-17rollup merge of #19832: japaric/no-nocopyAlex Crichton-6/+0
r? @aturon / @alexcrichton
2014-12-17rollup merge of #19770: csouth3/iterator-wrapperstructsAlex Crichton-13/+57
Using a type alias for iterator implementations is fragile since this exposes the implementation to users of the iterator, and any changes could break existing code. This PR changes the iterators of `BTreeMap`, `BTreeSet`, `HashMap`, and `HashSet` to use proper new types, rather than type aliases. However, since it is fair-game to treat a type-alias as the aliased type, this is a: [breaking-change].
2014-12-17rollup merge of #19720: csouth3/vecmap-newtypesAlex Crichton-14/+45
Using a type alias for iterator implementations is fragile since this exposes the implementation to users of the iterator, and any changes could break existing code. This commit changes the iterators of `VecMap` to use proper new types, rather than type aliases. However, since it is fair-game to treat a type-alias as the aliased type, this is a: [breaking-change].
2014-12-17auto merge of #19800 : sfackler/rust/core-hash, r=alexcrichtonbors-944/+13
r? @alexcrichton
2014-12-16Improve docs for std::vecSteve Klabnik-74/+105
2014-12-17Implement remove for RingBufPiotr Czarnecki-50/+250
2014-12-16std: Change escape_unicode to use new escapesAlex Crichton-13/+23
This changes the `escape_unicode` method on a `char` to use the new style of unicode escapes in the language. Closes #19811 Closes #19879
2014-12-16auto merge of #19782 : gereeter/rust/cleanup-btree-node, r=Gankrobors-298/+259
Before: ``` test btree::map::bench::find_rand_100 ... bench: 12 ns/iter (+/- 0) test btree::map::bench::find_rand_10_000 ... bench: 13 ns/iter (+/- 1) test btree::map::bench::find_seq_100 ... bench: 11 ns/iter (+/- 0) test btree::map::bench::find_seq_10_000 ... bench: 11 ns/iter (+/- 1) test btree::map::bench::insert_rand_100 ... bench: 106 ns/iter (+/- 1) test btree::map::bench::insert_rand_10_000 ... bench: 326 ns/iter (+/- 8) test btree::map::bench::insert_seq_100 ... bench: 198 ns/iter (+/- 1) test btree::map::bench::insert_seq_10_000 ... bench: 312 ns/iter (+/- 3) test btree::map::bench::iter_1000 ... bench: 16563 ns/iter (+/- 173) test btree::map::bench::iter_100000 ... bench: 1686508 ns/iter (+/- 108592) test btree::map::bench::iter_20 ... bench: 365 ns/iter (+/- 25) ``` After: ``` test btree::map::bench::find_rand_100 ... bench: 12 ns/iter (+/- 0) test btree::map::bench::find_rand_10_000 ... bench: 12 ns/iter (+/- 0) test btree::map::bench::find_seq_100 ... bench: 11 ns/iter (+/- 0) test btree::map::bench::find_seq_10_000 ... bench: 11 ns/iter (+/- 0) test btree::map::bench::insert_rand_100 ... bench: 89 ns/iter (+/- 1) test btree::map::bench::insert_rand_10_000 ... bench: 121 ns/iter (+/- 3) test btree::map::bench::insert_seq_100 ... bench: 149 ns/iter (+/- 0) test btree::map::bench::insert_seq_10_000 ... bench: 228 ns/iter (+/- 1) test btree::map::bench::iter_1000 ... bench: 16965 ns/iter (+/- 220) test btree::map::bench::iter_100000 ... bench: 1687836 ns/iter (+/- 18746) test btree::map::bench::iter_20 ... bench: 366 ns/iter (+/- 21) ```
2014-12-16auto merge of #19777 : nikomatsakis/rust/warn-on-shadowing, r=acrichtobors-3/+3
per rfc 459 cc https://github.com/rust-lang/rust/issues/19390 One question is: should we start by warning, and only switch to hard error later? I think we discussed something like this in the meeting. r? @alexcrichton
2014-12-15Move hash module from collections to coreSteven Fackler-944/+13
2014-12-15std: Second pass stabilization of `default`Alex Crichton-0/+26
This commit performs a second pass stabilization of the `std::default` module. The module was already marked `#[stable]`, and the inheritance of `#[stable]` was removed since this attribute was applied. This commit adds the `#[stable]` attribute to the trait definition and one method name, along with all implementations found in the standard distribution.
2014-12-16auto merge of #19747 : alexcrichton/rust/slice-one-trait, r=brsonbors-29/+695
This commit collapses the various prelude traits for slices into just one trait: * SlicePrelude/SliceAllocPrelude => SliceExt * CloneSlicePrelude/CloneSliceAllocPrelude => CloneSliceExt * OrdSlicePrelude/OrdSliceAllocPrelude => OrdSliceExt * PartialEqSlicePrelude => PartialEqSliceExt
2014-12-15Use wrapper structs for `BTreeSet`'s iterators.Chase Southwood-7/+29
Using a type alias for iterator implementations is fragile since this exposes the implementation to users of the iterator, and any changes could break existing code. This commit changes the iterators of `BTreeSet` to use proper new types, rather than type aliases. However, since it is fair-game to treat a type-alias as the aliased type, this is a: [breaking-change].
2014-12-15Use wrapper structs for `BTreeMap`'s iterators.Chase Southwood-6/+28
Using a type alias for iterator implementations is fragile since this exposes the implementation to users of the iterator, and any changes could break existing code. This commit changes the keys and values iterators of `BTreeMap` to use proper new types, rather than type aliases. However, since it is fair-game to treat a type-alias as the aliased type, this is a: [breaking-change].
2014-12-15Add a doctest for the string Add function.jbranchaud-0/+10