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; |
-} |