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

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

Issue 110233002: Reapply "Reduce footprint of HTML Timer by not creating a "cancel" closure." (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years 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/dartium/html_dartium.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/native_DOMImplementation.dart
diff --git a/tools/dom/src/native_DOMImplementation.dart b/tools/dom/src/native_DOMImplementation.dart
index d4ed796b16201c2d1f1134cdffc56c21ab9959f3..e54cc11752fab6f3ffdae5ef74a1b89207ac1e94 100644
--- a/tools/dom/src/native_DOMImplementation.dart
+++ b/tools/dom/src/native_DOMImplementation.dart
@@ -530,36 +530,33 @@ final _pureIsolateUriBaseClosure = () {
"is not supported in the browser");
};
-class _Timer implements Timer {
- const int _STATE_TIMEOUT = 0;
- const int _STATE_INTERVAL = 1;
- var _state;
+ class _Timer implements Timer {
+ var _canceler;
_Timer(int milliSeconds, void callback(Timer timer), bool repeating) {
+
if (repeating) {
- _state = window._setInterval(() {
+ int id = window._setInterval(() {
callback(this);
- }, milliSeconds) * 2 + _STATE_INTERVAL;
+ }, milliSeconds);
+ _canceler = () => window._clearInterval(id);
} else {
- _state = window._setTimeout(() {
- _state = null;
+ int id = window._setTimeout(() {
+ _canceler = null;
callback(this);
- }, milliSeconds) * 2 + _STATE_TIMEOUT;
+ }, milliSeconds);
+ _canceler = () => window._clearTimeout(id);
}
}
void cancel() {
- if (_state == null) return;
- int id = _state ~/ 2;
- if ((_state & 1) == _STATE_TIMEOUT) {
- window._clearTimeout(id);
- } else {
- window._clearInterval(id);
+ if (_canceler != null) {
+ _canceler();
}
- _state = null;
+ _canceler = null;
}
- bool get isActive => _state != null;
+ bool get isActive => _canceler != null;
}
get _timerFactoryClosure =>
« no previous file with comments | « sdk/lib/html/dartium/html_dartium.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698