From 80e9c8707a940ae359ea66e67c0064d3f45ac5c2 Mon Sep 17 00:00:00 2001 From: Jean Privat Date: Tue, 26 Nov 2013 15:02:35 -0500 Subject: [PATCH] lib: add `Object::is_same_instance` that will replace `is` Signed-off-by: Jean Privat --- lib/standard/collection/hash_collection.nit | 4 ++-- lib/standard/kernel.nit | 8 ++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/standard/collection/hash_collection.nit b/lib/standard/collection/hash_collection.nit index 9a53f99..7f73c3b 100644 --- a/lib/standard/collection/hash_collection.nit +++ b/lib/standard/collection/hash_collection.nit @@ -44,7 +44,7 @@ private abstract class HashCollection[K: Object, N: HashNode[Object]] fun node_at(k: K): nullable N do # cache: `is` is used instead of `==` because it is a faster filter (even if not exact) - if k is _last_accessed_key then return _last_accessed_node + if k.is_same_instance(_last_accessed_key) then return _last_accessed_node var res = node_at_idx(index_at(k), k) _last_accessed_key = k @@ -58,7 +58,7 @@ private abstract class HashCollection[K: Object, N: HashNode[Object]] var c = _array[i] while c != null do var ck = c._key - if ck is k or ck == k then # prefilter with `is` because the compiler is not smart enought yet + if ck.is_same_instance(k) or ck == k then # FIXME prefilter because the compiler is not smart enought yet break end c = c._next_in_bucklet diff --git a/lib/standard/kernel.nit b/lib/standard/kernel.nit index bf158a3..bbc2b70 100644 --- a/lib/standard/kernel.nit +++ b/lib/standard/kernel.nit @@ -35,11 +35,15 @@ interface Object # Unless specific code, you should not use this method. fun is_same_type(other: Object): Bool is intern + # Return true if `self` and `other` are the same instance. + # Unless specific code, you should use `==` instead. + fun is_same_instance(other: nullable Object): Bool do return self is other #is intern + # Have `self` and `other` the same value? ## # The exact meaning of "same value" is let to the subclasses. - # Implicitly, the default implementation, is `is` - fun ==(other: nullable Object): Bool do return self is other + # Implicitly, the default implementation, is `is_same_instance` + fun ==(other: nullable Object): Bool do return self.is_same_instance(other) # Have `self` and `other` different values? ## -- 1.7.9.5