]> git.lizzy.rs Git - rust.git/commitdiff
Fix the new capacity measurement in arenas.
authorNicholas Nethercote <nnethercote@mozilla.com>
Mon, 4 May 2020 07:17:07 +0000 (17:17 +1000)
committerNicholas Nethercote <nnethercote@mozilla.com>
Wed, 13 May 2020 01:29:16 +0000 (11:29 +1000)
For the given code paths, the amount of space used in the previous chunk
is irrelevant.

(This will almost never make a difference to behaviour, but it makes the
code clearer.)

src/libarena/lib.rs

index 0f0bd617f439c6cd8491b57addf70682e2582936..b42a2e711acd9581841a91e0db89e3381d7bfa5d 100644 (file)
@@ -224,7 +224,7 @@ fn grow(&self, n: usize) {
                     new_capacity = last_chunk.storage.capacity();
                     loop {
                         new_capacity = new_capacity.checked_mul(2).unwrap();
-                        if new_capacity >= currently_used_cap + n {
+                        if new_capacity >= n {
                             break;
                         }
                     }
@@ -350,7 +350,7 @@ fn grow(&self, needed_bytes: usize) {
                     new_capacity = last_chunk.storage.capacity();
                     loop {
                         new_capacity = new_capacity.checked_mul(2).unwrap();
-                        if new_capacity >= used_bytes + needed_bytes {
+                        if new_capacity >= needed_bytes {
                             break;
                         }
                     }