Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 43 _Timer._internal() {} | 43 _Timer._internal() {} |
| 44 | 44 |
| 45 void _clear() { | 45 void _clear() { |
| 46 _callback = null; | 46 _callback = null; |
| 47 _milliSeconds = 0; | 47 _milliSeconds = 0; |
| 48 _wakeupTime = 0; | 48 _wakeupTime = 0; |
| 49 } | 49 } |
| 50 | 50 |
| 51 bool get _repeating => _milliSeconds >= 0; | 51 bool get _repeating => _milliSeconds >= 0; |
| 52 | 52 |
| 53 bool get _isActive => _timers.contains(this); | |
|
floitsch
2013/07/01 12:49:43
contains is a linear operation.
Reuse _callback in
zarah
2013/07/01 16:15:35
Done.
| |
| 54 | |
| 53 | 55 |
| 54 // Cancels a set timer. The timer is removed from the timer list and if | 56 // Cancels a set timer. The timer is removed from the timer list and if |
| 55 // the given timer is the earliest timer the native timer is reset. | 57 // the given timer is the earliest timer the native timer is reset. |
| 56 void cancel() { | 58 void cancel() { |
| 57 _clear(); | 59 _clear(); |
| 58 // Return if already canceled. | 60 // Return if already canceled. |
| 59 if (list == null) return; | 61 if (list == null) return; |
| 60 assert(!_timers.isEmpty); | 62 assert(!_timers.isEmpty); |
| 61 _Timer first = _timers.first; | 63 _Timer first = _timers.first; |
| 62 unlink(); | 64 unlink(); |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 176 _getTimerFactoryClosure() { | 178 _getTimerFactoryClosure() { |
| 177 return (int milliSeconds, void callback(Timer timer), bool repeating) { | 179 return (int milliSeconds, void callback(Timer timer), bool repeating) { |
| 178 if (repeating) { | 180 if (repeating) { |
| 179 return new _Timer.periodic(milliSeconds, callback); | 181 return new _Timer.periodic(milliSeconds, callback); |
| 180 } | 182 } |
| 181 return new _Timer(milliSeconds, callback); | 183 return new _Timer(milliSeconds, callback); |
| 182 }; | 184 }; |
| 183 } | 185 } |
| 184 | 186 |
| 185 | 187 |
| OLD | NEW |