about summary refs log tree commit diff
path: root/src/libcore/slice.rs
AgeCommit message (Collapse)AuthorLines
2015-07-09Auto merge of #26884 - dotdash:fast, r=alexcrichtonbors-4/+22
Exploiting the fact that getting the length of the slices is known, 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. Benchmarks comparing vectors with 100,000 elements: Before: ``` running 8 tests test eq1_u8 ... bench: 66,757 ns/iter (+/- 113) test eq2_u16 ... bench: 111,267 ns/iter (+/- 149) test eq3_u32 ... bench: 126,282 ns/iter (+/- 111) test eq4_u64 ... bench: 126,418 ns/iter (+/- 155) test ne1_u8 ... bench: 88,990 ns/iter (+/- 161) test ne2_u16 ... bench: 89,126 ns/iter (+/- 265) test ne3_u32 ... bench: 96,901 ns/iter (+/- 92) test ne4_u64 ... bench: 96,750 ns/iter (+/- 137) ``` After: ``` running 8 tests test eq1_u8 ... bench: 46,413 ns/iter (+/- 521) test eq2_u16 ... bench: 46,500 ns/iter (+/- 74) test eq3_u32 ... bench: 50,059 ns/iter (+/- 92) test eq4_u64 ... bench: 54,001 ns/iter (+/- 92) test ne1_u8 ... bench: 47,595 ns/iter (+/- 53) test ne2_u16 ... bench: 47,521 ns/iter (+/- 59) test ne3_u32 ... bench: 44,889 ns/iter (+/- 74) test ne4_u64 ... bench: 47,775 ns/iter (+/- 68) ```
2015-07-08Fix up unsafe section of slice::from_raw_partsSteve Klabnik-0/+4
Added a proper Unsafety header, as well as mentioning that the pointer shouldn't be null. Fixes #26552
2015-07-08Improve PartialEq for slicesBjörn Steinbrink-4/+22
Exploiting the fact that getting the length of the slices is known, 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. Benchmarks comparing vectors with 100,000 elements: Before: ``` running 8 tests test eq1_u8 ... bench: 66,757 ns/iter (+/- 113) test eq2_u16 ... bench: 111,267 ns/iter (+/- 149) test eq3_u32 ... bench: 126,282 ns/iter (+/- 111) test eq4_u64 ... bench: 126,418 ns/iter (+/- 155) test ne1_u8 ... bench: 88,990 ns/iter (+/- 161) test ne2_u16 ... bench: 89,126 ns/iter (+/- 265) test ne3_u32 ... bench: 96,901 ns/iter (+/- 92) test ne4_u64 ... bench: 96,750 ns/iter (+/- 137) ``` After: ``` running 8 tests test eq1_u8 ... bench: 46,413 ns/iter (+/- 521) test eq2_u16 ... bench: 46,500 ns/iter (+/- 74) test eq3_u32 ... bench: 50,059 ns/iter (+/- 92) test eq4_u64 ... bench: 54,001 ns/iter (+/- 92) test ne1_u8 ... bench: 47,595 ns/iter (+/- 53) test ne2_u16 ... bench: 47,521 ns/iter (+/- 59) test ne3_u32 ... bench: 44,889 ns/iter (+/- 74) test ne4_u64 ... bench: 47,775 ns/iter (+/- 68) ```
2015-06-17More test fixes and fallout of stability changesAlex Crichton-0/+4
2015-06-17std: Deprecate the IntSliceExt traitAlex Crichton-0/+4
This trait has seen very little usage and while safe, may not belong in the standard library.
2015-06-17core: Split apart the global `core` featureAlex Crichton-15/+12
This commit shards the broad `core` feature of the libcore library into finer grained features. This split groups together similar APIs and enables tracking each API separately, giving a better sense of where each feature is within the stabilization process. A few minor APIs were deprecated along the way: * Iterator::reverse_in_place * marker::NoCopy
2015-05-27Remove #[cfg(stage0)] items.Eduard Burtescu-13/+0
2015-05-16Auto merge of #25434 - dotdash:gep, r=alexcrichtonbors-45/+61
Using regular pointer arithmetic to iterate collections of zero-sized types doesn't work, because we'd get the same pointer all the time. Our current solution is to convert the pointer to an integer, add an offset and then convert back, but this inhibits certain optimizations. What we should do instead is to convert the pointer to one that points to an i8\*, and then use a LLVM GEP instructions without the inbounds flag to perform the pointer arithmetic. This allows to generate pointers that point outside allocated objects without causing UB (as long as you don't dereference them), and it wraps around using two's complement, i.e. it behaves exactly like the wrapping_* operations we're currently using, with the added benefit of LLVM being able to better optimize the resulting IR.
2015-05-15Allow for better optimizations of iterators for zero-sized typesBjörn Steinbrink-45/+61
Using regular pointer arithmetic to iterate collections of zero-sized types doesn't work, because we'd get the same pointer all the time. Our current solution is to convert the pointer to an integer, add an offset and then convert back, but this inhibits certain optimizations. What we should do instead is to convert the pointer to one that points to an i8*, and then use a LLVM GEP instructions without the inbounds flag to perform the pointer arithmetic. This allows to generate pointers that point outside allocated objects without causing UB (as long as you don't dereference them), and it wraps around using two's complement, i.e. it behaves exactly like the wrapping_* operations we're currently using, with the added benefit of LLVM being able to better optimize the resulting IR.
2015-05-15Fix major compile time regressionBjörn Steinbrink-16/+16
The assume intrinsic has a strong, negative impact on compile times, so we're currently only using it in places where LLVM can simplify it to nonnull metadata on a load intruction. Unfortunately a recent change that fixed invalid assume calls introduce new assume calls for which this simplification can not happen, leading to a massive regression in compile times in certain cases. Moving the assumptions from the middle of the function to the beginning allows the simplification to happen again, bringing compile times back to their old levels. Fixes #25393
2015-05-11Avoid returning a slice with a null pointer from Iter.as_slice()Kevin Ballard-19/+19
core::slice::Iter.ptr can be null when iterating a slice of zero-sized elements, but the pointer value used for the slice itself cannot. Handle this case by always returning a dummy pointer for slices of zero-sized elements.
2015-05-11Reintroduce non-null assumptions in core::slice iteratorsKevin Ballard-8/+16
The previous assumptions were not valid for slices of zero-sized elements.
2015-05-11Handle overflow properly in core::sliceKevin Ballard-39/+12
core::slice was originally written to tolerate overflow (notably, with slices of zero-sized elements), but it was never updated to use wrapping arithmetic when overflow traps were added. Also correctly handle the case of calling .nth() on an Iter with a zero-sized element type. The iterator was assuming that the pointer value of the returned reference was meaningful, but that's not true for zero-sized elements. Fixes #25016.
2015-05-07Auto merge of #25013 - pnkfelix:span_to_lines-oflo, r=huonwbors-6/+24
Guard against overflow in `codemap::span_to_lines`. (Revised/expanded version of PR #24976) Make `span_to_lines` to return a `Result`. In `diagnostic`, catch `Err` from `span_to_lines` and print `"(unprintable span)"` instead. ---- There a number of recent issues that report the bug here. See e.g. #24761 and #24954. This change *might* fix them. However, that is *not* its main goal. The main goals are: 1. Make it possible for callers to recover from an error here, and 2. Insert a more conservative check, in that we are also checking that the files match up. ---- As a drive-by, fix #24997 , which was causing my attempts to `make check-stage1` on an `--enable-debug` build to fail.
2015-05-04Avoid latent (harmless) overflow in core::slice.Felix S. Klock II-6/+24
This overflow does not cause any problems; it just causes errors to be signalled when compiling with `-C debug-assertions`. Fix #24997
2015-05-01std: Remove index notation on slice iteratorsAlex Crichton-110/+0
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-04-24Deduplicate slice iter offset/transmute code.Steven Allen-45/+41
2015-04-22Address comments.Steven Allen-42/+46
1. Use next_back for last. 2. Use slices for computing nth. It might be possible to use the same code for both the mut/const case but I don't know how that will play with compiler optimizations.
2015-04-22Implement O(1) slice::Iter methods.Steven Allen-0/+54
Instead of using the O(n) defaults, define O(1) shortcuts.
2015-04-21std: Remove deprecated/unstable num functionalityAlex Crichton-1/+1
This commit removes all the old casting/generic traits from `std::num` that are no longer in use by the standard library. This additionally removes the old `strconv` module which has not seen much use in quite a long time. All generic functionality has been supplanted with traits in the `num` crate and the `strconv` module is supplanted with the [rust-strconv crate][rust-strconv]. [rust-strconv]: https://github.com/lifthrasiir/rust-strconv This is a breaking change due to the removal of these deprecated crates, and the alternative crates are listed above. [breaking-change]
2015-04-21std: Remove deprecated AsOsStr/Str/AsSlice traitsAlex Crichton-31/+0
Cleaning out more deprecated items
2015-04-14Positive case of `len()` -> `is_empty()`Tamir Duberstein-9/+9
`s/(?<!\{ self)(?<=\.)len\(\) == 0/is_empty()/g`
2015-04-07std: Hide facade extension traits in docsAlex Crichton-0/+1
These traits are currently all just unstable parts of the facade which are implementation details for primitives further up the facade. This may make it more difficult to find what set of methods you get if only linking to libcore, but for now that's also unstable behavior. Closes #22025
2015-04-01std: Changing the meaning of the count to splitnAlex Crichton-6/+8
This commit is an implementation of [RFC 979][rfc] which changes the meaning of the count parameter to the `splitn` function on strings and slices. The parameter now means the number of items that are returned from the iterator, not the number of splits that are made. [rfc]: https://github.com/rust-lang/rfcs/pull/979 Closes #23911 [breaking-change]
2015-03-31std: Clean out #[deprecated] APIsAlex Crichton-58/+0
This commit cleans out a large amount of deprecated APIs from the standard library and some of the facade crates as well, updating all users in the compiler and in tests as it goes along.
2015-03-30std: Standardize (input, output) param orderingsAlex Crichton-3/+3
This functions swaps the order of arguments to a few functions that previously took (output, input) parameters, but now take (input, output) parameters (in that order). The affected functions are: * ptr::copy * ptr::copy_nonoverlapping * slice::bytes::copy_memory * intrinsics::copy * intrinsics::copy_nonoverlapping Closes #22890 [breaking-change]
2015-03-27rollup merge of #23738: alexcrichton/snapshotsAlex Crichton-185/+0
Conflicts: src/libcollections/vec.rs
2015-03-26Register new snapshotsAlex Crichton-185/+0
2015-03-26Deprecate as_mut_slice methodsErick Tryzelaar-0/+6
This is technically a breaking change as it deprecates and unstables some previously stable apis that were missed in the last round of deprecations. [breaking change]
2015-03-23rollup merge of #23598: brson/gateAlex Crichton-0/+1
Conflicts: src/compiletest/compiletest.rs src/libcollections/lib.rs src/librustc_back/lib.rs src/libserialize/lib.rs src/libstd/lib.rs src/libtest/lib.rs src/test/run-make/rustdoc-default-impl/foo.rs src/test/run-pass/env-home-dir.rs
2015-03-23rollup merge of #23601: nikomatsakis/by-value-indexAlex Crichton-0/+201
This is a [breaking-change]. When indexing a generic map (hashmap, etc) using the `[]` operator, it is now necessary to borrow explicitly, so change `map[key]` to `map[&key]` (consistent with the `get` routine). However, indexing of string-valued maps with constant strings can now be written `map["abc"]`. r? @japaric cc @aturon @Gankro
2015-03-23Add generic conversion traitsAaron Turon-0/+5
This commit: * Introduces `std::convert`, providing an implementation of RFC 529. * Deprecates the `AsPath`, `AsOsStr`, and `IntoBytes` traits, all in favor of the corresponding generic conversion traits. Consequently, various IO APIs now take `AsRef<Path>` rather than `AsPath`, and so on. Since the types provided by `std` implement both traits, this should cause relatively little breakage. * Deprecates many `from_foo` constructors in favor of `from`. * Changes `PathBuf::new` to take no argument (creating an empty buffer, as per convention). The previous behavior is now available as `PathBuf::from`. * De-stabilizes `IntoCow`. It's not clear whether we need this separate trait. Closes #22751 Closes #14433 [breaking-change]
2015-03-23Add #![feature] attributes to doctestsBrian Anderson-0/+1
2015-03-23Adjust Index/IndexMut impls. For generic collections, we takeNiko Matsakis-0/+201
references. For collections whose keys are integers, we take both references and by-value.
2015-03-18Register new snapshotsAlex Crichton-2/+0
2015-03-17Rollup merge of #23329 - jbcrail:rm-syntax-highlight, r=sanxiynManish Goregaokar-2/+2
As suggested by @steveklabnik in #23254, I removed the redundant Rust syntax highlighting from the documentation.
2015-03-16impl<T> *const T, impl<T> *mut TJorge Aparicio-0/+1
2015-03-13Remove explicit syntax highlight from docs.Joseph Crail-2/+2
2015-03-13slice::from_raw_parts is preferred over transmuting a fresh raw::SliceOliver Schneider-14/+27
2015-03-12Rollup merge of #23263 - alexcrichton:stabilize-from-raw-parts, r=brsonManish Goregaokar-2/+2
These new APIs have had some time to bake now, and no pressing issues have come up so they should be ok for stabilizing. Specifically, these two APIs were stabilized: * `slice::from_raw_parts` * `slice::from_raw_parts_mut`
2015-03-11Example -> ExamplesSteve Klabnik-2/+2
This brings comments in line with https://github.com/rust-lang/rfcs/blob/master/text/0505-api-comment-conventions.md#using-markdown
2015-03-10std: Stabilize slice::from_raw_partsAlex Crichton-2/+2
These new APIs have had some time to bake now, and no pressing issues have come up so they should be ok for stabilizing. Specifically, these two APIs were stabilized: * `slice::from_raw_parts` * `slice::from_raw_parts_mut`
2015-03-03Rollup merge of #22988 - dcrewi:slice-swap-inline, r=alexcrichtonManish Goregaokar-0/+1
2015-03-02Slice::swap should be inlineableDavid Creswick-0/+1
2015-03-02Manual Clone for Windows/Chunks.Huon Wilson-2/+22
`#[derive(Clone)]` unnecessarily requires the element type to also be `Clone`.
2015-02-28Auto merge of #22669 - dotdash:fast_slice_iter, r=huonwbors-0/+3
This adds the assume() calls back that got lost when rebasing #21886.
2015-02-26Send/Sync audit for libcollectionsEdward Wang-1/+6
In the process, also replaces a raw mutable pointers with Unique to spell out the ownership semantics. cc #22709
2015-02-24std: Stabilize some `ptr` functionsAlex Crichton-4/+4
Specifically, the following actions were taken: * The `copy_memory` and `copy_nonoverlapping_memory` functions to drop the `_memory` suffix (as it's implied by the functionality). Both functions are now marked as `#[stable]`. * The `set_memory` function was renamed to `write_bytes` and is now stable. * The `zero_memory` function is now deprecated in favor of `write_bytes` directly. * The `Unique` pointer type is now behind its own feature gate called `unique` to facilitate future stabilization. * All type parameters now are `T: ?Sized` wherever possible and new clauses were added to the `offset` functions to require that the type is sized. [breaking-change]
2015-02-22Eliminate more excessive null-checks from slice iteratorsBjörn Steinbrink-0/+3
This adds the assume() calls back that got lost when rebasing #21886.
2015-02-20Refactored code into Searcher traits with naive implementationsMarvin Löbel-0/+4
Made the family of Split iterators use the Pattern API Renamed the Matcher traits into Searcher