Skip to content

Commit 396561b

Browse files
committed
Make sure arenas don't allocate bigger than HUGE_PAGE
1 parent 8850893 commit 396561b

File tree

1 file changed

+4
-8
lines changed
  • compiler/rustc_arena/src

1 file changed

+4
-8
lines changed

compiler/rustc_arena/src/lib.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -223,10 +223,8 @@ impl<T> TypedArena<T> {
223223
// If the previous chunk's len is less than HUGE_PAGE
224224
// bytes, then this chunk will be least double the previous
225225
// chunk's size.
226-
new_cap = last_chunk.storage.len();
227-
if new_cap < HUGE_PAGE / elem_size {
228-
new_cap = new_cap.checked_mul(2).unwrap();
229-
}
226+
new_cap = last_chunk.storage.len().min(HUGE_PAGE / elem_size / 2);
227+
new_cap = new_cap * 2;
230228
} else {
231229
new_cap = PAGE / elem_size;
232230
}
@@ -343,10 +341,8 @@ impl DroplessArena {
343341
// If the previous chunk's len is less than HUGE_PAGE
344342
// bytes, then this chunk will be least double the previous
345343
// chunk's size.
346-
new_cap = last_chunk.storage.len();
347-
if new_cap < HUGE_PAGE {
348-
new_cap = new_cap.checked_mul(2).unwrap();
349-
}
344+
new_cap = last_chunk.storage.len().min(HUGE_PAGE / 2);
345+
new_cap = new_cap * 2;
350346
} else {
351347
new_cap = PAGE;
352348
}

0 commit comments

Comments
 (0)