lib/core/collection: improve the default `has_all` for basic cases
authorJean Privat <jean@pryen.org>
Fri, 19 Feb 2016 15:34:15 +0000 (10:34 -0500)
committerJean Privat <jean@pryen.org>
Mon, 22 Feb 2016 13:50:46 +0000 (08:50 -0500)
Signed-off-by: Jean Privat <jean@pryen.org>

lib/core/collection/abstract_collection.nit

index 5f9af05..e17ecfa 100644 (file)
@@ -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