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

Side by Side 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 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 const int _STATE_TIMEOUT = 0; 534 var _canceler;
535 const int _STATE_INTERVAL = 1;
536 var _state;
537 535
538 _Timer(int milliSeconds, void callback(Timer timer), bool repeating) { 536 _Timer(int milliSeconds, void callback(Timer timer), bool repeating) {
537
539 if (repeating) { 538 if (repeating) {
540 _state = window._setInterval(() { 539 int id = window._setInterval(() {
541 callback(this); 540 callback(this);
542 }, milliSeconds) * 2 + _STATE_INTERVAL; 541 }, milliSeconds);
542 _canceler = () => window._clearInterval(id);
543 } else { 543 } else {
544 _state = window._setTimeout(() { 544 int id = window._setTimeout(() {
545 _state = null; 545 _canceler = null;
546 callback(this); 546 callback(this);
547 }, milliSeconds) * 2 + _STATE_TIMEOUT; 547 }, milliSeconds);
548 _canceler = () => window._clearTimeout(id);
548 } 549 }
549 } 550 }
550 551
551 void cancel() { 552 void cancel() {
552 if (_state == null) return; 553 if (_canceler != null) {
553 int id = _state ~/ 2; 554 _canceler();
554 if ((_state & 1) == _STATE_TIMEOUT) {
555 window._clearTimeout(id);
556 } else {
557 window._clearInterval(id);
558 } 555 }
559 _state = null; 556 _canceler = null;
560 } 557 }
561 558
562 bool get isActive => _state != null; 559 bool get isActive => _canceler != null;
563 } 560 }
564 561
565 get _timerFactoryClosure => 562 get _timerFactoryClosure =>
566 (int milliSeconds, void callback(Timer timer), bool repeating) { 563 (int milliSeconds, void callback(Timer timer), bool repeating) {
567 return new _Timer(milliSeconds, callback, repeating); 564 return new _Timer(milliSeconds, callback, repeating);
568 }; 565 };
569 566
570 get _pureIsolateTimerFactoryClosure => 567 get _pureIsolateTimerFactoryClosure =>
571 ((int milliSeconds, void callback(Timer time), bool repeating) => 568 ((int milliSeconds, void callback(Timer time), bool repeating) =>
572 throw new UnimplementedError("Timers on background isolates " 569 throw new UnimplementedError("Timers on background isolates "
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
612 _scheduleImmediateHelper._schedule(callback); 609 _scheduleImmediateHelper._schedule(callback);
613 }; 610 };
614 611
615 get _pureIsolateScheduleImmediateClosure => ((void callback()) => 612 get _pureIsolateScheduleImmediateClosure => ((void callback()) =>
616 throw new UnimplementedError("scheduleMicrotask in background isolates " 613 throw new UnimplementedError("scheduleMicrotask in background isolates "
617 "are not supported in the browser")); 614 "are not supported in the browser"));
618 615
619 void _initializeCustomElement(Element e) { 616 void _initializeCustomElement(Element e) {
620 _Utils.initializeCustomElement(e); 617 _Utils.initializeCustomElement(e);
621 } 618 }
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