@@ -16,8 +16,11 @@ class ComparingOrderedSet<E> extends OrderedSet<E>
1616 // If the default implementation of `Set` changes from `LinkedHashSet` to
1717 // something else that isn't ordered we'll have to change this to explicitly
1818 // be `LinkedHashSet` (or some other data structure that preserves order).
19- late SplayTreeSet <Set <E >> _backingSet;
20- late int _length;
19+ late final SplayTreeSet <Set <E >> _backingSet = SplayTreeSet <LinkedHashSet <E >>(
20+ _outerComparator,
21+ );
22+ final int Function (E e1, E e2) _comparator;
23+ int _length = 0 ;
2124
2225 bool _validReverseCache = true ;
2326 Iterable <E > _reverseCache = const Iterable .empty ();
@@ -45,22 +48,7 @@ class ComparingOrderedSet<E> extends OrderedSet<E>
4548 ComparingOrderedSet ({
4649 int Function (E e1, E e2)? compare,
4750 this .strictMode = true ,
48- }) {
49- final comparator = compare ?? _defaultCompare <E >();
50- _backingSet = SplayTreeSet <LinkedHashSet <E >>((Set <E > l1, Set <E > l2) {
51- if (l1.isEmpty) {
52- if (l2.isEmpty) {
53- return 0 ;
54- }
55- return - 1 ;
56- }
57- if (l2.isEmpty) {
58- return 1 ;
59- }
60- return comparator (l1.first, l2.first);
61- });
62- _length = 0 ;
63- }
51+ }) : _comparator = compare ?? _defaultCompare <E >();
6452
6553 @override
6654 int get length => _length;
@@ -143,4 +131,17 @@ class ComparingOrderedSet<E> extends OrderedSet<E>
143131 _length = 0 ;
144132 onClear ();
145133 }
134+
135+ int _outerComparator (Set <E > l1, Set <E > l2) {
136+ if (l1.isEmpty) {
137+ if (l2.isEmpty) {
138+ return 0 ;
139+ }
140+ return - 1 ;
141+ }
142+ if (l2.isEmpty) {
143+ return 1 ;
144+ }
145+ return _comparator (l1.first, l2.first);
146+ }
146147}
0 commit comments