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

Side by Side Diff: sdk/lib/io/timer_impl.dart

Issue 106103007: If a new timer is the last timer to time out, don't run through the entire list of timers. (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 | « no previous file | 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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 dart.io; 5 part of dart.io;
6 6
7 class _Timer extends LinkedListEntry<_Timer> implements Timer { 7 class _Timer extends LinkedListEntry<_Timer> implements Timer {
8 // Disables the timer. 8 // Disables the timer.
9 static const int _NO_TIMER = -1; 9 static const int _NO_TIMER = -1;
10 10
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 72
73 void _advanceWakeupTime() { 73 void _advanceWakeupTime() {
74 assert(_milliSeconds >= 0); 74 assert(_milliSeconds >= 0);
75 _wakeupTime += _milliSeconds; 75 _wakeupTime += _milliSeconds;
76 } 76 }
77 77
78 // Adds a timer to the timer list. Timers with the same wakeup time are 78 // Adds a timer to the timer list. Timers with the same wakeup time are
79 // enqueued in order and notified in FIFO order. 79 // enqueued in order and notified in FIFO order.
80 void _addTimerToList() { 80 void _addTimerToList() {
81 _Timer entry = _timers.isEmpty ? null : _timers.first; 81 _Timer entry = _timers.isEmpty ? null : _timers.first;
82 // If timer is last, add to end.
83 if (entry == null || _timers.last._wakeupTime <= _wakeupTime) {
84 _timers.add(this);
85 return;
86 }
87 // Otherwise scan through and find the right position.
82 while (entry != null) { 88 while (entry != null) {
83 if (_wakeupTime < entry._wakeupTime) { 89 if (_wakeupTime < entry._wakeupTime) {
84 entry.insertBefore(this); 90 entry.insertBefore(this);
85 return; 91 return;
86 } 92 }
87 entry = entry.next; 93 entry = entry.next;
88 } 94 }
89 _timers.add(this); 95 _timers.add(this);
90 } 96 }
91 97
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 _getTimerFactoryClosure() { 188 _getTimerFactoryClosure() {
183 return (int milliSeconds, void callback(Timer timer), bool repeating) { 189 return (int milliSeconds, void callback(Timer timer), bool repeating) {
184 if (repeating) { 190 if (repeating) {
185 return new _Timer.periodic(milliSeconds, callback); 191 return new _Timer.periodic(milliSeconds, callback);
186 } 192 }
187 return new _Timer(milliSeconds, callback); 193 return new _Timer(milliSeconds, callback);
188 }; 194 };
189 } 195 }
190 196
191 197
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698