Skip to content

Commit e8370e0

Browse files
committed
perf: fast-path for not oversized allocations
1 parent a983f30 commit e8370e0

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

src/raw/mod.rs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1509,19 +1509,21 @@ impl RawTableInner {
15091509

15101510
let ptr: NonNull<u8> = match do_alloc(alloc, layout) {
15111511
Ok(block) => {
1512-
// Utilize over-sized allocations.
1513-
let x = maximum_buckets_in(block.len(), table_layout, Group::WIDTH);
1514-
debug_assert!(x >= buckets);
1515-
// Calculate the new ctrl_offset.
1516-
let (_oversized_layout, oversized_ctrl_offset) =
1517-
match table_layout.calculate_layout_for(x) {
1518-
Some(lco) => lco,
1519-
None => unsafe { hint::unreachable_unchecked() },
1520-
};
1521-
debug_assert!(_oversized_layout.size() <= block.len());
1522-
debug_assert!(oversized_ctrl_offset >= ctrl_offset);
1523-
ctrl_offset = oversized_ctrl_offset;
1524-
buckets = x;
1512+
if block.len() > layout.size() {
1513+
// Utilize over-sized allocations.
1514+
let x = maximum_buckets_in(block.len(), table_layout, Group::WIDTH);
1515+
debug_assert!(x >= buckets);
1516+
// Calculate the new ctrl_offset.
1517+
let (_oversized_layout, oversized_ctrl_offset) =
1518+
match table_layout.calculate_layout_for(x) {
1519+
Some(lco) => lco,
1520+
None => unsafe { hint::unreachable_unchecked() },
1521+
};
1522+
debug_assert!(_oversized_layout.size() <= block.len());
1523+
debug_assert!(oversized_ctrl_offset >= ctrl_offset);
1524+
ctrl_offset = oversized_ctrl_offset;
1525+
buckets = x;
1526+
}
15251527

15261528
block.cast()
15271529
}

0 commit comments

Comments
 (0)