authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2026-08-25 14:20:48+01:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2026-08-25 22:59:25+01:00
log1a87c894a729b290cc2e9553fa9d16e1b0eb5453
tree8f268179e910917a8576442c6205e2b4453b27c5
parent6f8eb736856054b8a02ae2fe734340e2f8ce0a50
signaturelock-open Commit is signed but in an unrecognized format.

MappedFile: clean up accidental duplicate code


1 files changed, 4 insertions(+), 23 deletions(-)

src/link/MappedFile.zig+4-23
...@@ -1544,25 +1544,6 @@ fn growNodeViaInsertRange(...@@ -1544,25 +1544,6 @@ fn growNodeViaInsertRange(
1544 // We don't compute the size of the range yet, because depending on `grow_mode` we might want to1544 // We don't compute the size of the range yet, because depending on `grow_mode` we might want to
1545 // bump it based on our sibling and parent nodes' alignments. However, we can do an early check1545 // bump it based on our sibling and parent nodes' alignments. However, we can do an early check
1546 // for cases where we should obviously exit.1546 // for cases where we should obviously exit.
1547 const requested_range_size = new_size - old_size;
1548 if (!mf.flags.block_size.check(requested_range_size)) {
1549 // The requested size isn't exactly aligned.
1550 switch (grow_mode) {
1551 .exact => return false,
1552 .minimum => {
1553 // We can still choose to allow it by increasing the size a bit, but we shouldn't do
1554 // that if it would *significantly* increase the requested size.
1555 const block_size = mf.flags.block_size.toByteUnits();
1556 if (requested_range_size < block_size * 2) {
1557 // Bumping this size up to the next block boundary would be a quite significant
1558 // increase; let's not do it.
1559 return false;
1560 }
1561 },
1562 }
1563 }
1564 // If `grow_mode` is exact, we will use exactly this size, but if it is `.minimum`, we may bump
1565 // the size a little more.
1566 const min_range_size: u64 = s: {1547 const min_range_size: u64 = s: {
1567 const exact_size = new_size - old_size;1548 const exact_size = new_size - old_size;
1568 if (mf.flags.block_size.check(exact_size)) {1549 if (mf.flags.block_size.check(exact_size)) {
...@@ -1649,16 +1630,16 @@ fn growNodeViaInsertRange(...@@ -1649,16 +1630,16 @@ fn growNodeViaInsertRange(
1649 }1630 }
1650 // Traversal done. We didn't hit `max_moved_nodes`, so now we can use the computed alignment1631 // Traversal done. We didn't hit `max_moved_nodes`, so now we can use the computed alignment
1651 // requirement to figure out whether we're actually going to insert a range.1632 // requirement to figure out whether we're actually going to insert a range.
1652 if (need_range_align.check(requested_range_size)) {1633 if (need_range_align.check(min_range_size)) {
1653 break :range_size requested_range_size;1634 break :range_size min_range_size;
1654 }1635 }
1655 // Perhaps we're allowed to grow by more than `requested_range_size`?1636 // Perhaps we're allowed to grow by more than `min_range_size`?
1656 switch (grow_mode) {1637 switch (grow_mode) {
1657 .exact => return false,1638 .exact => return false,
1658 .minimum => {1639 .minimum => {
1659 const candidate_range_size = need_range_align.forward(min_range_size);1640 const candidate_range_size = need_range_align.forward(min_range_size);
1660 // Allow growing by up to 50% more than was requested.1641 // Allow growing by up to 50% more than was requested.
1661 if (candidate_range_size <= requested_range_size +| requested_range_size / 2) {1642 if (candidate_range_size <= min_range_size +| min_range_size / 2) {
1662 break :range_size candidate_range_size;1643 break :range_size candidate_range_size;
1663 } else {1644 } else {
1664 return false;1645 return false;