[kaffe] CVS kaffe (robilad): moved kaffe-awt specific org.kaffe.util classes over there

Kaffe CVS cvs-commits at kaffe.org
Sun Jul 16 10:05:38 PDT 2006


PatchSet 7356 
Date: 2006/07/16 16:32:11
Author: robilad
Branch: HEAD
Tag: (none) 
Log:
moved kaffe-awt specific org.kaffe.util classes over there

2006-07-16  Dalibor Topic  <robilad at kaffe.org>

        * libraries/javalib/vmspecific/org/kaffe/util/Timer.java,
        libraries/javalib/vmspecific/org/kaffe/util/TimerClient.java,
        libraries/javalib/vmspecific/org/kaffe/util/VectorSnapshot.java:
        Removed. Moved to kaffe's awt implementatin, i.e. ...

        * libraries/javalib/awt-implementations/kaffe/org/kaffe/util/TimerClient.java,
        libraries/javalib/awt-implementations/kaffe/org/kaffe/util/Timer.java,
        libraries/javalib/awt-implementations/kaffe/org/kaffe/util/VectorSnapshot.java:
        ... to here.

        * libraries/javalib/awt-implementations/Makefile.am: Added the new
        org/kaffe/util classes.

Members: 
	libraries/javalib/vmspecific/org/kaffe/util/Timer.java:1.1->1.2(DEAD) 
	libraries/javalib/vmspecific/org/kaffe/util/TimerClient.java:1.1->1.2(DEAD) 
	libraries/javalib/vmspecific/org/kaffe/util/VectorSnapshot.java:1.1->1.2(DEAD) 
	ChangeLog:1.4860->1.4861 
	libraries/javalib/Makefile.am:1.442->1.443 
	libraries/javalib/Makefile.in:1.556->1.557 
	libraries/javalib/awt-implementations/kaffe/Makefile.am:1.20->1.21 
	libraries/javalib/awt-implementations/kaffe/Makefile.in:1.73->1.74 
	libraries/javalib/awt-implementations/kaffe/org/kaffe/util/Timer.java:INITIAL->1.1 
	libraries/javalib/awt-implementations/kaffe/org/kaffe/util/TimerClient.java:INITIAL->1.1 
	libraries/javalib/awt-implementations/kaffe/org/kaffe/util/VectorSnapshot.java:INITIAL->1.1 

