Move us to HashSet to avoid the overhead of tracking the order

This commit is contained in:
Ian Hickson 2016-01-19 09:31:57 -08:00
parent b9716b84db
commit 5494323db9
13 changed files with 39 additions and 31 deletions

View file

@ -5,6 +5,7 @@
library stocks;
import 'dart:async';
import 'dart:collection';
import 'dart:math' as math;
import 'dart:ui' as ui;

View file

@ -203,7 +203,7 @@ class StockHomeState extends State<StockHome> {
stocks: stocks.toList(),
onAction: _buyStock,
onOpen: (Stock stock, Key arrowKey) {
Set<Key> mostValuableKeys = new Set<Key>();
Set<Key> mostValuableKeys = new HashSet<Key>();
mostValuableKeys.add(arrowKey);
Navigator.pushNamed(context, '/stock/${stock.symbol}', mostValuableKeys: mostValuableKeys);
},

View file

@ -5,6 +5,7 @@
/// An implementation of the Cassowary constraint solving algorithm in Dart.
library cassowary;
import 'dart:collection';
import 'dart:math';
part 'constraint.dart';

View file

@ -146,13 +146,11 @@ class Solver {
Result removeEditVariable(Variable variable) {
_EditInfo info = _edits[variable];
if (info == null) {
if (info == null)
return Result.unknownEditVariable;
}
if (removeConstraint(info.constraint) != Result.success) {
if (removeConstraint(info.constraint) != Result.success)
return Result.internalSolverError;
}
_edits.remove(variable);
return Result.success;
@ -173,7 +171,7 @@ class Solver {
}
Set flushUpdates() {
Set updates = new Set();
Set updates = new HashSet<dynamic>();
for (Variable variable in _vars.keys) {
_Symbol symbol = _vars[variable];
@ -183,10 +181,8 @@ class Solver {
if (variable._applyUpdate(updatedValue) && variable._owner != null) {
dynamic context = variable._owner.context;
if (context != null) {
if (context != null)
updates.add(context);
}
}
}
@ -212,9 +208,8 @@ class Solver {
}
if (needsCleanup) {
for (dynamic item in applied.reversed) {
for (dynamic item in applied.reversed)
undoer(item);
}
}
return result;
@ -223,9 +218,8 @@ class Solver {
_Symbol _symbolForVariable(Variable variable) {
_Symbol symbol = _vars[variable];
if (symbol != null) {
if (symbol != null)
return symbol;
}
symbol = new _Symbol(_SymbolType.external, tick++);
_vars[variable] = symbol;

View file

@ -3,6 +3,7 @@
// found in the LICENSE file.
import 'dart:async';
import 'dart:collection';
import 'dart:ui' show Point, Offset;
import 'arena.dart';
@ -43,7 +44,7 @@ abstract class OneSequenceGestureRecognizer extends GestureRecognizer {
GestureArena _gestureArena;
final List<GestureArenaEntry> _entries = <GestureArenaEntry>[];
final Set<int> _trackedPointers = new Set<int>();
final Set<int> _trackedPointers = new HashSet<int>();
void handleEvent(PointerEvent event);
void acceptGesture(int pointer) { }

View file

@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:collection';
import 'package:flutter/gestures.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart';
@ -85,7 +87,7 @@ class _InkResponseState<T extends InkResponse> extends State<T> {
} // else we're probably in deactivate()
}
);
_splashes ??= new Set<InkSplash>();
_splashes ??= new HashSet<InkSplash>();
_splashes.add(splash);
_currentSplash = splash;
updateHighlight(true);

View file

@ -3,6 +3,7 @@
// found in the LICENSE file.
import 'dart:async';
import 'dart:collection';
import 'dart:developer';
import 'dart:ui' as ui;
@ -142,7 +143,7 @@ abstract class Scheduler extends BindingBase {
int _nextFrameCallbackId = 0; // positive
Map<int, FrameCallback> _transientCallbacks = <int, FrameCallback>{};
final Set<int> _removedIds = new Set<int>();
final Set<int> _removedIds = new HashSet<int>();
int get transientCallbackCount => _transientCallbacks.length;

View file

@ -81,7 +81,7 @@ abstract class GlobalKey<T extends State<StatefulComponent>> extends Key {
static final Map<GlobalKey, Element> _registry = new Map<GlobalKey, Element>();
static final Map<GlobalKey, int> _debugDuplicates = new Map<GlobalKey, int>();
static final Map<GlobalKey, Set<GlobalKeyRemoveListener>> _removeListeners = new Map<GlobalKey, Set<GlobalKeyRemoveListener>>();
static final Set<GlobalKey> _removedKeys = new Set<GlobalKey>();
static final Set<GlobalKey> _removedKeys = new HashSet<GlobalKey>();
void _register(Element element) {
assert(() {
@ -129,7 +129,7 @@ abstract class GlobalKey<T extends State<StatefulComponent>> extends Key {
static void registerRemoveListener(GlobalKey key, GlobalKeyRemoveListener listener) {
assert(key != null);
Set<GlobalKeyRemoveListener> listeners =
_removeListeners.putIfAbsent(key, () => new Set<GlobalKeyRemoveListener>());
_removeListeners.putIfAbsent(key, () => new HashSet<GlobalKeyRemoveListener>());
bool added = listeners.add(listener);
assert(added);
}
@ -160,7 +160,7 @@ abstract class GlobalKey<T extends State<StatefulComponent>> extends Key {
try {
for (GlobalKey key in _removedKeys) {
if (!_registry.containsKey(key) && _removeListeners.containsKey(key)) {
Set<GlobalKeyRemoveListener> localListeners = new Set<GlobalKeyRemoveListener>.from(_removeListeners[key]);
Set<GlobalKeyRemoveListener> localListeners = new HashSet<GlobalKeyRemoveListener>.from(_removeListeners[key]);
for (GlobalKeyRemoveListener listener in localListeners)
listener(key);
}
@ -524,7 +524,7 @@ enum _ElementLifecycle {
class _InactiveElements {
bool _locked = false;
final Set<Element> _elements = new Set<Element>();
final Set<Element> _elements = new HashSet<Element>();
void _unmount(Element element) {
assert(element._debugLifecycleState == _ElementLifecycle.inactive);
@ -897,7 +897,7 @@ abstract class Element<T extends Widget> implements BuildContext {
ancestor = ancestor._parent;
if (ancestor != null) {
assert(ancestor is InheritedElement);
_dependencies ??= new Set<InheritedElement>();
_dependencies ??= new HashSet<InheritedElement>();
_dependencies.add(ancestor);
InheritedElement typedAncestor = ancestor;
typedAncestor._dependants.add(this);
@ -1378,7 +1378,7 @@ class ParentDataElement extends _ProxyElement<ParentDataWidget> {
class InheritedElement extends _ProxyElement<InheritedWidget> {
InheritedElement(InheritedWidget widget) : super(widget);
Set<Element> _dependants = new Set<Element>();
Set<Element> _dependants = new HashSet<Element>();
void debugDeactivated() {
assert(() {

View file

@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:collection';
import 'package:flutter/animation.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/scheduler.dart';
@ -98,7 +100,7 @@ class Hero extends StatefulComponent {
final bool alwaysAnimate;
static Map<Object, HeroHandle> of(BuildContext context, Set<Key> mostValuableKeys) {
mostValuableKeys ??= new Set<Key>();
mostValuableKeys ??= new HashSet<Key>();
assert(!mostValuableKeys.contains(null));
// first we collect ALL the heroes, sorted by their tags
Map<Object, Map<Key, HeroState>> heroes = <Object, Map<Key, HeroState>>{};
@ -177,7 +179,7 @@ class HeroState extends State<Hero> implements HeroHandle {
_HeroManifest result = new _HeroManifest(
key: _key,
config: config,
sourceStates: new Set<HeroState>.from(<HeroState>[this]),
sourceStates: new HashSet<HeroState>.from(<HeroState>[this]),
currentRect: startRect,
currentTurns: config.turns.toDouble()
);
@ -268,7 +270,7 @@ class _HeroQuestState implements HeroHandle {
_taken = true;
Set<HeroState> states = sourceStates;
if (targetState != null)
states = states.union(new Set<HeroState>.from(<HeroState>[targetState]));
states = states.union(new HashSet<HeroState>.from(<HeroState>[targetState]));
return new _HeroManifest(
key: key,
config: child,
@ -351,7 +353,7 @@ class HeroParty {
assert(to == null || to.sourceStates.length == 1);
assert(to == null || to.currentTurns.floor() == to.currentTurns);
HeroState targetState = to != null ? to.sourceStates.elementAt(0) : null;
Set<HeroState> sourceStates = from != null ? from.sourceStates : new Set<HeroState>();
Set<HeroState> sourceStates = from != null ? from.sourceStates : new HashSet<HeroState>();
sourceStates.remove(targetState);
RelativeRect sourceRect = from != null ? from.currentRect :
new RelativeRect.fromRect(to.currentRect.toRect(animationArea).center & Size.zero, animationArea);
@ -489,7 +491,7 @@ class HeroController extends NavigatorObserver {
Set<Key> _getMostValuableKeys() {
assert(_from != null);
assert(_to != null);
Set<Key> result = new Set<Key>();
Set<Key> result = new HashSet<Key>();
if (_from.settings.mostValuableKeys != null)
result.addAll(_from.settings.mostValuableKeys);
if (_to.settings.mostValuableKeys != null)

View file

@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:collection';
import 'package:flutter/rendering.dart';
import 'framework.dart';
@ -97,7 +99,7 @@ class _MixedViewportElement extends RenderObjectElement<MixedViewport> {
Map<_ChildKey, Element> _childrenByKey = new Map<_ChildKey, Element>();
/// The child offsets that we've been told are invalid.
final Set<int> _invalidIndices = new Set<int>();
final Set<int> _invalidIndices = new HashSet<int>();
/// Returns false if any of the previously-cached offsets have been marked as
/// invalid and need to be updated.

View file

@ -2,13 +2,15 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:collection';
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/widgets.dart';
import 'package:test/test.dart';
final List<String> results = <String>[];
Set<TestRoute> routes = new Set<TestRoute>();
Set<TestRoute> routes = new HashSet<TestRoute>();
class TestRoute extends Route<String> {
TestRoute(this.name);

View file

@ -3,6 +3,7 @@
// found in the LICENSE file.
import 'dart:async';
import 'dart:collection';
import 'dart:convert';
import 'dart:io';
@ -31,7 +32,7 @@ class AnalyzeCommand extends FlutterCommand {
@override
Future<int> runInProject() async {
Stopwatch stopwatch = new Stopwatch()..start();
Set<String> pubSpecDirectories = new Set<String>();
Set<String> pubSpecDirectories = new HashSet<String>();
List<String> dartFiles = argResults.rest.toList();
bool foundAnyInCurrentDirectory = false;

View file

@ -3,6 +3,7 @@
// found in the LICENSE file.
import 'dart:async';
import 'dart:collection';
import 'dart:convert';
import 'dart:io';
import 'dart:isolate';
@ -32,7 +33,7 @@ class RemoteListener {
final Suite _suite;
final WebSocket _socket;
final Set<LiveTest> _liveTests = new Set<LiveTest>();
final Set<LiveTest> _liveTests = new HashSet<LiveTest>();
static Future start(String server, Metadata metadata, Function getMain()) async {
WebSocket socket = await WebSocket.connect(server);