Commit Graph

331 Commits

Author SHA1 Message Date
Robin Kruppe
7ff10209aa Enlarge Bignum type from 1152 to 1280 bits.
This is necessary for decimal-to-float code (in a later commit) to handle
inputs such as 4.9406564584124654e-324 (the smallest subnormal f64).
According to the benchmarks for flt2dec::dragon, this does not
affect performance measurably. It probably uses slightly more stack
space though.
2015-08-08 17:15:14 +02:00
bors
ff6c6ce917 Auto merge of #27280 - bluss:siphash-perf, r=alexcrichton
Improve siphash performance for longer data

Use `ptr::copy_nonoverlapping` (aka memcpy) to load an u64 from the
byte stream. This is correct for any alignment, and the compiler will
use the appropriate instruction to load the data.

Also contains small tweaks that should benefit hashing short data too,
both the commit that removes a variable and the autovectorization of
the hash state initialization (in SipHash::reset).

Benchmarks show that hashing longer data benefits for the improved word loading.

Before (using benchmarks from the first commit in the PR):

The before benchmark is a bit noisy.

```
test hash::sip::bench_bytes_4                              ... bench:          41 ns/iter (+/- 0) = 97 MB/s
test hash::sip::bench_bytes_7                              ... bench:          49 ns/iter (+/- 2) = 142 MB/s
test hash::sip::bench_bytes_8                              ... bench:          42 ns/iter (+/- 4) = 190 MB/s
test hash::sip::bench_bytes_a_16                           ... bench:          57 ns/iter (+/- 14) = 280 MB/s
test hash::sip::bench_bytes_b_32                           ... bench:          85 ns/iter (+/- 74) = 376 MB/s
test hash::sip::bench_bytes_c_128                          ... bench:         278 ns/iter (+/- 33) = 460 MB/s
test hash::sip::bench_long_str                             ... bench:         825 ns/iter (+/- 103)
test hash::sip::bench_str_of_8_bytes                       ... bench:         151 ns/iter (+/- 66)
test hash::sip::bench_str_over_8_bytes                     ... bench:          59 ns/iter (+/- 3)
test hash::sip::bench_str_under_8_bytes                    ... bench:          47 ns/iter (+/- 56)
test hash::sip::bench_u32                                  ... bench:          39 ns/iter (+/- 93) = 205 MB/s
test hash::sip::bench_u32_keyed                            ... bench:          40 ns/iter (+/- 88) = 200 MB/s
test hash::sip::bench_u64                                  ... bench:          54 ns/iter (+/- 96) = 148 MB/s
```

After:

```
test hash::sip::bench_bytes_4                              ... bench:          41 ns/iter (+/- 3) = 97 MB/s
test hash::sip::bench_bytes_7                              ... bench:          48 ns/iter (+/- 0) = 145 MB/s
test hash::sip::bench_bytes_8                              ... bench:          35 ns/iter (+/- 1) = 228 MB/s
test hash::sip::bench_bytes_a_16                           ... bench:          45 ns/iter (+/- 1) = 355 MB/s
test hash::sip::bench_bytes_b_32                           ... bench:          60 ns/iter (+/- 0) = 533 MB/s
test hash::sip::bench_bytes_c_128                          ... bench:         161 ns/iter (+/- 5) = 795 MB/s
test hash::sip::bench_long_str                             ... bench:         514 ns/iter (+/- 5)
test hash::sip::bench_str_of_8_bytes                       ... bench:          44 ns/iter (+/- 0)
test hash::sip::bench_str_over_8_bytes                     ... bench:          51 ns/iter (+/- 0)
test hash::sip::bench_str_under_8_bytes                    ... bench:          52 ns/iter (+/- 6)
test hash::sip::bench_u32                                  ... bench:          40 ns/iter (+/- 2) = 200 MB/s
test hash::sip::bench_u32_keyed                            ... bench:          39 ns/iter (+/- 1) = 205 MB/s
test hash::sip::bench_u64                                  ... bench:          36 ns/iter (+/- 1) = 222 MB/s
```
2015-07-28 05:38:53 +00:00
Ulrik Sverdrup
381d2ed70d siphash: Add more benchmarks 2015-07-25 12:26:17 +02:00
bors
18557500cb Auto merge of #27026 - nagisa:overflowing-unsigned, r=pnkfelix
This commit fixes the negate_unsigned feature gate to appropriately
account for inferred variables.

This is technically a [breaking-change], but I’d consider it a bug fix.

cc @brson for your relnotes.

