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

Unified Diff: sdk/lib/html/dart2js/html_dart2js.dart

Side-by-side diff isn't available for this file because of its large size.
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:
Download patch
« no previous file with comments | « no previous file | tools/dom/src/dart2js_CssClassSet.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/html/dart2js/html_dart2js.dart
diff --git a/sdk/lib/html/dart2js/html_dart2js.dart b/sdk/lib/html/dart2js/html_dart2js.dart
index 0b5432789ddd28fb5cdf95bda9296c680479ec6f..898af6c54847cf0d5158a5ca3610b99c679bea0c 100644
--- a/sdk/lib/html/dart2js/html_dart2js.dart
+++ b/sdk/lib/html/dart2js/html_dart2js.dart
@@ -36878,16 +36878,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;
}
@@ -36961,7 +36960,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 | « no previous file | tools/dom/src/dart2js_CssClassSet.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698