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

Unified Diff: pkg/analyzer/lib/src/generated/utilities_general.dart

Issue 225183020: Correct or pause previous TimeCounters. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 8 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
Index: pkg/analyzer/lib/src/generated/utilities_general.dart
diff --git a/pkg/analyzer/lib/src/generated/utilities_general.dart b/pkg/analyzer/lib/src/generated/utilities_general.dart
index abee059ae1fb6f860f15ad3434ee6fcf08f03f25..d889e35463d18912b2224d9bcbdebec46bf90c53 100644
--- a/pkg/analyzer/lib/src/generated/utilities_general.dart
+++ b/pkg/analyzer/lib/src/generated/utilities_general.dart
@@ -11,7 +11,8 @@ library engine.utilities.general;
* Helper for measuring how much time is spent doing some operation.
*/
class TimeCounter {
- Stopwatch _sw = new Stopwatch();
+ static TimeCounter _current = null;
+ final Stopwatch _sw = new Stopwatch();
/**
* @return the number of milliseconds spent between [start] and [stop].
@@ -23,7 +24,9 @@ class TimeCounter {
*
* @return the [TimeCounterHandle] that should be used to stop counting.
*/
- TimeCounter_TimeCounterHandle start() => new TimeCounter_TimeCounterHandle(this);
+ TimeCounter_TimeCounterHandle start() {
+ return new TimeCounter_TimeCounterHandle(this);
+ }
}
/**
@@ -31,8 +34,16 @@ class TimeCounter {
*/
class TimeCounter_TimeCounterHandle {
final TimeCounter _counter;
+ TimeCounter _prev;
TimeCounter_TimeCounterHandle(this._counter) {
+ // if there is some counter running, pause it
+ _prev = TimeCounter._current;
+ if (_prev != null) {
+ _prev._sw.stop();
+ }
+ TimeCounter._current = _counter;
+ // start this counter
_counter._sw.start();
}
@@ -41,5 +52,10 @@ class TimeCounter_TimeCounterHandle {
*/
void stop() {
_counter._sw.stop();
+ // restore previous counter and resume it
+ TimeCounter._current = _prev;
+ if (_prev != null) {
+ _prev._sw.start();
+ }
}
-}
+}

Powered by Google App Engine
This is Rietveld 408576698