This is the mail archive of the
java-patches@sources.redhat.com
mailing list for the Java project.
PATCH: LinkedList.removeFirst() & removeLast()
- To: java-patches at sources dot redhat dot com
- Subject: PATCH: LinkedList.removeFirst() & removeLast()
- From: Bryce McKinlay <bryce at albatross dot co dot nz>
- Date: Sat, 02 Dec 2000 14:46:22 +1300
- CC: Adam Welc <welc at cs dot purdue dot edu>, classpath at gnu dot org
- References: <3A281A21.BE02BB3B@cs.purdue.edu> <3A281C42.2ADCD0F7@netreach.net>
Stuart Ballard wrote:
> Could whoever it was that did this
> rewrite (Tom?) take a look at these changes and reply to Adam?
Thanks, Adam. Your fix looks fine to me, but we also need to handle the
case where size == 1 and first == last. I'm checking this patch in to
libgcj and classpath.
regards
[ bryce ]
2000-12-02 Bryce McKinlay <bryce@albatross.co.nz>
From Adam Welc <welc@cs.purdue.edu>:
* java/util/LinkedList.java (removeFirst): Update `first' field.
Handle the last == first case.
(removeLast): Update `last' field. Handle the last == first case.
Index: java/util/LinkedList.java
===================================================================
RCS file: /cvs/java/libgcj/libjava/java/util/LinkedList.java,v
retrieving revision 1.3
diff -u -r1.3 LinkedList.java
--- LinkedList.java 2000/11/03 03:58:05 1.3
+++ LinkedList.java 2000/12/02 01:39:54
@@ -183,6 +183,11 @@
if (first.next != null)
first.next.previous = null;
+ else
+ last = null;
+
+ first = first.next;
+
return r;
}
@@ -195,7 +200,12 @@
Object r = last.data;
if (last.previous != null)
- last.previous.next = null;
+ last.previous.next = null;
+ else
+ first = null;
+
+ last = last.previous;
+
return r;
}