[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
java.util.Hashtable.size()/isEmpty()
From: |
Sascha Brawer |
Subject: |
java.util.Hashtable.size()/isEmpty() |
Date: |
Fri, 15 Feb 2002 11:19:15 +0100 |
Hello,
the implementations of java.util.Hashtable.size() and
java.util.Hashtable.isEmpty() merely access a single integer member
field. Since accesses to integer variables are required to be atomic, I
think these two methods don't need to be synchronized. Do people agree?
(Yes, it's a micro-optimization).
% cvs diff -u java/util/Hashtable.java
Index: java/util/Hashtable.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/util/Hashtable.java,v
retrieving revision 1.21
diff -u -r1.21 Hashtable.java
--- java/util/Hashtable.java 22 Jan 2002 22:27:01 -0000 1.21
+++ java/util/Hashtable.java 15 Feb 2002 10:18:28 -0000
@@ -274,8 +274,11 @@
* Returns the number of key-value mappings currently in this hashtable.
* @return the size
*/
- public synchronized int size()
+ public int size()
{
+ /* This method does not need to be synchronized
+ * because accessing an integer field is atomic.
+ */
return size;
}
@@ -283,8 +286,11 @@
* Returns true if there are no key-value mappings currently in this table.
* @return <code>size() == 0</code>
*/
- public synchronized boolean isEmpty()
+ public boolean isEmpty()
{
+ /* This method does not need to be synchronized
+ * because accessing an integer field is atomic.
+ */
return size == 0;
}
- java.util.Hashtable.size()/isEmpty(),
Sascha Brawer <=
- Re: java.util.Hashtable.size()/isEmpty(), Dalibor Topic, 2002/02/15
- Re: java.util.Hashtable.size()/isEmpty(), Artur Biesiadowski, 2002/02/15
- Re: java.util.Hashtable.size()/isEmpty(), Etienne M. Gagnon, 2002/02/15
- Re: java.util.Hashtable.size()/isEmpty(), Artur Biesiadowski, 2002/02/15
- Re: java.util.Hashtable.size()/isEmpty(), Etienne M. Gagnon, 2002/02/15
- Re: java.util.Hashtable.size()/isEmpty(), Etienne M. Gagnon, 2002/02/15
- Re: java.util.Hashtable.size()/isEmpty(), Sascha Brawer, 2002/02/15
- Re: java.util.Hashtable.size()/isEmpty(), Jeff Sturm, 2002/02/15
- Re: java.util.Hashtable.size()/isEmpty(), Artur Biesiadowski, 2002/02/15
- Re: java.util.Hashtable.size()/isEmpty(), Bryce McKinlay, 2002/02/15