Skip to content
This repository was archived by the owner on Feb 22, 2018. It is now read-only.

Commit 556ef5c

Browse files
committed
perf(compiler): 45x speedup. Cache the attribute keys.
1 parent b52323e commit 556ef5c

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

lib/core_dom/selector.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,14 @@ class _ElementSelector {
202202
return partialSelection;
203203
}
204204

205+
// A global cache for the _matchingKey RegExps. The size is bounded by
206+
// the number of attribute directive selectors used in the application.
207+
static var _matchingKeyCache = <String, RegExp>{};
208+
205209
String _matchingKey(Iterable<String> keys, String attrName) =>
206210
keys.firstWhere((key) =>
207-
new RegExp('^${key.replaceAll('*', r'[\w\-]+')}\$')
211+
_matchingKeyCache.putIfAbsent(key,
212+
() => new RegExp('^${key.replaceAll('*', r'[\w\-]+')}\$'))
208213
.hasMatch(attrName), orElse: () => null);
209214

210215
toString() => 'ElementSelector($name)';

0 commit comments

Comments
 (0)