Tom Tromey wrote:
>>>>>>"Eric" == Eric Blake <[EMAIL PROTECTED]> writes:
>>>>>>
>
>Eric> Modified files:
>Eric> . : AUTHORS ChangeLog
>Eric> java/util : HashMap.java Hashtable.java
>
>Eric> * java/util/Hashtable.java (contains): check for null
>Eric> (Hashtable(Map)): more efficient
>Eric> (clear): more efficient
>Eric> (clone): more efficient, by adding Entry.copy
>
>I think it is disputable whether these are really more efficient.
>
>I'm not too concerned with `clear'. In that case the new code may
>very well be more efficient. It is hard to say in a
>platform-independent way.
>
I don't agree with the change to 'clear'.
@@ -389,10 +400,7 @@
public synchronized void clear()
{
modCount++;
- for (int i=0; i < buckets.length; i++)
- {
- buckets[i] = null;
- }
+ buckets = new Entry[buckets.length];
size = 0;
}
Creating a whole new array is an expensive operation. In addition to the
cost of the allocation itself (typically this requires synchronization
on a global heap lock), it creates more garbage for the collector to
deal with (increasing GC frequency), and potentially uses more memory by
causing the heap to expand. In contrast, a small, tight loop like the
one above should execute very fast on any modern cpu (assuming a JIT and
taking cache behaviour into account), so unless buckets.length is very
large, its hard to imagine that it could be less efficient.
Any contradictory opinions?
regards
Bryce.
_______________________________________________
Classpath mailing list
[EMAIL PROTECTED]
http://mail.gnu.org/mailman/listinfo/classpath