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

Unified Diff: sdk/lib/profiler/profiler.dart

Issue 266913010: Refactor 'dart:profiler' UserTag API (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 7 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 | « runtime/vm/tags.h ('k') | tests/lib/profiler/user_tags_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/profiler/profiler.dart
diff --git a/sdk/lib/profiler/profiler.dart b/sdk/lib/profiler/profiler.dart
index 56614ddec0c5cc7fb4db5bee186b9b692463b43d..0bcae568dfd45b678de3e79710afdcd1fbc74b87 100644
--- a/sdk/lib/profiler/profiler.dart
+++ b/sdk/lib/profiler/profiler.dart
@@ -14,53 +14,52 @@ abstract class UserTag {
/// Label of [this].
String get label;
- /// Make [this] the current tag for the isolate.
- makeCurrent();
+ /// Make [this] the current tag for the isolate. Returns the current tag
+ /// before setting.
+ UserTag makeCurrent();
+
+ /// The default [UserTag] with label 'Default'.
+ static UserTag get defaultTag => _FakeUserTag._defaultTag;
}
// This is a fake implementation of UserTag so that code can compile and run
// in dart2js.
class _FakeUserTag implements UserTag {
- static List _instances = [];
+ static Map _instances = {};
_FakeUserTag.real(this.label);
factory _FakeUserTag(String label) {
// Canonicalize by name.
- for (var tag in _instances) {
- if (tag.label == label) {
- return tag;
- }
+ var existingTag = _instances[label];
+ if (existingTag != null) {
+ return existingTag;
}
// Throw an exception if we've reached the maximum number of user tags.
if (_instances.length == UserTag.MAX_USER_TAGS) {
throw new UnsupportedError(
'UserTag instance limit (${UserTag.MAX_USER_TAGS}) reached.');
}
- // Create a new instance and add it to the instance list.
+ // Create a new instance and add it to the instance map.
var instance = new _FakeUserTag.real(label);
- _instances.add(instance);
+ _instances[label] = instance;
return instance;
}
final String label;
- makeCurrent() {
+ UserTag makeCurrent() {
+ var old = _currentTag;
_currentTag = this;
+ return old;
}
+
+ static final UserTag _defaultTag = new _FakeUserTag('Default');
}
-var _currentTag = null;
+var _currentTag = _FakeUserTag._defaultTag;
/// Returns the current [UserTag] for the isolate.
UserTag getCurrentTag() {
return _currentTag;
}
-
-/// Sets the current [UserTag] for the isolate to null. Returns current tag
-/// before clearing.
-UserTag clearCurrentTag() {
- var old = _currentTag;
- _currentTag = null;
- return old;
-}
« no previous file with comments | « runtime/vm/tags.h ('k') | tests/lib/profiler/user_tags_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698