Fixes https://github.com/rust-lang/rust/issues/24676
Fixes #26840 
Fixes https://github.com/rust-lang/rust/issues/25206
2015-07-20 16:38:33 +00:00
arthurprs
c073f81920 optimize from_str_radix 2015-07-19 09:54:44 -03:00
Simonas Kazlauskas
0c9e3dc75c Fix negate_unsigned feature gate check
This commit fixes the negate_unsigned feature gate to appropriately
account for infered variables.

This is technically a [breaking-change].
2015-07-14 21:48:43 +03:00
Ulrik Sverdrup
86d954ba2b core: Revive SipHash's tests
These tests were bitrotting, include them in the crate and bring them up
to date and compiling.. and they pass.
2015-07-14 18:41:04 +02:00
Ulrik Sverdrup
836f32e769 Use vec![elt; n] where possible
The common pattern `iter::repeat(elt).take(n).collect::<Vec<_>>()` is
exactly equivalent to `vec![elt; n]`, do this replacement in the whole
tree.

(Actually, vec![] is smart enough to only call clone n - 1 times, while
the former solution would call clone n times, and this fact is
virtually irrelevant in practice.)
2015-07-09 11:05:32 +02:00
Alex Crichton
98566ea951 std: Fix formatting flags for chars
This recently regressed in #24689, and this updates the `Display` implementation
to take formatting flags into account.

Closes #26625
2015-06-30 19:26:03 -07:00
Simon Sapin
32b7b50baf Remove char::to_titlecase. Fix #26555
I added it because it was easy (same a `char::to_lowercase`,
just a different table), but it doesn’t make sense to have this
in std but not str::to_titlecase, which would require
https://github.com/unicode-rs/unicode-segmentation

