Skip to content

VecDeque::new allocates #68990

Description

@gnzlbg

I've noticed that VecDeque::new allocates. We don't guarantee that it doesn't, but this felt inconsistent with, e.g., Vec::new, for which we do guarantee that it does not allocate.

I'm not sure what the appropriate venue is for discussing this, but I think it would make sense to remove the surprise here and guarantee that VecDeque::new does not heap-allocate either.

cc @rust-lang/libs

Activity

  1. added
    C-enhancementCategory: An issue proposing an enhancement or a PR with one.
    T-libs-api[DEPRECATED; DO NOT USE]
    I-slowIssue: Problems and improvements with respect to performance of generated code.
    on Feb 9, 2020
  2. sfackler commented on Feb 9, 2020

    @sfackler
    Member
  3. zaharidichev commented on Feb 24, 2020

    @zaharidichev

    @sfackler Can I take a stab at that?

  4. sfackler commented on Feb 24, 2020

    @sfackler
    Member

    Sure

  5. zaharidichev commented on Mar 1, 2020

    @zaharidichev

    @sfackler, since this is my first take on an issue here, I wonder whether there is a mentor for this one (sorry not sure you are the right person to ask). Also, should I start with an RFC (or pre RFC) on that one. Seems the sensible approach to take is to use head and len() and avoid the requirement to always have at least one slot, even when empty (rust-lang/rfcs#1173 (comment)). Any suggestions arem ore than welcome :)

  6. sfackler commented on Mar 1, 2020

    @sfackler
    Member

    There's no need for an RFC for these kind of small behavior changes.

    Removing the one-empty slot requirement is one option, which may require adding a separately tracked length field. You could alternatively try to special-case the capacity 0 case, but it might be hard to ensure all of the corner cases are handled properly.

  7. lcnr commented on Mar 25, 2020

    @lcnr
    Contributor

    @zaharidichev are you still looking into this?

  8. whatisaphone commented on Mar 25, 2022

    @whatisaphone
    Contributor

    I'll just mention const fn since that was the keyword I first tried searching for, and it hasn't been mentioned here yet.

  9. Kobzol commented on Apr 1, 2022

    @Kobzol
    Member

    I started experimenting with this and it's quite annoying that if VecDeque is in a half-broken state (during refactoring), tests segfault, because VecDeque is probably used in the implementation of the test suite. Is there a way to say that "I want to run the test suite using stage0, but I want to test a modified implementation of std"?

  10. joboet commented on Dec 2, 2022

    @joboet
    Member

    This can be closed now that #102991 is merged.

  11. riking commented on Dec 2, 2022

    @riking

    Please link to the API Change Proposal where we lock in this guarantee, as well as zero-alloc From<Vec<T>>.

  12. SimonSapin commented on Dec 3, 2022

    @SimonSapin
    Contributor

    Per https://github.com/rust-lang/rust/pull/102991’s description there is no such guarantee (yet)

  13. Sp00ph commented on Dec 5, 2022

    @Sp00ph
    Member
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-collectionsArea: `std::collections`C-enhancementCategory: An issue proposing an enhancement or a PR with one.I-slowIssue: Problems and improvements with respect to performance of generated code.T-libs-api[DEPRECATED; DO NOT USE]

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions