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

Unified Diff: sdk/lib/html/dartium/html_dartium.dart

Side-by-side diff isn't available for this file because of its large size.
Issue 108213003: 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: Reapply with typo fixed. 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:
Download patch
« no previous file with comments | « no previous file | tools/dom/src/native_DOMImplementation.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/html/dartium/html_dartium.dart
diff --git a/sdk/lib/html/dartium/html_dartium.dart b/sdk/lib/html/dartium/html_dartium.dart
index 29a417ad3c74a7c287a970a80822a308d7bde81f..9b787e4f2baa09321a6697f220ddb7a412ad4c1a 100644
--- a/sdk/lib/html/dartium/html_dartium.dart
+++ b/sdk/lib/html/dartium/html_dartium.dart
@@ -37039,33 +37039,36 @@ final _pureIsolateUriBaseClosure = () {
"is not supported in the browser");
};
- class _Timer implements Timer {
- var _canceler;
+class _Timer implements Timer {
+ const int _STATE_TIMEOUT = 0;
+ const int _STATE_INTERVAL = 1;
+ var _state;
_Timer(int milliSeconds, void callback(Timer timer), bool repeating) {
-
if (repeating) {
- int id = window._setInterval(() {
+ _state = window._setInterval(() {
callback(this);
- }, milliSeconds);
- _canceler = () => window._clearInterval(id);
+ }, milliSeconds) * 2 + _STATE_INTERVAL;
} else {
- int id = window._setTimeout(() {
- _canceler = null;
+ _state = window._setTimeout(() {
+ _state = null;
callback(this);
- }, milliSeconds);
- _canceler = () => window._clearTimeout(id);
+ }, milliSeconds) * 2 + _STATE_TIMEOUT;
}
}
void cancel() {
- if (_canceler != null) {
- _canceler();
+ if (_state == null) return;
+ int id = _state ~/ 2;
+ if ((_state & 1) == _STATE_TIMEOUT) {
+ window._clearTimeout(id);
+ } else {
+ window._clearInterval(id);
}
- _canceler = null;
+ _state = null;
}
- bool get isActive => _canceler != null;
+ bool get isActive => _state != null;
}
get _timerFactoryClosure =>
« no previous file with comments | « no previous file | tools/dom/src/native_DOMImplementation.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698