From 5d4a786f4466ebcb06c36ed44f262c9e120a7273 Mon Sep 17 00:00:00 2001 From: Florian Loitsch Date: Mon, 10 Jul 2017 14:58:00 +0200 Subject: [PATCH] Revert "Don't use `LinkedList` in the core libraries anymore." This reverts commit fe17b5b2bc24454dd2f596d8ce6e2e7661e87f10. Review-Url: https://codereview.chromium.org/2974073002 . --- .../dart/resolver/inheritance_manager.dart | 2 +- runtime/lib/core_patch.dart | 1 + runtime/lib/regexp_patch.dart | 8 +- sdk/lib/internal/internal.dart | 1 - sdk/lib/internal/internal_sources.gypi | 1 - sdk/lib/internal/linked_list.dart | 123 ------------------ sdk/lib/io/io.dart | 9 +- tests/corelib/reg_exp_cache_test.dart | 19 --- 8 files changed, 14 insertions(+), 150 deletions(-) delete mode 100644 sdk/lib/internal/linked_list.dart delete mode 100644 tests/corelib/reg_exp_cache_test.dart diff --git a/pkg/analyzer/lib/src/dart/resolver/inheritance_manager.dart b/pkg/analyzer/lib/src/dart/resolver/inheritance_manager.dart index 1773241bea48..04c8f94d569f 100644 --- a/pkg/analyzer/lib/src/dart/resolver/inheritance_manager.dart +++ b/pkg/analyzer/lib/src/dart/resolver/inheritance_manager.dart @@ -370,7 +370,7 @@ class InheritanceManager { * overridden in the inheritance path (for which the type is in the path). * * @param chain the inheritance path that is built up as this method calls itself recursively, - * when this method is called an empty [Queue] should be provided + * when this method is called an empty [LinkedList] should be provided * @param currentType the current type in the inheritance path * @param memberName the name of the member that is being looked up the inheritance path */ diff --git a/runtime/lib/core_patch.dart b/runtime/lib/core_patch.dart index 1723f2af8a40..6000ffc06d7f 100644 --- a/runtime/lib/core_patch.dart +++ b/runtime/lib/core_patch.dart @@ -3,6 +3,7 @@ // BSD-style license that can be found in the LICENSE file. import "dart:async"; +import "dart:collection" show LinkedList, LinkedListEntry; import 'dart:convert' show ASCII, JSON; import "dart:isolate"; import "dart:math"; diff --git a/runtime/lib/regexp_patch.dart b/runtime/lib/regexp_patch.dart index 1533836dc5bf..5a6514527594 100644 --- a/runtime/lib/regexp_patch.dart +++ b/runtime/lib/regexp_patch.dart @@ -13,7 +13,7 @@ class RegExp { if (value == null) { if (_cache.length > _MAX_CACHE_SIZE) { _RegExpHashKey lastKey = _recentlyUsed.last; - _recentlyUsed.remove(lastKey); + lastKey.unlink(); _cache.remove(lastKey); } @@ -46,13 +46,13 @@ class RegExp { static const int _MAX_CACHE_SIZE = 256; static final Map<_RegExpHashKey, _RegExpHashValue> _cache = new HashMap<_RegExpHashKey, _RegExpHashValue>(); - static final internal.LinkedList<_RegExpHashKey> _recentlyUsed = - new internal.LinkedList<_RegExpHashKey>(); + static final LinkedList<_RegExpHashKey> _recentlyUsed = + new LinkedList<_RegExpHashKey>(); } // Represents both a key in the regular expression cache as well as its // corresponding entry in the LRU list. -class _RegExpHashKey extends internal.LinkedListEntry<_RegExpHashKey> { +class _RegExpHashKey extends LinkedListEntry<_RegExpHashKey> { final String pattern; final bool multiLine; final bool caseSensitive; diff --git a/sdk/lib/internal/internal.dart b/sdk/lib/internal/internal.dart index 4f47c5c96628..099c0ad1e887 100644 --- a/sdk/lib/internal/internal.dart +++ b/sdk/lib/internal/internal.dart @@ -15,7 +15,6 @@ part 'list.dart'; part 'print.dart'; part 'sort.dart'; part 'symbol.dart'; -part 'linked_list.dart'; // Powers of 10 up to 10^22 are representable as doubles. // Powers of 10 above that are only approximate due to lack of precission. diff --git a/sdk/lib/internal/internal_sources.gypi b/sdk/lib/internal/internal_sources.gypi index f655856fef33..15d25115a3a3 100644 --- a/sdk/lib/internal/internal_sources.gypi +++ b/sdk/lib/internal/internal_sources.gypi @@ -9,7 +9,6 @@ # The above file needs to be first as it lists the parts below. 'iterable.dart', 'list.dart', - 'linked_list.dart', 'print.dart', 'sort.dart', 'symbol.dart', diff --git a/sdk/lib/internal/linked_list.dart b/sdk/lib/internal/linked_list.dart deleted file mode 100644 index a63bed150f26..000000000000 --- a/sdk/lib/internal/linked_list.dart +++ /dev/null @@ -1,123 +0,0 @@ -// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -part of dart._internal; - -/// A rudimentary linked list. -class LinkedList> extends IterableBase { - T first; - T last; - int length = 0; - - bool get isEmpty => length == 0; - - /** - * Adds [newLast] to the end of this linked list. - */ - void add(T newLast) { - assert(newLast._next == null && newLast._previous == null); - if (last != null) { - assert(last._next == null); - last._next = newLast; - } else { - first = newLast; - } - newLast._previous = last; - last = newLast; - last._list = this; - length++; - } - - /** - * Adds [newFirst] to the beginning of this linked list. - */ - void addFirst(T newFirst) { - if (first != null) { - assert(first._previous == null); - first._previous = newFirst; - } else { - last = newFirst; - } - newFirst._next = first; - first = newFirst; - first._list = this; - length++; - } - - /** - * Removes the given [node] from this list. - * - * The entry must be in this linked list when this method is called. Also see - * [LinkedListEntry.unlink]. - */ - void remove(T node) { - assert(node._previous != null || node._next != null || length == 1); - length--; - if (node._previous == null) { - assert(identical(node, first)); - first = node._next; - } else { - node._previous._next = node._next; - } - if (node._next == null) { - assert(identical(node, last)); - last = node._previous; - } else { - node._next._previous = node._previous; - } - node._next = node._previous = null; - } - - Iterator get iterator => new _LinkedListIterator(this); -} - -class LinkedListEntry> { - T _next; - T _previous; - LinkedList _list; - - /** - * Unlinks the element from its linked list. - * - * The entry must be in a linked list when this method is called. - * This is equivalent to calling [LinkedList.remove] on the list this entry - * is currently in. - */ - void unlink() { - _list.remove(this); - } -} - -class _LinkedListIterator> implements Iterator { - /// The current element of the iterator. - // This field is writeable, but should only read by users of this class. - T current; - - /// The list the iterator iterates over. - /// - /// Set to [null] if the provided list was empty (indicating that there were - /// no entries to iterate over). - /// - /// Set to [null] as soon as [moveNext] was invoked (indicating that the - /// iterator has to work with [current] from now on. - LinkedList _list; - - _LinkedListIterator(this._list) { - if (_list.length == 0) _list = null; - } - - bool moveNext() { - // current is null if the iterator hasn't started iterating, or if the - // iteration is finished. In the first case, the [_list] field is not null. - if (current == null) { - if (_list == null) return false; - assert(_list.length > 0); - current = _list.first; - _list = null; - return true; - } - current = current._next; - return current != null; - } -} diff --git a/sdk/lib/io/io.dart b/sdk/lib/io/io.dart index 7ed48cca4741..9f98149cb19d 100644 --- a/sdk/lib/io/io.dart +++ b/sdk/lib/io/io.dart @@ -197,7 +197,14 @@ library dart.io; import 'dart:async'; import 'dart:_internal' hide Symbol; import 'dart:collection' - show HashMap, HashSet, Queue, ListQueue, UnmodifiableMapView; + show + HashMap, + HashSet, + Queue, + ListQueue, + LinkedList, + LinkedListEntry, + UnmodifiableMapView; import 'dart:convert'; import 'dart:developer' hide log; import 'dart:isolate'; diff --git a/tests/corelib/reg_exp_cache_test.dart b/tests/corelib/reg_exp_cache_test.dart deleted file mode 100644 index a5bc96cf65d0..000000000000 --- a/tests/corelib/reg_exp_cache_test.dart +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -// Runs several similar regexps in a loop to see if an internal cache works (at -// least in easy conditions). - -import "package:expect/expect.dart"; - -void main() { - for (int j = 1; j < 50; j++) { - for (int i = 0; i < 20 * j; i++) { - var regExp = new RegExp("foo$i"); - var match = regExp.firstMatch("foo$i"); - Expect.isNotNull(match); - Expect.equals("foo$i", match[0]); - } - } -}