===================================================================
Checking out kaffe/libraries/javalib/vmspecific/org/kaffe/util/Timer.java
RCS:  /home/cvs/kaffe/kaffe/libraries/javalib/vmspecific/org/kaffe/util/Attic/Timer.java,v
VERS: 1.1
***************
--- kaffe/libraries/javalib/vmspecific/org/kaffe/util/Timer.java	Sun Jul 16 17:05:25 2006
+++ /dev/null	Sun Aug  4 19:57:58 2002
@@ -1,174 +0,0 @@
-/*
- * Timer - simple Thread based Timer support
- *
- * Copyright (c) 1998
- *    Transvirtual Technologies, Inc.  All rights reserved.
- *
- * See the file "license.terms" for information on usage and redistribution 
- * of this file. 
- *
- * @author P.Mehlitz
- */
-
-package org.kaffe.util;
-
-
-public class Timer
-  extends Thread
-{
-	private TimerClientEntry[] clients;
-	private int nClients;
-	private int resolution;
-	private boolean stop;
-	private static Timer defaultTimer;
-
-public Timer () {
-	resolution = Integer.MAX_VALUE;
-	
-	clients = new TimerClientEntry[5];
-	for ( int i=0; i<clients.length; i++ ) {
-		clients[i] = new TimerClientEntry();
-	}
-	
-	setDaemon( true);
-	start();
-}
-
-public synchronized boolean addClient ( TimerClient tc, int startWait, int interval ) {
-	TimerClientEntry tce;
-	int i;
-
-	// we allow just a single instance of a client
-	// (otherwise we would need client ids to distinguish
-	// notifications and removes)
-	for ( i=0; i<nClients; i++ ){
-		if ( clients[i].client == tc )
-			return false;
-	}
-
-	if ( nClients == clients.length ){
-		TimerClientEntry[] newClients = new TimerClientEntry[clients.length+10];
-		System.arraycopy( clients, 0, newClients, 0, nClients);
-		clients = newClients;
-		for ( i=nClients; i<clients.length; i++ )
-			clients[i] = new TimerClientEntry();
-	}
-
-	tce = clients[nClients++];
-	tce.client = tc;
-	tce.nextNotify = System.currentTimeMillis() + startWait;
-	tce.interval = interval;
-
-	// If interval is smaller than current resolution, drop current
-	// resolution and wake the timer thread.
-	if (interval < resolution) {
-		resolution = interval;
-		interrupt();
-	}
-
-	if ( nClients == 1 ) {
-		notify();
-	}
-	
-	return true;
-}
-
-public static synchronized Timer getDefaultTimer () {
-	if ( defaultTimer == null ) {
-		defaultTimer = new Timer();
-	}
-	
-	return defaultTimer;
-}
-
-public synchronized boolean removeClient ( TimerClient tc ) {
-	int newres;
-
-	for (int i=0; i < nClients; i++ ) {
-		TimerClientEntry tce = clients[i];
-
-		if ( tce.client == tc ) {
-			int i1 = i+1;
-			int nmax = nClients-1;
-
-			tce.client = null;  // don't leak
-			
-			if (i1 < nmax)
-				System.arraycopy( clients, i1, clients, i, (nmax-i));
-			clients[--nClients] = tce;
-			
-			// adapt the timer resolution to the lowest remaining interval
-			if ( (resolution == tce.interval) && (nClients > 0) ) {
-				for ( i=0, newres=Integer.MAX_VALUE; i<nClients; i++ ){
-					if ( clients[i].interval < newres )
-						newres = clients[i].interval;
-				}
-				// No need to interrupt, this just increases the interval
-				// and takes effect after the next tick automatically.
-				// in case it was the last entry, we go to wait, anyway
-				// (but NOT here, we might be in a different thread)
-				if ( newres != resolution )
-					resolution = newres;
-			}
-
-			return true;
-		}
-	}
-	
-	return false;
-}
-
-public void run () {
-	long t;
-	int  i;
-
-	while ( !stop ) {
-		try {
-			while ( !stop ) {
-				synchronized ( this ) {
-					if ( nClients == 0 ){
-						wait();
-					}
-
-					t = System.currentTimeMillis();
-					for ( i=0; i<nClients; i++ ) {
-						TimerClientEntry tce = clients[i];
-
-						if ( t > tce.nextNotify ) {
-							tce.client.timerExpired( this);
-							tce.nextNotify = t + tce.interval;
-						}
-					}
-				}
-
-				if ( nClients > 0 ){ // otherwise we go waiting, anyway
-					Thread.sleep(resolution);
-				}
-			}
-		}
-		catch ( InterruptedException _ ) {
-			// deliberately tolerated
-		}
-		catch ( Exception x ) {
-			x.printStackTrace();
-		}
-	}
-}
-
-public void startNotify () {
-	stop = false;
-	start();
-}
-
-public void stopNotify () {
-	stop = true;
-}
-}
-
-class TimerClientEntry
-{
-	TimerClient client;
-	long nextNotify;
-	int interval;
-
-}
===================================================================
Checking out kaffe/libraries/javalib/vmspecific/org/kaffe/util/TimerClient.java
RCS:  /home/cvs/kaffe/kaffe/libraries/javalib/vmspecific/org/kaffe/util/Attic/TimerClient.java,v
VERS: 1.1
***************
--- kaffe/libraries/javalib/vmspecific/org/kaffe/util/TimerClient.java	Sun Jul 16 17:05:28 2006
+++ /dev/null	Sun Aug  4 19:57:58 2002
@@ -1,19 +0,0 @@
-/*
- * interface to be used in combination with kaffe.util.Timer 
- *
- * Copyright (c) 1998
- *    Transvirtual Technologies, Inc.  All rights reserved.
- *
- * See the file "license.terms" for information on usage and redistribution 
- * of this file. 
- *
- * @author P.C.Mehlitz
- */
-
-package org.kaffe.util;
-
-public interface TimerClient {
-
-void timerExpired ( Timer timer );
-
-}
===================================================================
Checking out kaffe/libraries/javalib/vmspecific/org/kaffe/util/VectorSnapshot.java
RCS:  /home/cvs/kaffe/kaffe/libraries/javalib/vmspecific/org/kaffe/util/Attic/VectorSnapshot.java,v
VERS: 1.1
***************
--- kaffe/libraries/javalib/vmspecific/org/kaffe/util/VectorSnapshot.java	Sun Jul 16 17:05:28 2006
+++ /dev/null	Sun Aug  4 19:57:58 2002
@@ -1,100 +0,0 @@
-package org.kaffe.util;
-
-import java.util.Enumeration;
-import java.util.NoSuchElementException;
-import java.util.Vector;
-
-/**
- * VectorSnapshot - class for (cached) Vector enumerations that can stand
- * overlapping element removal. A enumeration based on this is guaranteed to
- * touch all elements present at the time the iteration was started (regardless
- * of which elements will be removed from the Vector during the enumeration
- * process). Note that the standard Vector enumeration is index based, i.e.
- * it does not revert indices in case a element is removed as a consequence of
- * the enumeration process.
- *
- * Copyright (c) 1998
- *    Transvirtual Technologies, Inc.  All rights reserved.
- *
- * See the file "license.terms" for information on usage and redistribution
- * of this file.
- *
- */
-public class VectorSnapshot
-  implements Enumeration
-{
-	private Object[] elements;
-	private int index;
-	private int size;
-	private VectorSnapshot next;
-	private static VectorSnapshot cache;
-
-public VectorSnapshot ( Vector v ) {
-	size = v.size();
-	elements = new Object[size];
-	v.copyInto( elements);
-}
-
-public static synchronized VectorSnapshot getCached ( Vector v ) {
-	VectorSnapshot e, l = null;
-
-	if ( cache == null ) {
-		return new VectorSnapshot( v);
-	}
-	else {
-		int n = v.size();
-		
-		for ( e=cache; (e != null); l=e, e=e.next ){
-			if ( e.elements.length <= n ) {
-				if ( cache == e ) {
-					cache = e.next;
-				}
-				else {
-					l.next = e.next;
-				}
-				e.next = null;
-				v.copyInto( e.elements);
-				e.size = n;
-				return e;
-			}
-		}
-		
-		return new VectorSnapshot( v);
-	}
-}
-
-public boolean hasMoreElements () {
-	if ( index < size ){
-		return true;
-	}
-	else {
-		recycle();  // nothing we can do with a completed SnapshotEnumerator
-		return false;
-	}
-}
-
-public Object nextElement () {
-	if ( index >= size ) {
-		recycle();
-		throw new NoSuchElementException();
-	}
-	else {
-		return elements[index++];
-	}
-}
-
-public void recycle () {
-	// bailout if this would waste too much memory
-	if ( elements.length > 128 )
-		return;
-
-	for ( int i=0; i<size; i++ )  // avoid memory leak
-		elements[i] = null;
-	size = index = 0;
-
-	synchronized ( VectorSnapshot.class ) {
-		next = cache;
-		cache = this;
-	}
-}
-}
Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.4860 kaffe/ChangeLog:1.4861
--- kaffe/ChangeLog:1.4860	Sun Jul 16 16:17:41 2006
+++ kaffe/ChangeLog	Sun Jul 16 16:31:54 2006
@@ -1,5 +1,20 @@
 2006-07-16  Dalibor Topic  <robilad at kaffe.org>
 
