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

Side by Side Diff: tools/dom/src/native_DOMImplementation.dart

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:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sdk/lib/html/dartium/html_dartium.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 part of html; 5 part of html;
6 6
7 class _ConsoleVariables { 7 class _ConsoleVariables {
8 Map<String, Object> _data = new Map<String, Object>(); 8 Map<String, Object> _data = new Map<String, Object>();
9 9
10 /** 10 /**
(...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after
523 523
524 final _forwardingPrintClosure = _Utils.forwardingPrint; 524 final _forwardingPrintClosure = _Utils.forwardingPrint;
525 525
526 final _uriBaseClosure = () => Uri.parse(window.location.href); 526 final _uriBaseClosure = () => Uri.parse(window.location.href);
527 527
528 final _pureIsolateUriBaseClosure = () { 528 final _pureIsolateUriBaseClosure = () {
529 throw new UnimplementedError("Uri.base on a background isolate " 529 throw new UnimplementedError("Uri.base on a background isolate "
530 "is not supported in the browser"); 530 "is not supported in the browser");
531 }; 531 };
532 532
533 class _Timer implements Timer { 533 class _Timer implements Timer {
534 var _canceler; 534 const int _STATE_TIMEOUT = 0;
535 const int _STATE_INTERVAL = 1;
536 var _state;
535 537
536 _Timer(int milliSeconds, void callback(Timer timer), bool repeating) { 538 _Timer(int milliSeconds, void callback(Timer timer), bool repeating) {
537
538 if (repeating) { 539 if (repeating) {
539 int id = window._setInterval(() { 540 _state = window._setInterval(() {
540 callback(this); 541 callback(this);
541 }, milliSeconds); 542 }, milliSeconds) * 2 + _STATE_INTERVAL;
542 _canceler = () => window._clearInterval(id);
543 } else { 543 } else {
544 int id = window._setTimeout(() { 544 _state = window._setTimeout(() {
545 _canceler = null; 545 _state = null;
546 callback(this); 546 callback(this);
547 }, milliSeconds); 547 }, milliSeconds) * 2 + _STATE_TIMEOUT;
548 _canceler = () => window._clearTimeout(id);
549 } 548 }
550 } 549 }
551 550
552 void cancel() { 551 void cancel() {
553 if (_canceler != null) { 552 if (_state == null) return;
554 _canceler(); 553 int id = _state ~/ 2;
554 if ((_state & 1) == _STATE_TIMEOUT) {
555 window._clearTimeout(id);
556 } else {
557 window._clearInterval(id);
555 } 558 }
556 _canceler = null; 559 _state = null;
557 } 560 }
558 561
559 bool get isActive => _canceler != null; 562 bool get isActive => _state != null;
560 } 563 }
561 564
562 get _timerFactoryClosure => 565 get _timerFactoryClosure =>
563 (int milliSeconds, void callback(Timer timer), bool repeating) { 566 (int milliSeconds, void callback(Timer timer), bool repeating) {
564 return new _Timer(milliSeconds, callback, repeating); 567 return new _Timer(milliSeconds, callback, repeating);
565 }; 568 };
566 569
567 get _pureIsolateTimerFactoryClosure => 570 get _pureIsolateTimerFactoryClosure =>
568 ((int milliSeconds, void callback(Timer time), bool repeating) => 571 ((int milliSeconds, void callback(Timer time), bool repeating) =>
569 throw new UnimplementedError("Timers on background isolates " 572 throw new UnimplementedError("Timers on background isolates "
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
609 _scheduleImmediateHelper._schedule(callback); 612 _scheduleImmediateHelper._schedule(callback);
610 }; 613 };
611 614
612 get _pureIsolateScheduleImmediateClosure => ((void callback()) => 615 get _pureIsolateScheduleImmediateClosure => ((void callback()) =>
613 throw new UnimplementedError("scheduleMicrotask in background isolates " 616 throw new UnimplementedError("scheduleMicrotask in background isolates "
614 "are not supported in the browser")); 617 "are not supported in the browser"));
615 618
616 void _initializeCustomElement(Element e) { 619 void _initializeCustomElement(Element e) {
617 _Utils.initializeCustomElement(e); 620 _Utils.initializeCustomElement(e);
618 } 621 }
OLDNEW
« 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