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

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

Issue 12210065: Remove Stopwatch interface and make it a class. (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 | « sdk/lib/_internal/compiler/implementation/lib/core_patch.dart ('k') | no next file » | 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 b446069f70c1ad298a441051ec28816114d9149a..55648014c42149904c6829f3a8e3bfb9f8b02736 100644
--- a/sdk/lib/core/stopwatch.dart
+++ b/sdk/lib/core/stopwatch.dart
@@ -7,7 +7,15 @@ part of dart.core;
/**
* A simple [Stopwatch] interface to measure elapsed time.
*/
-abstract class Stopwatch {
+class Stopwatch {
+ // The _start and _stop fields capture the time when [start] and [stop]
+ // are called respectively.
+ // If _start is null, then the [Stopwatch] has not been started yet.
+ // If _stop is null, then the [Stopwatch] has not been stopped yet,
+ // or is running.
+ int _start;
+ int _stop;
+
/**
* Creates a [Stopwatch] in stopped state with a zero elapsed count.
*
@@ -16,7 +24,7 @@ abstract class Stopwatch {
*
* Stopwatch stopwatch = new Stopwatch()..start();
*/
- factory Stopwatch() => new _StopwatchImpl();
+ Stopwatch() : _start = null, _stop = null {}
/**
* Starts the [Stopwatch]. The [elapsed] count is increasing monotonically.
@@ -24,63 +32,6 @@ abstract class Stopwatch {
* without resetting the [elapsed] count.
* If the [Stopwatch] is currently running, then calling start does nothing.
*/
- void start();
-
- /**
- * Stops the [Stopwatch]. The [elapsed] count stops increasing.
- * If the [Stopwatch] is currently not running, then calling stop does
- * nothing.
- */
- void stop();
-
- /**
- * Resets the [elapsed] count to zero. This method does not stop or start
- * the [Stopwatch].
- */
- void reset();
-
- /**
- * Returns the elapsed number of clock ticks since calling [start] while the
- * [Stopwatch] is running.
- * Returns the elapsed number of clock ticks between calling [start] and
- * calling [stop].
- * Returns 0 if the [Stopwatch] has never been started.
- * The elapsed number of clock ticks increases by [frequency] every second.
- */
- int get elapsedTicks;
-
- /**
- * Returns the [elapsedTicks] counter converted to microseconds.
- */
- int get elapsedMicroseconds;
-
- /**
- * Returns the [elapsedTicks] counter converted to milliseconds.
- */
- int get elapsedMilliseconds;
-
- /**
- * 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 {
- // The _start and _stop fields capture the time when [start] and [stop]
- // are called respectively.
- // If _start is null, then the [Stopwatch] has not been started yet.
- // If _stop is null, then the [Stopwatch] has not been stopped yet,
- // or is running.
- int _start;
- int _stop;
-
- _StopwatchImpl() : _start = null, _stop = null {}
-
void start() {
if (isRunning) return;
if (_start == null) {
@@ -94,11 +45,20 @@ class _StopwatchImpl implements Stopwatch {
}
}
+ /**
+ * Stops the [Stopwatch]. The [elapsed] count stops increasing.
+ * If the [Stopwatch] is currently not running, then calling stop does
+ * nothing.
+ */
void stop() {
if (!isRunning) return;
_stop = _now();
}
+ /**
+ * Resets the [elapsed] count to zero. This method does not stop or start
+ * the [Stopwatch].
+ */
void reset() {
if (_start == null) return;
// If [_start] is not null, then the stopwatch had already been started. It
@@ -111,6 +71,14 @@ class _StopwatchImpl implements Stopwatch {
}
}
+ /**
+ * Returns the elapsed number of clock ticks since calling [start] while the
+ * [Stopwatch] is running.
+ * Returns the elapsed number of clock ticks between calling [start] and
+ * calling [stop].
+ * Returns 0 if the [Stopwatch] has never been started.
+ * The elapsed number of clock ticks increases by [frequency] every second.
+ */
int get elapsedTicks {
if (_start == null) {
return 0;
@@ -118,16 +86,28 @@ class _StopwatchImpl implements Stopwatch {
return (_stop == null) ? (_now() - _start) : (_stop - _start);
}
+ /**
+ * Returns the [elapsedTicks] counter converted to microseconds.
+ */
int get elapsedMicroseconds {
return (elapsedTicks * 1000000) ~/ frequency;
}
+ /**
+ * Returns the [elapsedTicks] counter converted to milliseconds.
+ */
int get elapsedMilliseconds {
return (elapsedTicks * 1000) ~/ frequency;
}
+ /**
+ * Returns the frequency of the elapsed counter in Hz.
+ */
int get frequency => _frequency();
+ /**
+ * Returns wether the [StopWatch] is currently running.
+ */
bool get isRunning => _start != null && _stop == null;
external static int _frequency();
« no previous file with comments | « sdk/lib/_internal/compiler/implementation/lib/core_patch.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698