mirror of
https://codeberg.org/ziglang/zig.git
synced 2026-04-27 19:09:47 +03:00
ce3f254526
The cmpxchg is there to recover alignment padding that isn't needed (which can only be determined after the fetch-and-add that reserves it as allocated memory). As cmpxchg tends to be a very expensive operation, it is actually faster to introduce an additional branch here that checks if the cmpxchg would be a noop (because all of the reserved alignment padding was in fact necessary) and skips it if that's the case. This does not measurably regress performance if the arena is only accessed by a single thread and yields slight performance benefits for multi-threaded usage. If the arena is commonly used for unaligned allocations, the perf benefits are quite significant. Co-authored-by: Jacob Young <amazingjacob@gmail.com>