+	* libraries/javalib/vmspecific/org/kaffe/util/Timer.java,
+	libraries/javalib/vmspecific/org/kaffe/util/TimerClient.java,
+	libraries/javalib/vmspecific/org/kaffe/util/VectorSnapshot.java:
+	Removed. Moved to kaffe's awt implementatin, i.e. ...
+
+	* libraries/javalib/awt-implementations/kaffe/org/kaffe/util/TimerClient.java,
+	libraries/javalib/awt-implementations/kaffe/org/kaffe/util/Timer.java,
+	libraries/javalib/awt-implementations/kaffe/org/kaffe/util/VectorSnapshot.java:
+	... to here.
+
+	* libraries/javalib/awt-implementations/Makefile.am: Added the new 
+	org/kaffe/util classes.
+
+2006-07-16  Dalibor Topic  <robilad at kaffe.org>
+
 	Switched over to GNU Classpath's java.lang.String.
 
 	* libraries/javalib/vmspecific/java/lang/String.java:
Index: kaffe/libraries/javalib/Makefile.am
diff -u kaffe/libraries/javalib/Makefile.am:1.442 kaffe/libraries/javalib/Makefile.am:1.443
--- kaffe/libraries/javalib/Makefile.am:1.442	Sun Jul 16 16:17:47 2006
+++ kaffe/libraries/javalib/Makefile.am	Sun Jul 16 16:32:03 2006
@@ -303,11 +303,8 @@
 	vmspecific/org/kaffe/util/NotImplementedReport.java \
 	vmspecific/org/kaffe/util/Ptr.java \
 	vmspecific/org/kaffe/util/SupportDisabled.java \
