diff --git a/rhino/src/main/java/org/mozilla/javascript/Hashtable.java b/rhino/src/main/java/org/mozilla/javascript/Hashtable.java index a022078455..2f877ed6d6 100644 --- a/rhino/src/main/java/org/mozilla/javascript/Hashtable.java +++ b/rhino/src/main/java/org/mozilla/javascript/Hashtable.java @@ -123,20 +123,25 @@ public int size() { public void put(Object key, Object value) { final Entry nv = new Entry(key, value); - if (!map.containsKey(nv)) { - // New value -- insert to end of doubly-linked list - map.put(nv, nv); - if (first == null) { - first = last = nv; - } else { - last.next = nv; - nv.prev = last; - last = nv; - } - } else { - // Update the existing value and keep it in the same place in the list - map.get(nv).value = value; - } + map.compute( + nv, + (k, existing) -> { + if (existing == null) { + // New value -- insert to end of doubly-linked list + if (first == null) { + first = last = nv; + } else { + last.next = nv; + nv.prev = last; + last = nv; + } + return nv; + } else { + // Update the existing value and keep it in the same place in the list + existing.value = value; + return existing; + } + }); } /**