rust/src/liballoc
bors 64b0277643 Auto merge of #29454 - stepancheg:vec-reserve, r=bluss
Before this patch `reserve` function allocated twice as requested
amount elements (not twice as capacity).  It leaded to unnecessary
excessive memory usage in scenarios like this:

```
let mut v = Vec::new();
v.push(17);
v.extend(0..10);
println!("{}", v.capacity());
```

`Vec` allocated 22 elements, while it could allocate just 11.

`reserve` function must have a property of keeping `push` operation
cost (which calls `reserve`) `O(1)`. To achieve this `reserve` must
exponentialy grow its capacity when it does reallocation.

There's better strategy to implement `reserve`:

```
let new_capacity = max(current_capacity * 2, requested_capacity);
```

This strategy still guarantees that capacity grows at `O(1)` with
`reserve`, and fixes the issue with `extend`.

Patch imlpements this strategy.
2015-10-30 22:23:41 +00:00
..
arc.rs don't use drop_in_place as an intrinsic 2015-10-30 11:24:54 -04:00
boxed.rs Remove some trivial transmutes 2015-10-17 20:29:49 -04:00
boxed_test.rs rustfmt liballoc 2015-09-24 10:00:54 +12:00
heap.rs Better function calls 2015-09-24 11:32:01 +12:00
lib.rs expose drop_in_place as ptr::drop_in_place 2015-10-30 10:54:25 -04:00
raw_vec.rs Fix excessive memory allocation in RawVec::reserve 2015-10-31 00:17:16 +03:00
rc.rs don't use drop_in_place as an intrinsic 2015-10-30 11:24:54 -04:00