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

Side by Side Diff: pkg/analyzer/lib/src/generated/utilities_general.dart

Issue 954013002: Replace try/finally with PerformanceTag.makeCurrentWhile(). (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 // This code was auto-generated, is not intended to be edited, and is subject to 5 // This code was auto-generated, is not intended to be edited, and is subject to
6 // significant change. Please see the README file for more information. 6 // significant change. Please see the README file for more information.
7 7
8 library engine.utilities.general; 8 library engine.utilities.general;
9 9
10 import 'dart:profiler'; 10 import 'dart:profiler';
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 * Return the label for this [PerformanceTag]. 73 * Return the label for this [PerformanceTag].
74 */ 74 */
75 String get label; 75 String get label;
76 76
77 /** 77 /**
78 * Make this the current tag for the isolate, and return the previous tag. 78 * Make this the current tag for the isolate, and return the previous tag.
79 */ 79 */
80 PerformanceTag makeCurrent(); 80 PerformanceTag makeCurrent();
81 81
82 /** 82 /**
83 * Make this the current tag for the isolate, run [f], and restore the
84 * previous tag. Returns the result of invoking [f].
85 */
86 makeCurrentWhile(f());
87
88 /**
83 * Reset the total time tracked by all [PerformanceTag]s to zero. 89 * Reset the total time tracked by all [PerformanceTag]s to zero.
84 */ 90 */
85 static void reset() { 91 static void reset() {
86 for (_PerformanceTagImpl tag in _PerformanceTagImpl.all) { 92 for (_PerformanceTagImpl tag in _PerformanceTagImpl.all) {
87 tag.stopwatch.reset(); 93 tag.stopwatch.reset();
88 } 94 }
89 } 95 }
90 } 96 }
91 97
92 class _PerformanceTagImpl implements PerformanceTag { 98 class _PerformanceTagImpl implements PerformanceTag {
(...skipping 14 matching lines...) Expand all
107 */ 113 */
108 final UserTag userTag; 114 final UserTag userTag;
109 115
110 /** 116 /**
111 * Stopwatch tracking the amount of time this [PerformanceTag] has been the 117 * Stopwatch tracking the amount of time this [PerformanceTag] has been the
112 * current tag for the isolate. 118 * current tag for the isolate.
113 */ 119 */
114 final Stopwatch stopwatch; 120 final Stopwatch stopwatch;
115 121
116 _PerformanceTagImpl(String label) 122 _PerformanceTagImpl(String label)
117 : userTag = new UserTag(label), stopwatch = new Stopwatch() { 123 : userTag = new UserTag(label),
124 stopwatch = new Stopwatch() {
118 all.add(this); 125 all.add(this);
119 } 126 }
120 127
121 @override 128 @override
122 int get elapsedMs => stopwatch.elapsedMilliseconds; 129 int get elapsedMs => stopwatch.elapsedMilliseconds;
123 130
124 @override 131 @override
125 String get label => userTag.label; 132 String get label => userTag.label;
126 133
127 @override 134 @override
128 PerformanceTag makeCurrent() { 135 PerformanceTag makeCurrent() {
129 if (identical(this, current)) { 136 if (identical(this, current)) {
130 return current; 137 return current;
131 } 138 }
132 _PerformanceTagImpl previous = current; 139 _PerformanceTagImpl previous = current;
133 previous.stopwatch.stop(); 140 previous.stopwatch.stop();
134 stopwatch.start(); 141 stopwatch.start();
135 current = this; 142 current = this;
136 userTag.makeCurrent(); 143 userTag.makeCurrent();
137 return previous; 144 return previous;
138 } 145 }
146
147 makeCurrentWhile(f()) {
148 PerformanceTag prevTag = makeCurrent();
149 try {
150 return f();
151 } finally {
152 prevTag.makeCurrent();
153 }
154 }
139 } 155 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698