diff --git a/javaslang/src/main/java/javaslang/collection/HashArrayMappedTrie.java b/javaslang/src/main/java/javaslang/collection/HashArrayMappedTrie.java index 40020380a2..7c0b6e4458 100644 --- a/javaslang/src/main/java/javaslang/collection/HashArrayMappedTrie.java +++ b/javaslang/src/main/java/javaslang/collection/HashArrayMappedTrie.java @@ -287,7 +287,7 @@ final class LeafSingleton extends LeafNode implements Serializable { @Override Option lookup(int shift, int keyHashCode, K key) { - if (Objects.equals(key, this.key)) { + if (keyHashCode == hash && Objects.equals(key, this.key)) { return Option.some(value); } else { return Option.none(); @@ -296,7 +296,7 @@ Option lookup(int shift, int keyHashCode, K key) { @Override AbstractNode modify(int shift, int keyHashCode, K key, V value, Action action) { - if (Objects.equals(key, this.key)) { + if (keyHashCode == hash && Objects.equals(key, this.key)) { return (action == REMOVE) ? EmptyNode.instance() : new LeafSingleton<>(hash, key, value); } else { return (action == REMOVE) ? this : mergeLeaves(shift, this, new LeafSingleton<>(keyHashCode, key, value));