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

Commit

Permalink
perf(compiler): 45x speedup. Cache the attribute keys.
Browse files Browse the repository at this point in the history
  • Loading branch information
jbdeboer committed Apr 3, 2014
1 parent b52323e commit 556ef5c
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/core_dom/selector.dart
Expand Up @@ -202,9 +202,14 @@ class _ElementSelector {
return partialSelection;
}

// A global cache for the _matchingKey RegExps. The size is bounded by
// the number of attribute directive selectors used in the application.
static var _matchingKeyCache = <String, RegExp>{};

String _matchingKey(Iterable<String> keys, String attrName) =>
keys.firstWhere((key) =>
new RegExp('^${key.replaceAll('*', r'[\w\-]+')}\$')
_matchingKeyCache.putIfAbsent(key,
() => new RegExp('^${key.replaceAll('*', r'[\w\-]+')}\$'))
.hasMatch(attrName), orElse: () => null);

toString() => 'ElementSelector($name)';
Expand Down

0 comments on commit 556ef5c

Please sign in to comment.