mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 14:54:52 +02:00
8247605: Avoid array allocation when concatenating with empty string
Reviewed-by: redestad, plevart
This commit is contained in:
parent
8e687450d6
commit
55e381b32f
5 changed files with 304 additions and 238 deletions
|
@ -1790,6 +1790,42 @@ public class TreeMap<K,V>
|
|||
return m.put(key, value);
|
||||
}
|
||||
|
||||
public V putIfAbsent(K key, V value) {
|
||||
if (!inRange(key))
|
||||
throw new IllegalArgumentException("key out of range");
|
||||
return m.putIfAbsent(key, value);
|
||||
}
|
||||
|
||||
public V merge(K key, V value, BiFunction<? super V, ? super V, ? extends V> remappingFunction) {
|
||||
if (!inRange(key))
|
||||
throw new IllegalArgumentException("key out of range");
|
||||
return m.merge(key, value, remappingFunction);
|
||||
}
|
||||
|
||||
public V computeIfAbsent(K key, Function<? super K, ? extends V> mappingFunction) {
|
||||
if (!inRange(key)) {
|
||||
// Do not throw if mapping function returns null
|
||||
// to preserve compatibility with default computeIfAbsent implementation
|
||||
if (mappingFunction.apply(key) == null) return null;
|
||||
throw new IllegalArgumentException("key out of range");
|
||||
}
|
||||
return m.computeIfAbsent(key, mappingFunction);
|
||||
}
|
||||
|
||||
public V compute(K key, BiFunction<? super K, ? super V, ? extends V> remappingFunction) {
|
||||
if (!inRange(key)) {
|
||||
// Do not throw if remapping function returns null
|
||||
// to preserve compatibility with default computeIfAbsent implementation
|
||||
if (remappingFunction.apply(key, null) == null) return null;
|
||||
throw new IllegalArgumentException("key out of range");
|
||||
}
|
||||
return m.compute(key, remappingFunction);
|
||||
}
|
||||
|
||||
public V computeIfPresent(K key, BiFunction<? super K, ? super V, ? extends V> remappingFunction) {
|
||||
return !inRange(key) ? null : m.computeIfPresent(key, remappingFunction);
|
||||
}
|
||||
|
||||
public final V get(Object key) {
|
||||
return !inRange(key) ? null : m.get(key);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue