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

Unified Diff: corelib/src/implementation/stopwatch_implementation.dart

Issue 8537011: Rename StopWatch to Stopwatch. Add new Stopwatch.start() and Stopwatch.reset(). (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: '' Created 9 years, 1 month 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 | corelib/src/stopwatch.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: corelib/src/implementation/stopwatch_implementation.dart
===================================================================
--- corelib/src/implementation/stopwatch_implementation.dart (revision 1504)
+++ corelib/src/implementation/stopwatch_implementation.dart (working copy)
@@ -3,17 +3,20 @@
// BSD-style license that can be found in the LICENSE file.
/**
- * A simple implementation of the [StopWatch] interface.
+ * A simple implementation of the [Stopwatch] interface.
*/
-class StopWatchImplementation implements StopWatch {
+class StopwatchImplementation 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.
+ // If _start is null, then the [Stopwatch] has not been started yet.
+ // If _stop is null, then the [Stopwatch] has not been stopped yet.
int _start;
int _stop;
- StopWatchImplementation() : _start = null, _stop = null {}
+ StopwatchImplementation() : _start = null, _stop = null {}
+ StopwatchImplementation.start() : _start = null, _stop = null {
+ start();
+ }
void start() {
if (_start === null) {
@@ -36,6 +39,18 @@
_stop = Clock.now();
}
+ void reset() {
+ if (_start === null) return;
+ // If [_start] is not null, then the stopwatch had already been started. It
+ // may running right now.
+ _start = Clock.now();
+ if (_stop !== null) {
+ // The watch is not running. So simply set the [_stop] to [_start] thus
+ // having an elapsed time of 0.
+ _stop = _start;
+ }
+ }
+
int elapsed() {
if (_start === null) {
return 0;
« no previous file with comments | « no previous file | corelib/src/stopwatch.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698