Only suggestions, we probably need microbenchmarks to choose between the
alternatives, as AbstractMap is used a lot within applications (at least
one per Widget, then an additional one per event type with a registered
handler).


http://gwt-code-reviews.appspot.com/1877803/diff/1/user/super/com/google/gwt/emul/java/util/AbstractMap.java
File user/super/com/google/gwt/emul/java/util/AbstractMap.java (right):

http://gwt-code-reviews.appspot.com/1877803/diff/1/user/super/com/google/gwt/emul/java/util/AbstractMap.java#newcode144
user/super/com/google/gwt/emul/java/util/AbstractMap.java:144: for
(Iterator<Entry<K, V>> iter = entrySet().iterator(); iter.hasNext();) {
Instead of duplicating the code from implFindEntry, how about changing
implFindEntry to return the entry's value instead? (using a marker value
to signal that no entry was found).

containsKey would then be:

   return implFindEntry(key, false) != ABSENT;

and get and remove would use:

   return value == ABSENT ? null : value;

The downside to that approach is that it introduces a clinit if ABSENT
is made static, or an ABSENT instance per AbstractMap otherwise.

Alternatively, implFindEntry could be changed to:

   if (remove) {
     entry = new MapEntryImpl<K, V>(entry.getKey(), entry.getValue());
     iter.remove();
   }

only adding a small runtime overhead on removal.

http://gwt-code-reviews.appspot.com/1877803/

--
http://groups.google.com/group/Google-Web-Toolkit-Contributors

Reply via email to