summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Wielaard <mark@klomp.org>2007-04-06 15:56:25 +0000
committerMark Wielaard <mark@klomp.org>2007-04-06 15:56:25 +0000
commit4cc46f1cca8a7c97ed5fc0effa511e6705802a3f (patch)
tree5911e2276acb0661b85e135e99e22e3b235b8125
parent9d89ebaf763178447aa4e44480ff16d396284a3b (diff)
downloadclasspath-4cc46f1cca8a7c97ed5fc0effa511e6705802a3f.tar.gz
2007-04-06 Mark Wielaard <mark@klomp.org>
* lib/mkcollections.pl.in: Add externalclasses. * java/util/Collections.java: Unroll enhanced for loops. * java/util/HashMap.java: Likewise. * java/util/Hashtable.java: Likewise. * java/util/TreeMap.java: Likewise.
-rw-r--r--ChangeLog10
-rw-r--r--java/util/Collections.java32
-rw-r--r--java/util/HashMap.java16
-rw-r--r--java/util/Hashtable.java18
-rw-r--r--java/util/TreeMap.java8
-rwxr-xr-xlib/mkcollections.pl.in17
6 files changed, 69 insertions, 32 deletions
diff --git a/ChangeLog b/ChangeLog
index 2d12d0a0c..70392c892 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2007-04-06 Mark Wielaard <mark@klomp.org>
+
+ * lib/mkcollections.pl.in: Add externalclasses.
+ * java/util/Collections.java: Unroll enhanced for loops.
+ * java/util/HashMap.java: Likewise.
+ * java/util/Hashtable.java: Likewise.
+ * java/util/TreeMap.java: Likewise.
+
2007-04-06 Andrew John Hughes <gnu_andrew@member.fsf.org>
* gnu/javax/management/Translator.java:
@@ -182,7 +190,7 @@
for removed files.
* native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkToolkit.c
Removed unused bits from gthread-jni.c.
-
+
2007-04-03 Francis Kung <fkung@redhat.com>
* gnu/java/awt/peer/gtk/FreetypeGlyphVector.java
diff --git a/java/util/Collections.java b/java/util/Collections.java
index 1c3735eab..fd802fe9d 100644
--- a/java/util/Collections.java
+++ b/java/util/Collections.java
@@ -1462,8 +1462,10 @@ public class Collections
public static int frequency (Collection<?> c, Object o)
{
int result = 0;
- for (Object v : c)
+ final Iterator<?> it = c.iterator();
+ while (it.hasNext())
{
+ Object v = it.next();
if (AbstractCollection.equals(o, v))
++result;
}
@@ -1524,8 +1526,9 @@ public class Collections
public static boolean disjoint(Collection<?> c1, Collection<?> c2)
{
Collection<Object> oc1 = (Collection<Object>) c1;
- for (Object o : oc1)
- if (c2.contains(o))
+ final Iterator<Object> it = oc1.iterator();
+ while (it.hasNext())
+ if (c2.contains(it.next()))
return false;
return true;
}
@@ -5827,8 +5830,10 @@ public class Collections
public boolean addAll(Collection<? extends E> coll)
{
Collection<E> typedColl = (Collection<E>) c;
- for (E element : typedColl)
+ final Iterator<E> it = typedColl.iterator();
+ while (it.hasNext())
{
+ final E element = it.next();
if (!type.isInstance(element))
throw new ClassCastException("A member of the collection is not of the correct type.");
}
@@ -6169,9 +6174,10 @@ public class Collections
public boolean addAll(int index, Collection<? extends E> coll)
{
Collection<E> typedColl = (Collection<E>) coll;
- for (E element : typedColl)
+ final Iterator<E> it = typedColl.iterator();
+ while (it.hasNext())
{
- if (!type.isInstance(element))
+ if (!type.isInstance(it.next()))
throw new ClassCastException("A member of the collection is not of the correct type.");
}
return list.addAll(index, coll);
@@ -6872,8 +6878,10 @@ public class Collections
public void putAll(Map<? extends K, ? extends V> map)
{
Map<K,V> typedMap = (Map<K,V>) map;
- for (Map.Entry<K,V> entry : typedMap.entrySet())
+ final Iterator<Map.Entry<K,V>> it = typedMap.entrySet().iterator();
+ while (it.hasNext())
{
+ final Map.Entry<K,V> entry = it.next();
if (!keyType.isInstance(entry.getKey()))
throw new ClassCastException("A key is of the wrong type.");
if (!valueType.isInstance(entry.getValue()))
@@ -7494,8 +7502,9 @@ public class Collections
public boolean addAll(Collection<? extends T> c)
{
boolean result = false;
- for (T e : c)
- result |= deque.offerFirst(e);
+ final Iterator<? extends T> it = c.iterator();
+ while (it.hasNext())
+ result |= deque.offerFirst(it.next());
return result;
}
@@ -7572,8 +7581,9 @@ public class Collections
public boolean addAll(Collection<? extends E> c)
{
boolean result = false;
- for (E e : c)
- result |= (map.put(e, true) == null);
+ final Iterator<? extends E> it = c.iterator();
+ while (it.hasNext())
+ result |= (map.put(it.next(), true) == null);
return result;
}
diff --git a/java/util/HashMap.java b/java/util/HashMap.java
index 92022a7d5..eca3ad6aa 100644
--- a/java/util/HashMap.java
+++ b/java/util/HashMap.java
@@ -380,11 +380,11 @@ public class HashMap<K, V> extends AbstractMap<K, V>
*/
public void putAll(Map<? extends K, ? extends V> m)
{
- Map<K,V> addMap;
-
- addMap = (Map<K,V>) m;
- for (Map.Entry<K,V> e : addMap.entrySet())
+ final Map<K,V> addMap = (Map<K,V>) m;
+ final Iterator<Map.Entry<K,V>> it = addMap.entrySet().iterator();
+ while (it.hasNext())
{
+ final Map.Entry<K,V> e = it.next();
// Optimize in case the Entry is one of our own.
if (e instanceof AbstractMap.SimpleEntry)
{
@@ -710,12 +710,12 @@ public class HashMap<K, V> extends AbstractMap<K, V>
*/
void putAllInternal(Map<? extends K, ? extends V> m)
{
- Map<K,V> addMap;
-
- addMap = (Map<K,V>) m;
+ final Map<K,V> addMap = (Map<K,V>) m;
+ final Iterator<Map.Entry<K,V>> it = addMap.entrySet().iterator();
size = 0;
- for (Map.Entry<K,V> e : addMap.entrySet())
+ while (it.hasNext())
{
+ final Map.Entry<K,V> e = it.next();
size++;
K key = e.getKey();
int idx = hash(key);
diff --git a/java/util/Hashtable.java b/java/util/Hashtable.java
index 2e265a473..20fb002b9 100644
--- a/java/util/Hashtable.java
+++ b/java/util/Hashtable.java
@@ -505,12 +505,11 @@ public class Hashtable<K, V> extends Dictionary<K, V>
*/
public synchronized void putAll(Map<? extends K, ? extends V> m)
{
- Map<K,V> addMap;
-
- addMap = (Map<K,V>) m;
-
- for (Map.Entry<K,V> e : addMap.entrySet())
+ final Map<K,V> addMap = (Map<K,V>) m;
+ final Iterator<Map.Entry<K,V>> it = addMap.entrySet().iterator();
+ while (it.hasNext())
{
+ final Map.Entry<K,V> e = it.next();
// Optimize in case the Entry is one of our own.
if (e instanceof AbstractMap.SimpleEntry)
{
@@ -857,13 +856,12 @@ public class Hashtable<K, V> extends Dictionary<K, V>
*/
void putAllInternal(Map<? extends K, ? extends V> m)
{
- Map<K,V> addMap;
-
- addMap = (Map<K,V>) m;
+ final Map<K,V> addMap = (Map<K,V>) m;
+ final Iterator<Map.Entry<K,V>> it = addMap.entrySet().iterator();
size = 0;
-
- for (Map.Entry<K,V> e : addMap.entrySet())
+ while (it.hasNext());
{
+ final Map.Entry<K,V> e = it.next();
size++;
K key = e.getKey();
int idx = hash(key);
diff --git a/java/util/TreeMap.java b/java/util/TreeMap.java
index 71047cfc9..f54cbc336 100644
--- a/java/util/TreeMap.java
+++ b/java/util/TreeMap.java
@@ -2721,8 +2721,10 @@ public class TreeMap<K, V> extends AbstractMap<K, V>
public String toString()
{
StringBuilder r = new StringBuilder("{");
- for (Entry<DK,DV> e : entrySet())
+ final Iterator<Entry<DK,DV>> it = entrySet().iterator();
+ while (it.hasNext())
{
+ final Entry<DK,DV> e = it.next();
r.append(e.getKey());
r.append('=');
r.append(e.getValue());
@@ -3157,8 +3159,10 @@ public class TreeMap<K, V> extends AbstractMap<K, V>
public String toString()
{
StringBuilder r = new StringBuilder("[");
- for (D o : this)
+ final Iterator<D> it = iterator();
+ while (it.hasNext())
{
+ final D o = it.next();
if (o == this)
r.append("<this>");
else
diff --git a/lib/mkcollections.pl.in b/lib/mkcollections.pl.in
index 3d2d3c78a..2c80aa1de 100755
--- a/lib/mkcollections.pl.in
+++ b/lib/mkcollections.pl.in
@@ -55,6 +55,12 @@ my @javautilclasses=qw(AbstractCollection
TreeMap
TreeSet
Vector);
+my @externalclasses=qw(AbstractQueue
+ ArrayDeque
+ Deque
+ NavigableMap
+ NavigableSet
+ Queue);
my $destPkg = $destpath;
$destPkg =~ s!/!.!g;
@@ -109,6 +115,9 @@ EOF
for $clazz (@javautilclasses) {
$_ =~ s/java.util.$clazz/$clazz/g;
}
+ for $clazz (@externalclasses) {
+ $_ =~ s/java.util.$clazz/$clazz/g;
+ }
$_ =~ s/abstract (interface)/$1/g;
@@ -139,3 +148,11 @@ for $file (@javautilclasses) {
print "$outfile\n";
convert ($file, $infile, $outfile);
}
+
+for $file (@externalclasses) {
+ my $infile = "$classpath/external/jsr166/java/util/$file.java";
+ my $outfile = "$destpath/$file.java";
+ print "$outfile\n";
+ convert ($file, $infile, $outfile);
+}
+