This is the mail archive of the
java-patches@sources.redhat.com
mailing list for the Java project.
PATCH: More list updates
- To: java-patches at sources dot redhat dot com, classpath at gnu dot org
- Subject: PATCH: More list updates
- From: Bryce McKinlay <bryce at albatross dot co dot nz>
- Date: Fri, 03 Nov 2000 16:57:23 +1300
This patch makes AbstractList.SubList a top-level private class in 0rder
to work around gcj's static inner class problems (arguably, this also
makes the code cleaner). It also fixes a bug in LinkedList: modification
counts must always be updated in the iterator add() and remove() methods
so that other iterators on the same list will detect concurrent
modification correctly against modifications made through the iterator
view.
This patch is against libgcj, but I'm checking the same into classpath.
regards
[ bryce ]
2000-11-03 Bryce McKinlay <bryce@albatross.co.nz>
* java/util/AbstractList.java (SubList): Make it a top-level private
class.
* java/util/LinkedList.java (remove): Do update modCount and knownMod.
(add): Ditto.
* Makefile.am (ordinary_java_source_files): Add LinkedList.java.
* Makefile.in: Rebuilt.
Index: java/util/AbstractList.java
===================================================================
RCS file: /cvs/java/libgcj/libjava/java/util/AbstractList.java,v
retrieving revision 1.4
diff -u -b -r1.4 AbstractList.java
--- AbstractList.java 2000/11/02 10:17:15 1.4
+++ AbstractList.java 2000/11/03 03:46:22
@@ -309,9 +309,12 @@
knownMod++;
}
} // AbstractList.Iterator
+}
- static class SubList extends AbstractList
- {
+
+
+class SubList extends AbstractList
+{
private AbstractList backingList;
private int offset;
private int size;
@@ -319,9 +322,7 @@
public SubList(AbstractList backing, int fromIndex, int toIndex)
{
backingList = backing;
- // FIXME: The `this' prefixes in this class are a workaround for a
- // gcj bug. They should be removed later.
- this.modCount = backingList.modCount;
+ modCount = backingList.modCount;
offset = fromIndex;
size = toIndex - fromIndex;
}
@@ -337,7 +338,7 @@
*/
private void checkMod()
{
- if (this.modCount != backingList.modCount)
+ if (modCount != backingList.modCount)
throw new ConcurrentModificationException();
}
@@ -496,8 +497,7 @@
public void remove()
{
i.remove();
- // FIXME: Uncomment the following line once the compiler is fixed.
- //SubList.this.modCount++;
+ modCount++;
size--;
position = nextIndex();
}
@@ -510,8 +510,7 @@
public void add(Object o)
{
i.add(o);
- // FIXME: Uncomment the following line once the compiler is fixed.
- //SubList.this.modCount++;
+ modCount++;
size++;
position++;
}
@@ -536,5 +535,4 @@
// through the corresponding methods of the subList.
};
}
- } // AbstractList.SubList
-}
+} // SubList
Index: java/util/LinkedList.java
===================================================================
RCS file: /cvs/java/libgcj/libjava/java/util/LinkedList.java,v
retrieving revision 1.2
diff -u -b -r1.2 LinkedList.java
--- LinkedList.java 2000/11/02 10:08:03 1.2
+++ LinkedList.java 2000/11/03 03:46:22
@@ -322,7 +322,7 @@
prev.next = e;
prev = e;
}
- // Fix up the links between the last new entry and the following entry.
+ // Link the new chain of entries into the list.
prev.next = after;
if (after != null)
after.previous = e;
@@ -621,8 +621,8 @@
next = lastReturned.next;
previous = lastReturned.previous;
- // Because the list is being manipulated directly, there's no need to
- // touch either modCount or knownMod here.
+ modCount++;
+ knownMod++;
removeEntry(lastReturned);
lastReturned = null;
@@ -631,11 +631,27 @@
public void add(Object o)
{
checkMod();
- // Because the list is being manipulated directly, there's no need to
- // touch either modCount or knownMod here.
+ modCount++;
+ knownMod++;
Entry e = new Entry(o);
- addEntry(position, e);
+ e.previous = previous;
+ e.next = next;
+
+ if (previous != null)
+ previous.next = e;
+ else
+ first = e;
+
+ if (next != null)
+ {
+ next.previous = e;
+ next = next.next;
+ }
+ else
+ last = e;
+
previous = e;
+ size++;
position++;
lastReturned = null;
}
Index: Makefile.am
===================================================================
RCS file: /cvs/java/libgcj/libjava/Makefile.am,v
retrieving revision 1.100
diff -u -b -r1.100 Makefile.am
--- Makefile.am 2000/11/02 20:33:05 1.100
+++ Makefile.am 2000/11/03 03:46:23
@@ -935,6 +935,7 @@
java/util/HashMap.java \
java/util/Hashtable.java \
java/util/Iterator.java \
+java/util/LinkedList.java \
java/util/List.java \
java/util/ListIterator.java \
java/util/ListResourceBundle.java \