Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1302)

Unified Diff: tools/dom/src/dart2js_CssClassSet.dart

Issue 1092553002: Improve CssClassSet add / remove (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sdk/lib/html/dart2js/html_dart2js.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/dom/src/dart2js_CssClassSet.dart
diff --git a/tools/dom/src/dart2js_CssClassSet.dart b/tools/dom/src/dart2js_CssClassSet.dart
index cf5fa33660748dc256431f16a4a2704dcf39ccc8..8d483b34dc2c1008bae87baa7e35e550d874da49 100644
--- a/tools/dom/src/dart2js_CssClassSet.dart
+++ b/tools/dom/src/dart2js_CssClassSet.dart
@@ -142,16 +142,15 @@ class _ElementCssClassSet extends CssClassSetImpl {
static bool _add(Element _element, String value) {
DomTokenList list = _classListOf(_element);
- // Compute returned result independently of action upon the set. One day we
- // will be able to optimize it way if unused.
- bool added = !_classListContains(list, value);
+ // Compute returned result independently of action upon the set.
+ bool added = !_classListContainsBeforeAddOrRemove(list, value);
_classListAdd(list, value);
return added;
}
static bool _remove(Element _element, String value) {
DomTokenList list = _classListOf(_element);
- bool removed = _classListContains(list, value);
+ bool removed = _classListContainsBeforeAddOrRemove(list, value);
_classListRemove(list, value);
return removed;
}
@@ -225,7 +224,17 @@ class _ElementCssClassSet extends CssClassSetImpl {
JS('returns:JSUInt31;effects:none;depends:all;', '#.length', list);
static bool _classListContains(DomTokenList list, String value) =>
- JS('returns:bool;effects:none;depends:all;',
+ JS('returns:bool;effects:none;depends:all',
+ '#.contains(#)', list, value);
+
+ static bool _classListContainsBeforeAddOrRemove(
+ DomTokenList list, String value) =>
+ // 'throws:never' is a lie, since 'contains' will throw on an illegal
+ // token. However, we always call this function immediately prior to
+ // add/remove/toggle with the same token. Often the result of 'contains'
+ // is unused and the lie makes it possible for the 'contains' instruction
+ // to be removed.
+ JS('returns:bool;effects:none;depends:all;throws:null(1)',
'#.contains(#)', list, value);
static void _classListAdd(DomTokenList list, String value) {
« no previous file with comments | « sdk/lib/html/dart2js/html_dart2js.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698