Skip to content

Commit fbf36fc

Browse files
Claude Opus 4.7 (1M context)claude
andcommitted
Performance: hoist String fast-path above null check in hashCodeIgnoreCase(CharSequence)
The original ordering tested `cs == null` first, then checked `cs instanceof String` to delegate to the optimized String-specific overload. Since `null instanceof String` is false, the null branch is never taken on the String path and adds a wasted comparison on what is by far the most common input type. Reordering so the String-dispatch runs first preserves null-safety (null instanceof String == false leaves the null check in place for non-String inputs) and removes one branch on the hot path. Pure reordering, no behavioral change. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent b45c0b8 commit fbf36fc

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

src/main/java/com/cedarsoftware/util/StringUtilities.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -990,13 +990,13 @@ public static String createString(byte[] bytes, String encoding) {
990990
* @return the case-insensitive hash code, or 0 if cs is null
991991
*/
992992
public static int hashCodeIgnoreCase(CharSequence cs) {
993-
if (cs == null) return 0;
994-
995993
// For String, delegate to the optimized String-specific version
996994
if (cs instanceof String) {
997995
return hashCodeIgnoreCase((String) cs);
998996
}
999997

998+
if (cs == null) return 0;
999+
10001000
// Single-pass optimization with ASCII fast path.
10011001
final int n = cs.length();
10021002
int h = 0;

0 commit comments

Comments
 (0)