Author: [EMAIL PROTECTED]
Date: Thu Oct 30 17:51:19 2008
New Revision: 3916

Modified:
    releases/1.6/user/super/com/google/gwt/emul/java/util/Collections.java

Log:
Cache the entry set, key set, and values collection for unmodifiable maps  
to reduce object creation on repeated calls.

Patch by: amitmanjhi
Review by: me


Modified:  
releases/1.6/user/super/com/google/gwt/emul/java/util/Collections.java
==============================================================================
--- releases/1.6/user/super/com/google/gwt/emul/java/util/Collections.java      
 
(original)
+++ releases/1.6/user/super/com/google/gwt/emul/java/util/Collections.java      
 
Thu Oct 30 17:51:19 2008
@@ -227,7 +227,10 @@
        }
      }

+    private transient UnmodifiableSet<Map.Entry<K, V>> entrySet;
+    private transient UnmodifiableSet<K> keySet;
      private final Map<? extends K, ? extends V> map;
+    private transient UnmodifiableCollection<V> values;

      public UnmodifiableMap(Map<? extends K, ? extends V> map) {
        this.map = map;
@@ -246,7 +249,10 @@
      }

      public Set<Map.Entry<K, V>> entrySet() {
-      return new UnmodifiableEntrySet<K, V>(map.entrySet());
+      if (entrySet == null) {
+        entrySet = new UnmodifiableEntrySet<K, V>(map.entrySet());
+      }
+      return entrySet;
      }

      public boolean equals(Object o) {
@@ -266,7 +272,10 @@
      }

      public Set<K> keySet() {
-      return unmodifiableSet(map.keySet());
+      if (keySet == null) {
+        keySet = new UnmodifiableSet<K>(map.keySet());
+      }
+      return keySet;
      }

      public V put(K key, V value) {
@@ -290,7 +299,10 @@
      }

      public Collection<V> values() {
-      return unmodifiableCollection(map.values());
+      if (values == null) {
+        values = new UnmodifiableCollection<V>(map.values());
+      }
+      return values;
      }
    }


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

Reply via email to