Skip to content

Commit ecc9c60

Browse files
committed
perf(napi/parser): raw transfer: reduce maths complexity (#13145)
Tiny perf optimization. Reduce complexity of maths by doing as much calculation as possible using consts. Shaves off 1 operation! https://godbolt.org/z/5h4hzznxs This change does not alter the result. `data_offset + RAW_METADATA_SIZE` couldn't overflow because `data_offset` was derived from a `u32`, and this code (raw transfer) is only run on 64-bit systems, so there's plenty of headroom in `usize`. But it does make it easier to support 32-bit in future.
1 parent c63c944 commit ecc9c60

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

napi/parser/src/raw_transfer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ unsafe fn parse_raw_impl(
189189
};
190190
let source_len = source_len as usize;
191191
let data_offset = source_len.next_multiple_of(BUMP_ALIGN);
192-
let data_size = BUFFER_SIZE.saturating_sub(data_offset + RAW_METADATA_SIZE);
192+
let data_size = (BUFFER_SIZE - RAW_METADATA_SIZE).saturating_sub(data_offset);
193193
assert!(data_size >= Allocator::RAW_MIN_SIZE, "Source text is too long");
194194

195195
// Create `Allocator`.

0 commit comments

Comments
 (0)