From: Jean Privat Date: Tue, 20 Oct 2015 00:04:11 +0000 (-0400) Subject: core::hash_collection: do not allocate the storage, wait for the first `store`. X-Git-Tag: v0.7.9~22^2~3 X-Git-Url: http://nitlanguage.org core::hash_collection: do not allocate the storage, wait for the first `store`. Signed-off-by: Jean Privat --- diff --git a/lib/core/collection/hash_collection.nit b/lib/core/collection/hash_collection.nit index 930c371..1a27991 100644 --- a/lib/core/collection/hash_collection.nit +++ b/lib/core/collection/hash_collection.nit @@ -257,6 +257,7 @@ class HashMap[K, V] redef fun []=(key, v) do + if _capacity == 0 then enlarge(17) # 17 because magic in `store` var i = index_at(key) var c = node_at_idx(i, key) if c != null then @@ -273,7 +274,6 @@ class HashMap[K, V] do _capacity = 0 _the_length = 0 - enlarge(0) end redef var keys: RemovableCollection[K] = new HashMapKeys[K, V](self) is lazy @@ -446,6 +446,7 @@ class HashSet[E] redef fun add(item) do + if _capacity == 0 then enlarge(17) # 17 because magic in `store` var i = index_at(item) var c = node_at_idx(i, item) if c != null then @@ -465,7 +466,6 @@ class HashSet[E] do _capacity = 0 _the_length = 0 - enlarge(0) end # Build a list filled with the items of `coll`.