From 7ed14551b622de9dde65d41722c91b4c9b90cea2 Mon Sep 17 00:00:00 2001 From: Jean Privat Date: Mon, 19 Oct 2015 20:04:11 -0400 Subject: [PATCH] core::hash_collection: do not allocate the storage, wait for the first `store`. Signed-off-by: Jean Privat --- lib/core/collection/hash_collection.nit | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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`. -- 1.7.9.5