about summary refs log tree commit diff
path: root/src/libcore
AgeCommit message (Collapse)AuthorLines
2015-09-16Remove boundary checks in slice comparison operatorsAndrea Canciani-2/+6
In order to get rid of all range checks, the compiler needs to explicitly see that the slices it iterates over are as long as the loop variable upper bound. This further improves the performance of slice comparison: ``` test u8_cmp ... bench: 4,761 ns/iter (+/- 1,203) test u8_lt ... bench: 4,579 ns/iter (+/- 649) test u8_partial_cmp ... bench: 4,768 ns/iter (+/- 761) test u16_cmp ... bench: 4,607 ns/iter (+/- 580) test u16_lt ... bench: 4,681 ns/iter (+/- 567) test u16_partial_cmp ... bench: 4,607 ns/iter (+/- 967) test u32_cmp ... bench: 4,448 ns/iter (+/- 891) test u32_lt ... bench: 4,546 ns/iter (+/- 992) test u32_partial_cmp ... bench: 4,415 ns/iter (+/- 646) test u64_cmp ... bench: 4,380 ns/iter (+/- 1,184) test u64_lt ... bench: 5,684 ns/iter (+/- 602) test u64_partial_cmp ... bench: 4,663 ns/iter (+/- 1,158) ```
2015-09-16Reuse cmp in totally ordered typesAndrea Canciani-3/+1
Instead of manually defining it, `partial_cmp` can simply wrap the result of `cmp` for totally ordered types.
2015-09-16Improve PartialOrd for slicesAndrea Canciani-18/+21
Reusing the same idea as in #26884, we can exploit the fact that the length of slices is known, hence we can use a counted loop instead of iterators, which means that we only need a single counter, instead of having to increment and check one pointer for each iterator. Using the generic implementation of the boolean comparison operators (`lt`, `le`, `gt`, `ge`) provides further speedup for simple types. This happens because the loop scans elements checking for equality and dispatches to element comparison or length comparison depending on the result of the prefix comparison. ``` test u8_cmp ... bench: 14,043 ns/iter (+/- 1,732) test u8_lt ... bench: 16,156 ns/iter (+/- 1,864) test u8_partial_cmp ... bench: 16,250 ns/iter (+/- 2,608) test u16_cmp ... bench: 15,764 ns/iter (+/- 1,420) test u16_lt ... bench: 19,833 ns/iter (+/- 2,826) test u16_partial_cmp ... bench: 19,811 ns/iter (+/- 2,240) test u32_cmp ... bench: 15,792 ns/iter (+/- 3,409) test u32_lt ... bench: 18,577 ns/iter (+/- 2,075) test u32_partial_cmp ... bench: 18,603 ns/iter (+/- 5,666) test u64_cmp ... bench: 16,337 ns/iter (+/- 2,511) test u64_lt ... bench: 18,074 ns/iter (+/- 7,914) test u64_partial_cmp ... bench: 17,909 ns/iter (+/- 1,105) ``` ``` test u8_cmp ... bench: 6,511 ns/iter (+/- 982) test u8_lt ... bench: 6,671 ns/iter (+/- 919) test u8_partial_cmp ... bench: 7,118 ns/iter (+/- 1,623) test u16_cmp ... bench: 6,689 ns/iter (+/- 921) test u16_lt ... bench: 6,712 ns/iter (+/- 947) test u16_partial_cmp ... bench: 6,725 ns/iter (+/- 780) test u32_cmp ... bench: 7,704 ns/iter (+/- 1,294) test u32_lt ... bench: 7,611 ns/iter (+/- 3,062) test u32_partial_cmp ... bench: 7,640 ns/iter (+/- 1,149) test u64_cmp ... bench: 7,517 ns/iter (+/- 2,164) test u64_lt ... bench: 7,579 ns/iter (+/- 1,048) test u64_partial_cmp ... bench: 7,629 ns/iter (+/- 1,195) ```
2015-09-16Specialize `PartialOrd` for totally ordered primitive typesAndrea Canciani-4/+22
Knowing the result of equality comparison can enable additional optimizations in LLVM. Additionally, this makes it obvious that `partial_cmp` on totally ordered types cannot return `None`.
2015-09-16Simplify sample code for {Option, Result}::iter_mutAdolfo Ochagavía-2/+2
Fixes #28431
2015-09-15Add a comment that the `Atomic*` are all implicitly `Send`Tobias Bucher-0/+3
2015-09-15Auto merge of #28268 - petrochenkov:fnptr, r=alexcrichtonbors-69/+71
Closes https://github.com/rust-lang/rust/issues/26082
2015-09-14Auto merge of #28248 - PeterReid:master, r=alexcrichtonbors-15/+11
Overflows in integer pow() computations would be missed if they preceded a 0 bit of the exponent being processed. This made calls such as 2i32.pow(1024) not trigger an overflow. Fixes #28012
2015-09-14Auto merge of #28358 - dotdash:nounwind, r=alexcrichtonbors-0/+2
This allows to skip the codegen for all the unneeded landing pads, reducing code size across the board by about 2-5%, depending on the crate. Compile times seem to be pretty unaffected though :-/
2015-09-14Mark all extern functions as nounwindBjörn Steinbrink-0/+2
Unwinding across an FFI boundary is undefined behaviour, so we can mark all external function as nounwind. The obvious exception are those functions that actually perform the unwinding.
2015-09-14Auto merge of #28368 - lfairy:write-impl, r=alexcrichtonbors-0/+15
There is already a corresponding impl for `std::io::Write`. This change will make the two traits more consistent.
2015-09-13Auto merge of #28339 - alexcrichton:stabilize-1.4, r=aturonbors-8/+11
The FCP is coming to a close and 1.4 is coming out soon, so this brings in the libs team decision for all library features this cycle. Stabilized APIs: * `<Box<str>>::into_string` * `Arc::downgrade` * `Arc::get_mut` * `Arc::make_mut` * `Arc::try_unwrap` * `Box::from_raw` * `Box::into_raw` * `CStr::to_str` * `CStr::to_string_lossy` * `CString::from_raw` * `CString::into_raw` * `IntoRawFd::into_raw_fd` * `IntoRawFd` * `IntoRawHandle::into_raw_handle` * `IntoRawHandle` * `IntoRawSocket::into_raw_socket` * `IntoRawSocket` * `Rc::downgrade` * `Rc::get_mut` * `Rc::make_mut` * `Rc::try_unwrap` * `Result::expect` * `String::into_boxed_slice` * `TcpSocket::read_timeout` * `TcpSocket::set_read_timeout` * `TcpSocket::set_write_timeout` * `TcpSocket::write_timeout` * `UdpSocket::read_timeout` * `UdpSocket::set_read_timeout` * `UdpSocket::set_write_timeout` * `UdpSocket::write_timeout` * `Vec::append` * `Vec::split_off` * `VecDeque::append` * `VecDeque::retain` * `VecDeque::split_off` * `rc::Weak::upgrade` * `rc::Weak` * `slice::Iter::as_slice` * `slice::IterMut::into_slice` * `str::CharIndices::as_str` * `str::Chars::as_str` * `str::split_at_mut` * `str::split_at` * `sync::Weak::upgrade` * `sync::Weak` * `thread::park_timeout` * `thread::sleep` Deprecated APIs * `BTreeMap::with_b` * `BTreeSet::with_b` * `Option::as_mut_slice` * `Option::as_slice` * `Result::as_mut_slice` * `Result::as_slice` * `f32::from_str_radix` * `f64::from_str_radix` Closes #27277 Closes #27718 Closes #27736 Closes #27764 Closes #27765 Closes #27766 Closes #27767 Closes #27768 Closes #27769 Closes #27771 Closes #27773 Closes #27775 Closes #27776 Closes #27785 Closes #27792 Closes #27795 Closes #27797
2015-09-13Implement more traits for function pointersVadim Petrochenkov-69/+71
2015-09-13Add a blanket impl for &mut std::fmt::WriteChris Wong-0/+15
There is already a corresponding impl for `std::io::Write`. This change will make the two traits more consistent.
2015-09-12Stop a private method on `SipHasher` from shadowing `Hasher::write`Tobias Bucher-8/+3
2015-09-11std: Stabilize/deprecate features for 1.4Alex Crichton-8/+11
The FCP is coming to a close and 1.4 is coming out soon, so this brings in the libs team decision for all library features this cycle. Stabilized APIs: * `<Box<str>>::into_string` * `Arc::downgrade` * `Arc::get_mut` * `Arc::make_mut` * `Arc::try_unwrap` * `Box::from_raw` * `Box::into_raw` * `CStr::to_str` * `CStr::to_string_lossy` * `CString::from_raw` * `CString::into_raw` * `IntoRawFd::into_raw_fd` * `IntoRawFd` * `IntoRawHandle::into_raw_handle` * `IntoRawHandle` * `IntoRawSocket::into_raw_socket` * `IntoRawSocket` * `Rc::downgrade` * `Rc::get_mut` * `Rc::make_mut` * `Rc::try_unwrap` * `Result::expect` * `String::into_boxed_slice` * `TcpSocket::read_timeout` * `TcpSocket::set_read_timeout` * `TcpSocket::set_write_timeout` * `TcpSocket::write_timeout` * `UdpSocket::read_timeout` * `UdpSocket::set_read_timeout` * `UdpSocket::set_write_timeout` * `UdpSocket::write_timeout` * `Vec::append` * `Vec::split_off` * `VecDeque::append` * `VecDeque::retain` * `VecDeque::split_off` * `rc::Weak::upgrade` * `rc::Weak` * `slice::Iter::as_slice` * `slice::IterMut::into_slice` * `str::CharIndices::as_str` * `str::Chars::as_str` * `str::split_at_mut` * `str::split_at` * `sync::Weak::upgrade` * `sync::Weak` * `thread::park_timeout` * `thread::sleep` Deprecated APIs * `BTreeMap::with_b` * `BTreeSet::with_b` * `Option::as_mut_slice` * `Option::as_slice` * `Result::as_mut_slice` * `Result::as_slice` * `f32::from_str_radix` * `f64::from_str_radix` Closes #27277 Closes #27718 Closes #27736 Closes #27764 Closes #27765 Closes #27766 Closes #27767 Closes #27768 Closes #27769 Closes #27771 Closes #27773 Closes #27775 Closes #27776 Closes #27785 Closes #27792 Closes #27795 Closes #27797
2015-09-10Optimize string comparison by using memcmpErick Tryzelaar-15/+20
llvm seems to be having some trouble optimizing the iterator-based string comparsion method into some equivalent to memcmp. This explicitly calls out to the memcmp intrinisic in order to allow llvm to generate better code. In some manual benchmarking, this memcmp-based approach is 20 times faster than the iterator approach.
2015-09-08some more clippy-based improvementsAndre Bogus-3/+3
2015-09-07Use unsafe more idiomaticallySteve Klabnik-1/+3
Generally, including everything that makes an unsafe block safe in the block is good style. Since the assert! is what makes this safe, it should go inside the block. I also added a few bits of whitespace.
2015-09-04Fix for issue #28012: pow overflow inconsistencyPeter Reid-15/+11
Overflows in integer pow() computations would be missed if they preceded a 0 bit of the exponent being processed. This made calls such as 2i32.pow(1024) not trigger an overflow.
2015-09-04Auto merge of #28197 - petrochenkov:borrow, r=alexcrichtonbors-0/+15
2015-09-04Auto merge of #28119 - nagisa:bytesderef, r=alexcrichtonbors-30/+3
2015-09-03std: Account for CRLF in {str, BufRead}::linesAlex Crichton-4/+10
This commit is an implementation of [RFC 1212][rfc] which tweaks the behavior of the `str::lines` and `BufRead::lines` iterators. Both iterators now account for `\r\n` sequences in addition to `\n`, allowing for less surprising behavior across platforms (especially in the `BufRead` case). Splitting *only* on the `\n` character can still be achieved with `split('\n')` in both cases. The `str::lines_any` function is also now deprecated as `str::lines` is a drop-in replacement for it. [rfc]: https://github.com/rust-lang/rfcs/blob/master/text/1212-line-endings.md Closes #28032
2015-09-04Rollup merge of #28191 - llogiq:iter, r=ManishearthManish Goregaokar-6/+6
Nothing too big, a few needless returns and a few closures eliminated (the latter may improve performance in some cases, at least compilation should be a bit faster).
2015-09-04Rollup merge of #28188 - Manishearth:elide-core, r=alexcrichtonManish Goregaokar-72/+72
Makes things more greppable. This change was made automatically by clippy + bash scripts, though I will run test passes, please review carefully.
2015-09-03Implement `Borrow` for fixed-size arraysVadim Petrochenkov-0/+15
2015-09-03take mapped function by mutable referencellogiq-4/+4
2015-09-03Elide lifetimes in libcoreManish Goregaokar-72/+72
2015-09-03clippy improvements to iteratorsllogiq-6/+6
2015-09-03Make `null()` and `null_mut()` const functionsVadim Petrochenkov-4/+4
2015-09-01Auto merge of #28088 - tbu-:pr_fixed_size_array, r=alexcrichtonbors-12/+12
2015-08-31Change explicit BytesDeref impl into Cloned iteratorSimonas Kazlauskas-30/+3
2015-08-31Auto merge of #28101 - ijks:24214-str-bytes, r=alexcrichtonbors-0/+15
Specifically, `count`, `last`, and `nth` are implemented to use the methods of the underlying slice iterator. Partially closes #24214.
2015-08-31Implement `FixedSizeArray` for all fixed size arraysTobias Bucher-12/+12
Do so by using the fact that fixed size arrays (like `[u8; 8]` can be coerced to slices `&[u8]`, this is expressed through the trait `Unsize<[T]>` that all fixed size arrays implement.
2015-08-30Add overrides to iterator methods for `str::Bytes`Daan Rijks-0/+15
Specifically, `count`, `last`, and `nth` are implemented to use the methods of the underlying slice iterator. Partially closes #24214.
2015-08-28Add .as_str() to str::Chars and str::CharIndices. See #27775.Simon Sapin-0/+24
2015-08-28Auto merge of #28038 - durka:grep-unstable-issue-refs, r=alexcrichtonbors-2/+4
After submitting #28031, I ran a [script](https://gist.github.com/durka/a5243440697c780f669b) on the rest of src/ and found some anomalies. In this PR are the fixes that I thought were obvious (but I might be wrong!). The others I've submitted in issue #28037.
2015-08-28Rollup merge of #28048 - steveklabnik:doc_unimplemented, r=alexcrichtonManish Goregaokar-0/+45
2015-08-28Rollup merge of #28039 - birkenfeld:option_result_ref_intoiter, r=alexcrichtonManish Goregaokar-0/+40
Fixes #27996. Does this need any `#[stable]`/`#[unstable]` attributes?
2015-08-27Auto merge of #28031 - durka:patch-6, r=alexcrichtonbors-1/+1
It was pointing at the issue for `placement_new_protocol`.
2015-08-27Some extra examples for the unimplemented! macroSteve Klabnik-0/+45
2015-08-27core: Implement IntoIterator for Option and Result referencesGeorg Brandl-0/+40
Fixes #27996.
2015-08-27fix some more unstable issue annotationsAlex Burka-2/+4
2015-08-27Auto merge of #28016 - ranma42:mini-rem-in-core, r=alexcrichtonbors-2/+24
The implementation of the remainder operation belongs to librustc_trans, but it is also stubbed out in libcore in order to expose it as a trait on primitive types. Instead of exposing some implementation details (like the upcast to `f64` in MSVC), use a minimal implementation just like that of the `Div` trait.
2015-08-27Auto merge of #28028 - tshepang:add-size_hint-example, r=alexcrichtonbors-0/+7
2015-08-27Auto merge of #28027 - tshepang:improve-sentence, r=alexcrichtonbors-1/+1
2015-08-27Restore removed code and mark it for usage in stage0Andrea Canciani-0/+41
The old code is temporarily needed in order to keep the MSVC build working. It should be possible to remove this code after the bootstrap compiler is updated to contain the MSVC workaround from #27875.
2015-08-27Auto merge of #27975 - sfackler:iter-order-methods, r=aturonbors-96/+219
This does cause some breakage due to deficiencies in resolve - `path::Components` is both an `Iterator` and implements `Eq`, `Ord`, etc. If one calls e.g. `partial_cmp` on a `Components` and passes a `&Components` intending to target the `PartialOrd` impl, the compiler will select the `partial_cmp` from `Iterator` and then error out. I doubt anyone will run into breakage from `Components` specifically, but we should see if there are third party types that will run into issues. `iter::order::equals` wasn't moved to `Iterator` since it's exactly the same as `iter::order::eq` but with an `Eq` instead of `PartialEq` bound, which doensn't seem very useful. I also updated `le`, `gt`, etc to use `partial_cmp` which lets us drop the extra `PartialEq` bound. cc #27737 r? @alexcrichton
2015-08-26Make iter::order functions into methods on IteratorSteven Fackler-96/+219
This does cause some breakage due to deficiencies in resolve - `path::Components` is both an `Iterator` and implements `Eq`, `Ord`, etc. If one calls e.g. `partial_cmp` on a `Components` and passes a `&Components` intending to target the `PartialOrd` impl, the compiler will select the `partial_cmp` from `Iterator` and then error out. I doubt anyone will run into breakage from `Components` specifically, but we should see if there are third party types that will run into issues. `iter::order::equals` wasn't moved to `Iterator` since it's exactly the same as `iter::order::eq` but with an `Eq` instead of `PartialEq` bound, which doensn't seem very useful. I also updated `le`, `gt`, etc to use `partial_cmp` which lets us drop the extra `PartialEq` bound. cc #27737
2015-08-27Auto merge of #27808 - SimonSapin:utf16decoder, r=alexcrichtonbors-0/+110
* Rename `Utf16Items` to `Utf16Decoder`. "Items" is meaningless. * Generalize it to any `u16` iterator, not just `[u16].iter()` * Make it yield `Result` instead of a custom `Utf16Item` enum that was isomorphic to `Result`. This enable using the `FromIterator for Result` impl. * Replace `Utf16Item::to_char_lossy` with a `Utf16Decoder::lossy` iterator adaptor. This is a [breaking change], but only for users of the unstable `rustc_unicode` crate. I’d like this functionality to be stabilized and re-exported in `std` eventually, as the "low-level equivalent" of `String::from_utf16` and `String::from_utf16_lossy` like #27784 is the low-level equivalent of #27714. CC @aturon, @alexcrichton