[PATCH] Implement a noop clear() for Collections#EMPTY_LIST
Mohamed Naufal
naufal11 at gmail.com
Sat May 28 09:05:13 UTC 2016
Hi,
I see that this is applicable to EmptyMap and EmptySet as well, here's an
updated patch with clear() overridden for all 3 classes.
Thanks,
Naufal
On 23 May 2016 at 16:13, Paul Sandoz <paul.sandoz at oracle.com> wrote:
> Hi Naufal,
>
> Thanks for looking at this.
>
> For us to accept your patch (no matter how small) you need to become a
> contributor, which requires that you agree to the Oracle Contributor
> Agreement (OCA), see:
>
> http://openjdk.java.net/contribute/
>
> Thanks,
> Paul.
>
> > On 22 May 2016, at 12:10, Mohamed Naufal <naufal11 at gmail.com> wrote:
> >
> > Hi,
> >
> > A call to clear() on Collections#EMPTY_LIST is currently redirected to
> > AbstractList#clear(), which performs a bunch of checks and creates a
> > ListItr object, all of which is unnecessary for an EmptyList.
> >
> > PFA a patch that implements a noop clear() for EmptyList.
> >
> > Thanks,
> > Naufal
> > <EmptyList_clear.diff>
>
>
-------------- next part --------------
# HG changeset patch
# User Mohamed Naufal <naufal11 at gmail.com>
# Date 1464424050 -19800
# Sat May 28 13:57:30 2016 +0530
# Node ID 78c139550bfce1c1795dc5d7820766b95de19d2c
# Parent bbc19b6de175e355d008d6b968183bd3c4edce55
Collections: Implement a noop clear() for EmptyList, EmptyMap and EmptySet
diff -r bbc19b6de175 -r 78c139550bfc src/java.base/share/classes/java/util/Collections.java
--- a/src/java.base/share/classes/java/util/Collections.java Thu May 26 16:02:16 2016 +0000
+++ b/src/java.base/share/classes/java/util/Collections.java Sat May 28 13:57:30 2016 +0530
@@ -4324,6 +4324,7 @@
public int size() {return 0;}
public boolean isEmpty() {return true;}
+ public void clear() {}
public boolean contains(Object obj) {return false;}
public boolean containsAll(Collection<?> c) { return c.isEmpty(); }
@@ -4447,6 +4448,7 @@
public int size() {return 0;}
public boolean isEmpty() {return true;}
+ public void clear() {}
public boolean contains(Object obj) {return false;}
public boolean containsAll(Collection<?> c) { return c.isEmpty(); }
@@ -4582,6 +4584,7 @@
public int size() {return 0;}
public boolean isEmpty() {return true;}
+ public void clear() {}
public boolean containsKey(Object key) {return false;}
public boolean containsValue(Object value) {return false;}
public V get(Object key) {return null;}
More information about the core-libs-dev
mailing list