Conversation
| if (hashCode == null) { | ||
| synchronized (delegate) { | ||
| if (hashCode == null) { | ||
| hashCode = delegate.hashCode(); | ||
| } | ||
| } | ||
| } | ||
| return hashCode; |
There was a problem hiding this comment.
i would probably use the simple "racy" version of this similar like it used to be:
this should be safe since:
- doc requires managers to be stateless, I assume this means all maps are immutable
- this will be likely only used from one thread
- race condition would not be a big deal since all it would to is to introduce a chance that the value is computed more than once under high contention
There was a problem hiding this comment.
I have other idea, will add done() method....
mbien
left a comment
There was a problem hiding this comment.
makes sense to me, left one comment.
| public MMap<K, V> done() { | ||
| return new DoneMMap<>(delegate); | ||
| } |
There was a problem hiding this comment.
return this instanceof DoneMMap ? this : new DoneMMap<>(delegate);
}otherwise this would keep copying the maps even if nothing changed.
There was a problem hiding this comment.
but done method is overridden in DoneMMap? I don't get it
There was a problem hiding this comment.
wait maybe I am wrong here - this likely can't happen since done() of the frozen instance is a no-op
This reverts commit 5c0e574.
|
it will copy the map twice now though. first: second later: which will hit the same copy constructor again. |
|
As graph is growing, same instances of HashMaps are repeatedly asked for hashCode, that in default implementation goes over all keys and values over and over again.
Changes: