From cc575412817b9a052807908a4f968d47221b60b7 Mon Sep 17 00:00:00 2001 From: overlookmotel <557937+overlookmotel@users.noreply.github.com> Date: Tue, 1 Oct 2024 14:58:36 +0000 Subject: [PATCH] refactor(data_structures): `NonEmptyStack::len` hint that `len` is never 0 (#6220) Tiny optimization. Make sure compiler knows that `NonEmptyStack::len` can never return 0. --- crates/oxc_data_structures/src/stack/non_empty.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/crates/oxc_data_structures/src/stack/non_empty.rs b/crates/oxc_data_structures/src/stack/non_empty.rs index 31b1eedfa..82754d7a7 100644 --- a/crates/oxc_data_structures/src/stack/non_empty.rs +++ b/crates/oxc_data_structures/src/stack/non_empty.rs @@ -100,7 +100,9 @@ impl StackCommon for NonEmptyStack { // When stack has 1 entry, `start - cursor == 0`, so add 1 to get number of entries. // SAFETY: Capacity cannot exceed `Self::MAX_CAPACITY`, which is `<= isize::MAX`, // and offset can't exceed capacity, so `+ 1` cannot wrap around. - offset + 1 + // `checked_add(1).unwrap_unchecked()` instead of just `+ 1` to hint to compiler + // that return value can never be zero. + unsafe { offset.checked_add(1).unwrap_unchecked() } } }