[freenet-cvs] r11660 - trunk/freenet/src/freenet/io/comm

toad at freenetproject.org toad at freenetproject.org
Sat Feb 3 16:05:56 UTC 2007


Author: toad
Date: 2007-02-03 16:05:56 +0000 (Sat, 03 Feb 2007)
New Revision: 11660

Modified:
   trunk/freenet/src/freenet/io/comm/MessageFilter.java
Log:
Reduce allocations in match() significantly at the cost of a few more bytes for a Vector

Modified: trunk/freenet/src/freenet/io/comm/MessageFilter.java
===================================================================
--- trunk/freenet/src/freenet/io/comm/MessageFilter.java	2007-02-03 16:04:57 UTC (rev 11659)
+++ trunk/freenet/src/freenet/io/comm/MessageFilter.java	2007-02-03 16:05:56 UTC (rev 11660)
@@ -38,6 +38,7 @@
     private PeerContext _droppedConnection;
 	private MessageType _type;
     private HashMap _fields = new HashMap();
+    private Vector _fieldList = new Vector(1,1);
     PeerContext _source;
     private long _timeout;
     private int _initialTimeout;
@@ -102,7 +103,8 @@
 			throw new IncorrectTypeException("Got " + fieldValue.getClass() + ", expected " + _type.typeOf(fieldName) + " for " + _type.getName());
 		}
 		synchronized (_fields) {
-			_fields.put(fieldName, fieldValue);
+			if(_fields.put(fieldName, fieldValue) == null)
+				_fieldList.add(fieldName);
 		}
 		return this;
 	}
@@ -133,8 +135,8 @@
 			return false;
 		}
 		synchronized (_fields) {
-			for (Iterator iter = _fields.keySet().iterator(); iter.hasNext();) {
-				String fieldName = (String) iter.next();
+			for (int i = 0; i < _fieldList.size(); i++) {
+				String fieldName = (String) _fieldList.get(i);
 				if (!m.isSet(fieldName)) {
 					return false;
 				}




More information about the cvs mailing list