From bacbeb2e0bb268e81c156a5c2cd22c7b4736916a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Foucault?= Date: Tue, 3 Mar 2026 09:35:01 +0100 Subject: [PATCH] refactor: Remove usage of float instruction --- src/header/map.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/header/map.rs b/src/header/map.rs index 85504d14..a123606e 100644 --- a/src/header/map.rs +++ b/src/header/map.rs @@ -371,7 +371,7 @@ const FORWARD_SHIFT_THRESHOLD: usize = 512; // If growing the hash map would cause the load factor to drop bellow this // threshold, then instead of growing, the headermap is switched to the red // danger state and safe hashing is used instead. -const LOAD_FACTOR_THRESHOLD: f32 = 0.2; +const LOAD_FACTOR_THRESHOLD: usize = 5; // Macro used to iterate the hash table starting at a given point, looping when // the end is hit. @@ -1739,9 +1739,10 @@ impl HeaderMap { let len = self.entries.len(); if self.danger.is_yellow() { - let load_factor = self.entries.len() as f32 / self.indices.len() as f32; - - if load_factor >= LOAD_FACTOR_THRESHOLD { + // Overflow is not a concern here: entries.len() is bounded by + // MAX_SIZE (2^15) and LOAD_FACTOR_THRESHOLD is 5, so the product + // fits comfortably within a usize. + if self.entries.len() * LOAD_FACTOR_THRESHOLD >= self.indices.len() { // Transition back to green danger level self.danger.set_green();