-	vmspecific/org/kaffe/util/Timer.java \
-	vmspecific/org/kaffe/util/TimerClient.java \
 	vmspecific/org/kaffe/util/UNIXTimeZone.java \
 	vmspecific/org/kaffe/util/UTF8.java \
-	vmspecific/org/kaffe/util/VectorSnapshot.java \
 	vmspecific/org/kaffe/util/zip/SwitchInflater.java \
 	vmspecific/org/objectweb/asm153/Attribute.java \
 	vmspecific/org/objectweb/asm153/ByteVector.java \
Index: kaffe/libraries/javalib/Makefile.in
diff -u kaffe/libraries/javalib/Makefile.in:1.556 kaffe/libraries/javalib/Makefile.in:1.557
--- kaffe/libraries/javalib/Makefile.in:1.556	Sun Jul 16 16:17:49 2006
+++ kaffe/libraries/javalib/Makefile.in	Sun Jul 16 16:32:06 2006
@@ -617,11 +617,8 @@
 	vmspecific/org/kaffe/util/NotImplementedReport.java \
 	vmspecific/org/kaffe/util/Ptr.java \
 	vmspecific/org/kaffe/util/SupportDisabled.java \
-	vmspecific/org/kaffe/util/Timer.java \
-	vmspecific/org/kaffe/util/TimerClient.java \
 	vmspecific/org/kaffe/util/UNIXTimeZone.java \
 	vmspecific/org/kaffe/util/UTF8.java \
-	vmspecific/org/kaffe/util/VectorSnapshot.java \
 	vmspecific/org/kaffe/util/zip/SwitchInflater.java \
 	vmspecific/org/objectweb/asm153/Attribute.java \
 	vmspecific/org/objectweb/asm153/ByteVector.java \
Index: kaffe/libraries/javalib/awt-implementations/kaffe/Makefile.am
diff -u kaffe/libraries/javalib/awt-implementations/kaffe/Makefile.am:1.20 kaffe/libraries/javalib/awt-implementations/kaffe/Makefile.am:1.21
--- kaffe/libraries/javalib/awt-implementations/kaffe/Makefile.am:1.20	Sun Jul 16 14:06:36 2006
+++ kaffe/libraries/javalib/awt-implementations/kaffe/Makefile.am	Sun Jul 16 16:32:08 2006
@@ -319,7 +319,10 @@
 org_kaffe_io_SRCS = \
 	org/kaffe/io/AccessibleBAOStream.java
 org_kaffe_util_SRCS = \
-	org/kaffe/util/DoubleLinkedObject.java
+	org/kaffe/util/DoubleLinkedObject.java \
+	org/kaffe/util/TimerClient.java \
+	org/kaffe/util/Timer.java \
+	org/kaffe/util/VectorSnapshot.java
 org_kaffe_util_log_SRCS = \
         org/kaffe/util/log/LogClient.java \
         org/kaffe/util/log/LogStream.java \
Index: kaffe/libraries/javalib/awt-implementations/kaffe/Makefile.in
diff -u kaffe/libraries/javalib/awt-implementations/kaffe/Makefile.in:1.73 kaffe/libraries/javalib/awt-implementations/kaffe/Makefile.in:1.74
--- kaffe/libraries/javalib/awt-implementations/kaffe/Makefile.in:1.73	Sun Jul 16 15:05:02 2006
+++ kaffe/libraries/javalib/awt-implementations/kaffe/Makefile.in	Sun Jul 16 16:32:08 2006
@@ -676,7 +676,10 @@
 	org/kaffe/io/AccessibleBAOStream.java
 
 org_kaffe_util_SRCS = \
-	org/kaffe/util/DoubleLinkedObject.java
+	org/kaffe/util/DoubleLinkedObject.java \
+	org/kaffe/util/TimerClient.java \
+	org/kaffe/util/Timer.java \
+	org/kaffe/util/VectorSnapshot.java
 
 org_kaffe_util_log_SRCS = \
         org/kaffe/util/log/LogClient.java \
