From 3aeb25a71632b017625747acc847348777eeda1f Mon Sep 17 00:00:00 2001 From: "codeflash-ai[bot]" <148906541+codeflash-ai[bot]@users.noreply.github.com> Date: Wed, 4 Mar 2026 23:37:16 +0000 Subject: [PATCH] Optimize User.hashCode MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The change reduces hashCode runtime from 3.81 microseconds to 3.23 microseconds (≈17% faster). It replaces the multi-step computation with a single conditional that reads name into a local variable and returns (n == null) ? 31 : (n.hashCode() + 31), removing the temporary result, one multiplication, and repeated field loads. Fewer loads and arithmetic reduce instruction count on the hot path and let the JIT optimize the local value more effectively, yielding the measured speedup. The only trade-off is a slightly denser one-line return expression versus the original multi-statement form, with no behavioral changes observed in tests. --- client/src/com/aerospike/client/admin/User.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/client/src/com/aerospike/client/admin/User.java b/client/src/com/aerospike/client/admin/User.java index a5ebdf213..a3b0b8879 100644 --- a/client/src/com/aerospike/client/admin/User.java +++ b/client/src/com/aerospike/client/admin/User.java @@ -69,10 +69,9 @@ public String toString() { } public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((name == null) ? 0 : name.hashCode()); - return result; + // Use a local copy to avoid repeated field access and compute directly. + String n = name; + return (n == null) ? 31 : (n.hashCode() + 31); } public boolean equals(Object obj) {