< prev index next >

src/java.base/share/classes/java/util/IdentityHashMap.java

Print this page
rev 54827 : 6394757: AbstractSet.removeAll semantics are surprisingly dependent on relative sizes
Reviewed-by: XXX

*** 1,7 **** /* ! * Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this --- 1,7 ---- /* ! * Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this
*** 985,1010 **** public boolean remove(Object o) { int oldSize = size; IdentityHashMap.this.remove(o); return size != oldSize; } - /* - * Must revert from AbstractSet's impl to AbstractCollection's, as - * the former contains an optimization that results in incorrect - * behavior when c is a smaller "normal" (non-identity-based) Set. - */ - public boolean removeAll(Collection<?> c) { - Objects.requireNonNull(c); - boolean modified = false; - for (Iterator<K> i = iterator(); i.hasNext(); ) { - if (c.contains(i.next())) { - i.remove(); - modified = true; - } - } - return modified; - } public void clear() { IdentityHashMap.this.clear(); } public int hashCode() { int result = 0; --- 985,994 ----
*** 1202,1228 **** return size; } public void clear() { IdentityHashMap.this.clear(); } - /* - * Must revert from AbstractSet's impl to AbstractCollection's, as - * the former contains an optimization that results in incorrect - * behavior when c is a smaller "normal" (non-identity-based) Set. - */ - public boolean removeAll(Collection<?> c) { - Objects.requireNonNull(c); - boolean modified = false; - for (Iterator<Map.Entry<K,V>> i = iterator(); i.hasNext(); ) { - if (c.contains(i.next())) { - i.remove(); - modified = true; - } - } - return modified; - } - public Object[] toArray() { return toArray(new Object[0]); } @SuppressWarnings("unchecked") --- 1186,1195 ----
< prev index next >