contains method
- @override
override
Returns true if the collection contains an element equal to element
.
This operation will check each element in order for being equal to
element
, unless it has a more efficient way to find an element
equal to element
.
The equality used to determine whether element
is equal to an element of
the iterable defaults to the Object.== of the element.
Some types of iterable may have a different equality used for its elements.
For example, a Set may have a custom equality
(see Set.identity) that its contains
uses.
Likewise the Iterable
returned by a Map.keys call
should use the same equality that the Map
uses for keys.
Implementation
@override
bool contains(Object element) {
if (_list.length < 3)
return _list.contains(element);
if (_isDirty) {
if (_set == null) {
_set = HashSet<T>.from(_list);
} else {
_set.clear();
_set.addAll(_list);
}
_isDirty = false;
}
return _set.contains(element);
}