Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Iterator::map_windows #82413

Commits on Jul 14, 2021

  1. Add Iterator::map_windows

    This method returns an iterator over mapped windows of the starting
    iterator. Adding the more straight-forward `Iterator::windows` is not
    easily possible right now as the items are stored in the iterator type,
    meaning the `next` call would return references to `self`. This is not
    allowed by the current `Iterator` trait design. This might change once
    GATs have landed.
    
    The idea has been brought up by @m-ou-se here:
    https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/Iterator.3A.3A.7Bpairwise.2C.20windows.7D/near/224587771
    LukasKalbertodt committed Jul 14, 2021
    Configuration menu
    Copy the full SHA
    84ee217 View commit details
    Browse the repository at this point in the history

Commits on Jul 15, 2021

  1. Configuration menu
    Copy the full SHA
    0cddbb0 View commit details
    Browse the repository at this point in the history
  2. Optimize Iterator::map_windows by using a buffer of size 2 * N

    This means one iteration is amortized O(1) instead of O(N). Note that
    `N` here refers to the array size (not the iterator length!) which is
    expected to be fairly small most of the time.
    
    Unfortunately, this optimization makes the implementation a lot more
    involved and requires lots more `unsafe` code. Therefore, quite a few
    tests were added to hopefully make sure everything is safe and sound.
    LukasKalbertodt committed Jul 15, 2021
    Configuration menu
    Copy the full SHA
    2c9dac0 View commit details
    Browse the repository at this point in the history