From: Jean Privat Date: Fri, 19 Feb 2016 15:34:15 +0000 (-0500) Subject: lib/core/collection: improve the default `has_all` for basic cases X-Git-Url: http://nitlanguage.org lib/core/collection: improve the default `has_all` for basic cases Signed-off-by: Jean Privat --- diff --git a/lib/core/collection/abstract_collection.nit b/lib/core/collection/abstract_collection.nit index 5f9af05..e17ecfa 100644 --- a/lib/core/collection/abstract_collection.nit +++ b/lib/core/collection/abstract_collection.nit @@ -149,6 +149,12 @@ interface Collection[E] # It is memory-efficient but relies on `has` so may be CPU-inefficient for some kind of collections. fun has_all(other: Collection[nullable Object]): Bool do + if is_same_instance(other) then return true + var ol = other.length + var l = length + if ol == 0 then return true + if l == 0 then return false + if ol == 1 then return has(other.first) for x in other do if not has(x) then return false return true end