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

Make TypedArena::alloc_from_iter like DroplessArena::alloc_from_iter. #116327

Closed
wants to merge 2 commits into from

Commits on Oct 2, 2023

  1. Make TypedArena::alloc_from_iter like `DroplessArena::alloc_from_it…

    …er`.
    
    `TypedArena` and `DroplessArena` both have an `alloc_from_impl` function, but
    they are implemented in completely different ways.
    
    - `TypedArena` uses the `IterExt` trait, which by default (a) collects the
      iterator's elements into a temporary `SmallVec`, (b) allocates memory, and
      (c) bulk-copies (and consumes) the elements into the arena memory. There are
      also specializations for `array::IntoIter`/`Vec`/`SmallVec` that
      avoid copying into a temporary `SmallVec`.
    
    - `DroplessArena` has two ways of doing it:
      - For known-sized iterators, it allocates memory and then copies items
        in one at a time.
     -  Otherwise, it works much like the default case for `TypedArena`, collecting
        into a temporary `SmallVec` and then bulk-copying.
    
    Performance-wise, they are very similar. `DroplessArena` is a little
    more general, because it automatically works with any known-sized
    iterator type, while `TypedArena`'s approach requires specialization on
    a per-type basis.
    
    This commit removes `IterExt` and moves
    `DroplessArena::{write,alloc}_from_iter` so they can be used from
    `TypedArena`. This reduces the amount of code in this file.
    nnethercote committed Oct 2, 2023
    Configuration menu
    Copy the full SHA
    56a99fa View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    2c40e82 View commit details
    Browse the repository at this point in the history