nitlanguage
/
nit.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
7b8fc94
)
lib/core/collection: improve the default `has_all` for basic cases
author
Jean Privat
<jean@pryen.org>
Fri, 19 Feb 2016 15:34:15 +0000
(10:34 -0500)
committer
Jean 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
patch
|
blob
|
history
diff --git
a/lib/core/collection/abstract_collection.nit
b/lib/core/collection/abstract_collection.nit
index
5f9af05
..
e17ecfa
100644
(file)
--- 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