===================================================================
Checking out kaffe/libraries/javalib/awt-implementations/kaffe/org/kaffe/util/Timer.java
RCS:  /home/cvs/kaffe/kaffe/libraries/javalib/awt-implementations/kaffe/org/kaffe/util/Timer.java,v
VERS: 1.1
***************
--- /dev/null	Sun Aug  4 19:57:58 2002
+++ kaffe/libraries/javalib/awt-implementations/kaffe/org/kaffe/util/Timer.java	Sun Jul 16 17:05:36 2006
@@ -0,0 +1,174 @@
+/*
+ * Timer - simple Thread based Timer support
+ *
+ * Copyright (c) 1998
+ *    Transvirtual Technologies, Inc.  All rights reserved.
+ *
+ * See the file "license.terms" for information on usage and redistribution 
+ * of this file. 
+ *
+ * @author P.Mehlitz
+ */
+
+package org.kaffe.util;
+
+
+public class Timer
+  extends Thread
+{
+	private TimerClientEntry[] clients;
+	private int nClients;
+	private int resolution;
+	private boolean stop;
+	private static Timer defaultTimer;
+
+public Timer () {
+	resolution = Integer.MAX_VALUE;
+	
+	clients = new TimerClientEntry[5];
+	for ( int i=0; i<clients.length; i++ ) {
+		clients[i] = new TimerClientEntry();
+	}
+	
+	setDaemon( true);
+	start();
+}
+
+public synchronized boolean addClient ( TimerClient tc, int startWait, int interval ) {
+	TimerClientEntry tce;
+	int i;
+
+	// we allow just a single instance of a client
+	// (otherwise we would need client ids to distinguish
+	// notifications and removes)
+	for ( i=0; i<nClients; i++ ){
+		if ( clients[i].client == tc )
+			return false;
+	}
+
+	if ( nClients == clients.length ){
+		TimerClientEntry[] newClients = new TimerClientEntry[clients.length+10];
+		System.arraycopy( clients, 0, newClients, 0, nClients);
+		clients = newClients;
+		for ( i=nClients; i<clients.length; i++ )
+			clients[i] = new TimerClientEntry();
+	}
+
+	tce = clients[nClients++];
+	tce.client = tc;
+	tce.nextNotify = System.currentTimeMillis() + startWait;
+	tce.interval = interval;
+
+	// If interval is smaller than current resolution, drop current
+	// resolution and wake the timer thread.
+	if (interval < resolution) {
+		resolution = interval;
+		interrupt();
+	}
+
+	if ( nClients == 1 ) {
+		notify();
+	}
+	
+	return true;
+}
+
+public static synchronized Timer getDefaultTimer () {
+	if ( defaultTimer == null ) {
+		defaultTimer = new Timer();
+	}
+	
+	return defaultTimer;
+}
+
+public synchronized boolean removeClient ( TimerClient tc ) {
+	int newres;
+
+	for (int i=0; i < nClients; i++ ) {
+		TimerClientEntry tce = clients[i];
+
+		if ( tce.client == tc ) {
+			int i1 = i+1;
+			int nmax = nClients-1;
+
+			tce.client = null;  // don't leak
+			
+			if (i1 < nmax)
+				System.arraycopy( clients, i1, clients, i, (nmax-i));
+			clients[--nClients] = tce;
+			
+			// adapt the timer resolution to the lowest remaining interval
+			if ( (resolution == tce.interval) && (nClients > 0) ) {
+				for ( i=0, newres=Integer.MAX_VALUE; i<nClients; i++ ){
+					if ( clients[i].interval < newres )
+						newres = clients[i].interval;
+				}
+				// No need to interrupt, this just increases the interval
+				// and takes effect after the next tick automatically.
+				// in case it was the last entry, we go to wait, anyway
+				// (but NOT here, we might be in a different thread)
+				if ( newres != resolution )
+					resolution = newres;
+			}
+
+			return true;
+		}
+	}
+	
+	return false;
+}
+
+public void run () {
+	long t;
+	int  i;
+
+	while ( !stop ) {
+		try {
+			while ( !stop ) {
+				synchronized ( this ) {
+					if ( nClients == 0 ){
+						wait();
+					}
+
+					t = System.currentTimeMillis();
+					for ( i=0; i<nClients; i++ ) {
+						TimerClientEntry tce = clients[i];
+
+						if ( t > tce.nextNotify ) {
+							tce.client.timerExpired( this);
+							tce.nextNotify = t + tce.interval;
+						}
+					}
+				}
+
+				if ( nClients > 0 ){ // otherwise we go waiting, anyway
+					Thread.sleep(resolution);
+				}
+			}
+		}
+		catch ( InterruptedException _ ) {
+			// deliberately tolerated
+		}
+		catch ( Exception x ) {
+			x.printStackTrace();
+		}
+	}
+}
+
+public void startNotify () {
+	stop = false;
+	start();
+}
+
+public void stopNotify () {
+	stop = true;
+}
+}
+
+class TimerClientEntry
+{
+	TimerClient client;
+	long nextNotify;
+	int interval;
+
+}
===================================================================
Checking out kaffe/libraries/javalib/awt-implementations/kaffe/org/kaffe/util/TimerClient.java
RCS:  /home/cvs/kaffe/kaffe/libraries/javalib/awt-implementations/kaffe/org/kaffe/util/TimerClient.java,v
VERS: 1.1
***************
--- /dev/null	Sun Aug  4 19:57:58 2002
+++ kaffe/libraries/javalib/awt-implementations/kaffe/org/kaffe/util/TimerClient.java	Sun Jul 16 17:05:37 2006
@@ -0,0 +1,19 @@
+/*
+ * interface to be used in combination with kaffe.util.Timer 
+ *
+ * Copyright (c) 1998
+ *    Transvirtual Technologies, Inc.  All rights reserved.
+ *
+ * See the file "license.terms" for information on usage and redistribution 
+ * of this file. 
+ *
+ * @author P.C.Mehlitz
+ */
+
+package org.kaffe.util;
+
+public interface TimerClient {
+
+void timerExpired ( Timer timer );
+
+}
===================================================================
Checking out kaffe/libraries/javalib/awt-implementations/kaffe/org/kaffe/util/VectorSnapshot.java
RCS:  /home/cvs/kaffe/kaffe/libraries/javalib/awt-implementations/kaffe/org/kaffe/util/VectorSnapshot.java,v
VERS: 1.1
***************
--- /dev/null	Sun Aug  4 19:57:58 2002
+++ kaffe/libraries/javalib/awt-implementations/kaffe/org/kaffe/util/VectorSnapshot.java	Sun Jul 16 17:05:37 2006
@@ -0,0 +1,100 @@
+package org.kaffe.util;
+
+import java.util.Enumeration;
+import java.util.NoSuchElementException;
+import java.util.Vector;
+
+/**
+ * VectorSnapshot - class for (cached) Vector enumerations that can stand
+ * overlapping element removal. A enumeration based on this is guaranteed to
+ * touch all elements present at the time the iteration was started (regardless
+ * of which elements will be removed from the Vector during the enumeration
+ * process). Note that the standard Vector enumeration is index based, i.e.
+ * it does not revert indices in case a element is removed as a consequence of
+ * the enumeration process.
+ *
+ * Copyright (c) 1998
+ *    Transvirtual Technologies, Inc.  All rights reserved.
+ *
+ * See the file "license.terms" for information on usage and redistribution
+ * of this file.
+ *
+ */
+public class VectorSnapshot
+  implements Enumeration
+{
+	private Object[] elements;
+	private int index;
+	private int size;
+	private VectorSnapshot next;
+	private static VectorSnapshot cache;
+
+public VectorSnapshot ( Vector v ) {
+	size = v.size();
+	elements = new Object[size];
+	v.copyInto( elements);
+}
+
+public static synchronized VectorSnapshot getCached ( Vector v ) {
+	VectorSnapshot e, l = null;
+
+	if ( cache == null ) {
+		return new VectorSnapshot( v);
+	}
+	else {
+		int n = v.size();
+		
+		for ( e=cache; (e != null); l=e, e=e.next ){
+			if ( e.elements.length <= n ) {
+				if ( cache == e ) {
+					cache = e.next;
+				}
+				else {
+					l.next = e.next;
+				}
+				e.next = null;
+				v.copyInto( e.elements);
+				e.size = n;
+				return e;
+			}
+		}
+		
+		return new VectorSnapshot( v);
+	}
+}
+
+public boolean hasMoreElements () {
+	if ( index < size ){
+		return true;
+	}
+	else {
+		recycle();  // nothing we can do with a completed SnapshotEnumerator
+		return false;
+	}
+}
+
+public Object nextElement () {
+	if ( index >= size ) {
+		recycle();
+		throw new NoSuchElementException();
+	}
+	else {
+		return elements[index++];
+	}
+}
+
+public void recycle () {
+	// bailout if this would waste too much memory
+	if ( elements.length > 128 )
+		return;
+
+	for ( int i=0; i<size; i++ )  // avoid memory leak
+		elements[i] = null;
+	size = index = 0;
+
+	synchronized ( VectorSnapshot.class ) {
+		next = cache;
+		cache = this;
+	}
+}
+}




More information about the kaffe mailing list