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

Unified Diff: sdk/lib/core/stopwatch.dart

Issue 12221073: Add Stopwatch.isRunning. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 10 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tests/corelib/stopwatch_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/core/stopwatch.dart
diff --git a/sdk/lib/core/stopwatch.dart b/sdk/lib/core/stopwatch.dart
index 7d8ce334cd1d1c8a748af7295813cb22d1bf7776..b446069f70c1ad298a441051ec28816114d9149a 100644
--- a/sdk/lib/core/stopwatch.dart
+++ b/sdk/lib/core/stopwatch.dart
@@ -63,6 +63,11 @@ abstract class Stopwatch {
* Returns the frequency of the elapsed counter in Hz.
*/
int get frequency;
+
+ /**
+ * Returns wether the [StopWatch] is currently running.
+ */
+ bool get isRunning;
}
class _StopwatchImpl implements Stopwatch {
@@ -77,14 +82,12 @@ class _StopwatchImpl implements Stopwatch {
_StopwatchImpl() : _start = null, _stop = null {}
void start() {
+ if (isRunning) return;
if (_start == null) {
// This stopwatch has never been started.
_start = _now();
} else {
- if (_stop == null) {
- return;
- }
- // Restarting this stopwatch. Prepend the elapsed time to the current
+ // Restart this stopwatch. Prepend the elapsed time to the current
// start time.
_start = _now() - (_stop - _start);
_stop = null;
@@ -92,9 +95,7 @@ class _StopwatchImpl implements Stopwatch {
}
void stop() {
- if (_start == null || _stop != null) {
- return;
- }
+ if (!isRunning) return;
_stop = _now();
}
@@ -127,6 +128,8 @@ class _StopwatchImpl implements Stopwatch {
int get frequency => _frequency();
+ bool get isRunning => _start != null && _stop == null;
+
external static int _frequency();
external static int _now();
}
« no previous file with comments | « no previous file | tests/corelib/stopwatch_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698