| Age | Commit message (Collapse) | Author | Lines |
|
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
|
|
|
|
`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')`.)
|
|
Also fix up some tests from last commit.
|
|
The length of the underlying vector must now be exactly as long as it needs to
be.
|
|
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.
|
|
- 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().
|
|
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]
|
|
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`.
|
|
|
|
|
|
|
|
|
|
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.
|
|
0 not a power of 2.
Vec panics when attempting to reserve capacity > int::MAX (uint::MAX / 2).
|
|
This commit adds `resize` to `Vec` in accordance with RFC 509.
|
|
This does not yet start the movement to rustc-serialize. That detail is left to
a future PR.
|
|
|
|
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
|
|
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
|
|
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.
|
|
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]
|
|
|
|
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]
|
|
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
|
|
re-export
|
|
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]
|
|
|
|
|
|
Random improvements to the `std::vec` docs.
|
|
This commit stabilizes the `mem` and `default` modules of std.
|
|
|
|
This changes the `escape_unicode` method on a `char` to use the new style of
unicode escapes in the language.
Closes #19811
Closes #19879
|
|
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.
|
|
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
|
|
r? @aturon / @alexcrichton
|
|
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].
|
|
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].
|
|
r? @alexcrichton
|
|
|
|
|
|
This changes the `escape_unicode` method on a `char` to use the new style of
unicode escapes in the language.
Closes #19811
Closes #19879
|
|
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)
```
|
|
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
|
|
|
|
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.
|
|
This commit collapses the various prelude traits for slices into just one trait:
* SlicePrelude/SliceAllocPrelude => SliceExt
* CloneSlicePrelude/CloneSliceAllocPrelude => CloneSliceExt
* OrdSlicePrelude/OrdSliceAllocPrelude => OrdSliceExt
* PartialEqSlicePrelude => PartialEqSliceExt
|
|
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].
|
|
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].
|
|
|