about summary refs log tree commit diff
path: root/library/core/src/slice/iter
AgeCommit message (Collapse)AuthorLines
2025-02-23rename sub_ptr 😅bendn-1/+1
2025-02-14Add real safety commentsScott McMurray-1/+14
2025-02-14Go back to `Some` instead of transmuting to it.Scott McMurray-1/+1
This adds a few more statements to `next`, but optimizes better in the loops (saving 2 blocks in `forward_loop`, for example)
2025-02-14Save another BB by using `SubUnchecked` instead of a call to `arith_offset`Scott McMurray-4/+4
Probably reasonable anyway since it more obviously drops provenance.
2025-02-14Simplify `slice::Iter::next` enough that it inlinesScott McMurray-6/+16
2025-02-12`transmute` should also assume non-null pointersScott McMurray-1/+1
Previously it only did integer-ABI things, but this way it does data pointers too. That gives more information in general to the backend, and allows slightly simplifying one of the helpers in slice iterators.
2024-09-25Use `&raw` in the standard libraryJosh Stone-3/+3
Since the stabilization in #127679 has reached stage0, 1.82-beta, we can start using `&raw` freely, and even the soft-deprecated `ptr::addr_of!` and `ptr::addr_of_mut!` can stop allowing the unstable feature. I intentionally did not change any documentation or tests, but the rest of those macro uses are all now using `&raw const` or `&raw mut` in the standard library.
2024-06-19Shrink some slice iterator MIRScott McMurray-2/+4
2024-04-25Convert some iter macros to normal functionsScott McMurray-21/+20
With all the MIR optimization changes that have happened since these were written, let's see if they still actually matter.
2024-02-15Replace `NonZero::<_>::new` with `NonZero::new`.Markus Reiter-2/+2
2024-02-15Use generic `NonZero` internally.Markus Reiter-4/+4
2024-01-13libs: use `assert_unchecked` instead of intrinsicjoboet-2/+2
2023-07-20Get `!nonnull` metadata consistently in slice iterators, without needing ↵Scott McMurray-67/+79
`assume`s
2023-06-14use indexed loop instead of ptr bumpingThe 8472-10/+20
this seems to produce less IR
2023-06-12optimize slice::Iter::foldThe 8472-0/+23
2023-05-10Simplify the implementation of iterators over slices of ZSTsScott McMurray-24/+33
Currently, slice iterators over ZSTs store `end = start.wrapping_byte_add(len)`. That's slightly convenient for `is_empty`, but kinda annoying for pretty much everything else -- see bugs like 42789, for example. This PR instead changes it to just `end = ptr::invalid(len)` instead. That's easier to think about (IMHO, at least) as well as easier to represent.
2023-05-06Remove some `assume`s from slice iterators that don't do anythingScott McMurray-10/+6
2023-04-28replace version placeholdersPietro Albini-1/+1
2023-04-21More `IS_ZST` in `library`Scott McMurray-1/+1
I noticed that `post_inc_start` and `pre_dec_end` were doing this check in different ways https://github.com/rust-lang/rust/blob/d19b64fb54391b64ce99981577c67c93ac2a9ffa/library/core/src/slice/iter/macros.rs#L76-L93 so started making this PR, then added a few more I found since I was already making changes anyway.
2023-03-27replace advance_by returning usize with Result<(), NonZeroUsize>The 8472-4/+4
2023-03-27Change advance(_back)_by to return `usize` instead of `Result<(), usize>`The 8472-4/+4
A successful advance is now signalled by returning `0` and other values now represent the remaining number of steps that couldn't be advanced as opposed to the amount of steps that have been advanced during a partial advance_by. This simplifies adapters a bit, replacing some `match`/`if` with arithmetic. Whether this is beneficial overall depends on whether `advance_by` is mostly used as a building-block for other iterator methods and adapters or whether we also see uses by users where `Result` might be more useful.
2023-02-28rewrite iterator `Default` tests as doctestsThe 8472-0/+7
2023-02-28Implement Default for some alloc/core iteratorsThe 8472-0/+7
This way one can `mem::take()` them out of structs or #[derive(Default)] on structs containing them. These changes will be insta-stable.
2023-02-04Allow canonicalizing the `array::map` loop in trusted casesScott McMurray-0/+9
2023-01-15replace manual ptr arithmetic with ptr_subThe 8472-16/+6
2023-01-14Remove various double spaces in source comments.André Vennberg-1/+1
2022-09-22Make ZST checks in core/alloc more readableScott McMurray-4/+4
There's a bunch of these checks because of special handing for ZSTs in various unsafe implementations of stuff. This lets them be `T::IS_ZST` instead of `mem::size_of::<T>() == 0` every time, making them both more readable and more terse. *Not* proposed for stabilization at this time. Would be `pub(crate)` except `alloc` wants to use it too. (And while it doesn't matter now, if we ever get something like 85836 making it a const can help codegen be simpler.)
2022-09-04remove some integer casts from slice iterMaybe Waffle-9/+9
2022-08-23Make use of `[wrapping_]byte_{add,sub}`Maybe Waffle-1/+1
...replacing `.cast().wrapping_offset().cast()` & similar code.
2022-05-08Warn on unused doc(hidden) on trait impl itemsLeón Orell Valerian Liehr-1/+0
2022-05-02This aligns the inline attributes of existing `__iterator_get_unchecked` ↵The 8472-0/+1
with those of `next()` on adapters that have both. It improves the performance of iterators using unchecked access when building in incremental mode (due to the larger CGU count?). It might negatively affect incremental compile times for better runtime results, but considering that the equivalent `next()` implementations also are `#[inline]` and usually are more complex this should be ok. ``` ./x.py bench library/core -i --stage 0 --test-args bench_trusted_random_access OLD: 119,172 ns/iter NEW: 17,714 ns/iter ```
2022-03-29cleanup some of the less terrifying library codeAria Beingessner-1/+1
2022-03-29Make the stdlib largely conform to strict provenance.Aria Beingessner-2/+2
Some things like the unwinders and system APIs are not fully conformant, this only covers a lot of low-hanging fruit.
2021-08-03#[inline] slice::advance_byThe8472-2/+3
2021-07-22Fix whitespaceTim Vermeulen-2/+1
Co-authored-by: Ivan Tham <pickfire@riseup.net>
2021-07-22Add testsTim Vermeulen-2/+2
2021-07-22Implement slice::{Iter, IterMut}::{advance_by, advance_back_by}Tim Vermeulen-0/+16
Co-authored-by: The8472 <git@infinite-source.de>
2020-09-25Rename Iterator::get_uncheckedMatthew Jasper-1/+1
It's possible for method resolution to pick this method over a lower priority stable method, causing compilation errors. Since this method is permanently unstable, give it a name that is very unlikely to be used in user code.
2020-09-14Move iterator impls to a new moduleLzu Tao-0/+407