At some point in the future this feature will be available
(both on char and str) in a crates.io crate.
2015-06-24 22:16:25 -07:00
Alex Crichton
ce1a965cf5 Fallout in tests and docs from feature renamings 2015-06-17 09:07:16 -07:00
bors
a54a809219 Auto merge of #25359 - thepowersgang:result-expect-2, r=alexcrichton
As it says in the title. I've added an `expect` method to `Result` that allows printing both an error message (e.g. what operation was attempted), and the error value. This is separate from the `unwrap` and `ok().expect("message")` behaviours.
2015-06-15 05:11:53 +00:00
John Hodge
0937c10f3c libcore/Result - RFC#1119 Add an 'expect' method to Result 2015-06-15 12:00:16 +08:00
Joshua Landau
ca7418b846 Removed many pointless calls to *iter() and iter_mut() 2015-06-10 21:14:03 +01:00
Simon Sapin
6369dcbad8 Move collectionstest::char into coretest::char 2015-06-09 13:08:29 +02:00
Simon Sapin
c6a8d5e733 Fix coretest::char::test_to_uppercase for complex mapping 2015-06-09 13:08:22 +02:00
bors
a0f028da07 Auto merge of #25817 - XMPPwocky:once_cleanedup, r=alexcrichton
Closes #24443.
2015-05-30 01:12:35 +00:00
Nathaniel Theis
103e79d26a Implement RFC 771: std::iter::once 2015-05-29 12:02:13 -07:00
Niko Matsakis
2c5e784d6f add const_fn features 2015-05-29 09:42:54 -04:00
Simon Sapin
d0afa6ede3 Add map and filter_map associated functions to std::cell::Ref and RefMut
See design discussion in https://github.com/rust-lang/rust/pull/25747
2015-05-29 08:39:07 +02:00
Simon Sapin
c516eee503 Move std::cell::clone_ref to a clone associated function on std::cell::Ref
... and generalize the bounds on the value type.
2015-05-28 23:01:36 +02:00
Eduard Burtescu
377b0900ae Use const fn to abstract away the contents of UnsafeCell & friends. 2015-05-27 11:19:03 +03:00
Steven Fackler
e161d5cf73 Stabilize debug builders for 1.2.0 2015-05-19 21:57:39 -07:00
Nick Cameron
5d4cce6cec Rebasing 2015-05-13 14:35:53 +12:00
bors
67ba6dcf68 Auto merge of #24612 - lifthrasiir:flt2dec, r=pnkfelix
This is a direct port of my prior work on the float formatting. The detailed description is available [here](https://github.com/lifthrasiir/rust-strconv#flt2dec). In brief,

* This adds a new hidden module `core::num::flt2dec` for testing from `libcoretest`. Why is it in `core::num` instead of `core::fmt`? Because I envision that the table used by `flt2dec` is directly applicable to `dec2flt` (cf. #24557) as well, which exceeds the realm of "formatting".
* This contains both Dragon4 algorithm (exact, complete but slow) and Grisu3 algorithm (exact, fast but incomplete).
* The code is accompanied with a large amount of self-tests and some exhaustive tests. In particular, `libcoretest` gets a new dependency on `librand`. For the external interface it relies on the existing test suite.
* It is known that, in the best case, the entire formatting code has about 30 KBs of binary overhead (judged from strconv experiments). Not too bad but there might be a potential room for improvements.

This is rather large code. I did my best to comment and annotate the code, but you have been warned.

For the maximal availability the original code was licensed in CC0, but I've also dual-licensed it in MIT/Apache as well so there should be no licensing concern.

This is [breaking-change] as it changes the float output slightly (and it also affects the casing of `inf` and `nan`). I hope this is not a big deal though :)

Fixes #7030, #18038 and #24556. Also related to #6220 and #20870.

## Known Issues

- [x] I've yet to finish `make check-stage1`. It does pass main test suites including `run-pass` but there might be some unknown edges on the doctests.
- [ ] Figure out how this PR affects rustc.
- [ ] Determine which internal routine is mapped to the formatting specifier. Depending on the decision, some internal routine can be safely removed (for instance, currently `to_shortest_str` is unused).
2015-05-09 14:56:56 +00:00
Kang Seonghoon
3d34e177dd core: use banker's rounding for the exact mode in flt2dec.
For the shortest mode the IEEE 754 decoder already provides
an exact rounding range accounting for banker's rounding,
but it was not the case for the exact mode. This commit alters
the exact mode algorithm for Dragon so that any number ending at
`...x5000...` with even `x` and infinite zeroes will round to
`...x` instead of `...(x+1)` as it was. Grisu is not affected
by this change because this halfway case always results in
the failure for Grisu.
2015-05-06 21:11:14 +09:00
Kang Seonghoon
a641b05fda core: updated for the master changes.
The master no longer has `std::num::Float`, so a generic `ldexp` is
not readily available. `DecodableFloat::ldexpi` works around this.
2015-05-06 14:22:26 +09:00
Kang Seonghoon
97ea7c14ba core: fixed a slight bug.
The bug involves the incorrect logic for `core::num::flt2dec::decoder`.
This makes some numbers in the form of 2^n missing one final digits,
which breaks the bijectivity criterion. The regression tests have been
added, and f32 exhaustive test is rerun to get the updated result.
2015-05-06 14:22:26 +09:00
Kang Seonghoon
8a195f0754 core: fixed typos and revised comments in flt2dec. 2015-05-06 14:22:20 +09:00
Kang Seonghoon
f9bfda0a6f core: tweaked flt2dec to match the casing of the older formatting code. 2015-05-06 14:21:48 +09:00
Kang Seonghoon
c82da7a54b core: added core::num::flt2dec for floating-point formatting.
This is a fork of the flt2dec portion of rust-strconv [1] with
a necessary relicensing (the original code was licensed CC0-1.0).
Each module is accompanied with large unit tests, integrated
in this commit as coretest::num::flt2dec. This module is added
in order to replace the existing core::fmt::float method.

The forked revision of rust-strconv is from 2015-04-20, with a commit ID
9adf6d3571c6764a6f240a740c823024f70dc1c7.

[1] https://github.com/lifthrasiir/rust-strconv/
2015-05-06 14:19:37 +09:00
Steven Allen
3fcbc31489 Optimize iterator adapters.
Specifically, make count, nth, and last call the corresponding methods
on the underlying iterator where possible. This way, if the underlying
iterator has an optimized count, nth, or last implementations (e.g.
slice::Iter), these methods will propagate these optimizations.

Additionally, change Skip::next to take advantage of a potentially
optimized nth method on the underlying iterator.
2015-05-05 14:17:23 -04:00
bors
1a60dc4fc4 Auto merge of #24737 - P1start:dst-cell, r=alexcrichton
This + DST coercions (#24619) would allow code like `Rc<RefCell<Box<Trait>>>` to be simplified to `Rc<RefCell<Trait>>`.
2015-05-03 17:22:09 +00:00
bors
f6574c5b04 Auto merge of #25006 - alexcrichton:unstable-indexing, r=aturon
These implementations were intended to be unstable, but currently the stability
attributes cannot handle a stable trait with an unstable `impl` block. This
commit also audits the rest of the standard library for explicitly-`#[unstable]`
impl blocks. No others were removed but some annotations were changed to
`#[stable]` as they're defacto stable anyway.

One particularly interesting `impl` marked `#[stable]` as part of this commit
is the `Add<&[T]>` impl for `Vec<T>`, which uses `push_all` and implicitly
clones all elements of the vector provided.

Closes #24791

[breaking-change]
2015-05-01 22:54:09 +00:00
P1start
57d8289754 Make UnsafeCell, RefCell, Mutex, and RwLock accept DSTs
This + DST coercions (#24619) would allow code like `Rc<RefCell<Box<Trait>>>` to
be simplified to `Rc<RefCell<Trait>>`.
2015-05-02 10:03:35 +12:00
Alex Crichton
b1976f1f6e std: Remove index notation on slice iterators
These implementations were intended to be unstable, but currently the stability
attributes cannot handle a stable trait with an unstable `impl` block. This
commit also audits the rest of the standard library for explicitly-`#[unstable]`
impl blocks. No others were removed but some annotations were changed to
`#[stable]` as they're defacto stable anyway.

One particularly interesting `impl` marked `#[stable]` as part of this commit
is the `Add<&[T]>` impl for `Vec<T>`, which uses `push_all` and implicitly
clones all elements of the vector provided.

Closes #24791
2015-05-01 10:40:46 -07:00
bors
613109db1b Auto merge of #24720 - critiqjo:stepby-sizehint, r=alexcrichton
`Iterator::size_hint` can be easily implemented for `StepBy`.
#23708
2015-05-01 16:42:19 +00:00
critiqjo
2a8fc9b02c iterator: Add StepBy::size_hint method
Fixes `Step::steps_between` implementations by integer types
to correctly handle `by != 1`.
2015-05-01 14:10:08 +05:30
Tamir Duberstein
f7947bc936 Unstub some tests 2015-04-28 21:23:28 -07:00
Tamir Duberstein
8073af7399 Tests need not be public 2015-04-28 21:22:58 -07:00
Tamir Duberstein
cd5abe7635 Remove unused variable 2015-04-28 21:22:06 -07:00
bors
c48b499ea3 Auto merge of #24888 - tamird:snapshot, r=alexcrichton
r? @alexcrichton cc @brson
2015-04-29 02:16:01 +00:00
Tamir Duberstein
69abc12b00 Register new snapshots 2015-04-28 17:23:45 -07:00
bors
c4b23aec4c Auto merge of #24865 - bluss:range-size, r=alexcrichton
core: Fix size_hint for signed integer `Range<T>` iterators

There was an overflow bug in .size_hint() for signed iterators, which
produced an hilariously incorrect size or an overflow panic.

Incorrect size is a serious bug since the iterators are marked
ExactSizeIterator. (And leads to abort() on (-1i8..127).collect() when
the collection tries to preallocate too much).

> (-1i8..127).size_hint()
(18446744073709551488, Some(18446744073709551488))

Bug found using quickcheck.

Fixes #24851
2015-04-29 00:15:22 +00:00
bors
97d4e76c20 Auto merge of #24701 - Stebalien:slice, r=alexcrichton
Instead of using the O(n) defaults, define O(1) shortcuts. I also copied (and slightly modified) the relevant tests from the iter tests into the slice tests just in case someone comes along and changes them in the future.

Partially implements  #24214.
2015-04-27 22:46:48 +00:00
Ulrik Sverdrup
95be21df47 core: Fix size_hint for signed integer Range<T> iterators
There was an overflow bug in .size_hint() for signed iterators, which
produced an hilariously incorrect size or an overflow panic.

Incorrect size is a serious bug since the iterators are marked
ExactSizeIterator. (And leads to abort() on (-1i8..127).collect() when
the collection tries to preallocate too much).

All signed range iterators were affected.

> (-1i8..127).size_hint()
(18446744073709551488, Some(18446744073709551488))

Bug found using quickcheck.

Fixes #24851
2015-04-27 21:14:43 +02:00
Johannes Oertel
07cc7d9960 Change name of unit test sub-module to "tests".
Changes the style guidelines regarding unit tests to recommend using a
sub-module named "tests" instead of "test" for unit tests as "test"
might clash with imports of libtest.
2015-04-24 23:06:41 +02:00
Steven Allen
de8c79a535 Implement O(1) slice::Iter methods.
Instead of using the O(n) defaults, define O(1) shortcuts.
2015-04-22 17:17:24 -04:00
Alex Crichton
a568a7f9f2 std: Bring back f32::from_str_radix as an unstable API
This API was exercised in a few tests and mirrors the `from_str_radix`
functionality of the integer types.
2015-04-21 15:23:54 -07:00
Piotr Czarnecki
13bc8afa4b Model lexer: Fix remaining issues 2015-04-21 12:02:12 +02:00