lib/standard: redef a fast path for `HashMap#get_or_null`
authorJean Privat <jean@pryen.org>
Tue, 3 Feb 2015 13:53:05 +0000 (20:53 +0700)
committerJean Privat <jean@pryen.org>
Tue, 3 Feb 2015 13:53:05 +0000 (20:53 +0700)
Signed-off-by: Jean Privat <jean@pryen.org>

lib/standard/collection/hash_collection.nit

index f4f218e..b62d876 100644 (file)
@@ -235,6 +235,16 @@ class HashMap[K, V]
                end
        end
 
+       redef fun get_or_null(key)
+       do
+               var c = node_at(key)
+               if c == null then
+                       return null
+               else
+                       return c._value
+               end
+       end
+
        redef fun iterator: HashMapIterator[K, V] do return new HashMapIterator[K,V](self)
 
        redef fun length do return _the_length