You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
`push` currently uses this line to reserve space in the vector:
```
self.grow(cmp::max(cap * 2, 1))
```
This risks overflowing `usize`. In practice this won't lead to any
bugs, because the capacity can't be larger than `isize::MAX` because of
invariants upheld in liballoc, but this is not easy to see.
Replacing this with `self.reserve(1)` is clearer, easier to reason about
safety (because `reserve` uses checked arithmetic), and will make it
easier to change the growth strategy in the future. (Currently
`reserve(1)` will grow to the next power of 2.)
This does not regress any of the `push` benchmarks. Marking `reserve`
as inline is necessary to prevent `insert` benchmarks from regressing
because of a change in the optimizer's inlining decisions there.
0 commit comments