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

Unified Diff: dart/sdk/lib/_internal/compiler/implementation/mirrors_used.dart

Issue 113283008: Use growable lists. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Use the right constructor to create a List from an iterable. Created 6 years, 11 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 | « no previous file | dart/tests/lib/mirrors/mirrors_used_merge_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: dart/sdk/lib/_internal/compiler/implementation/mirrors_used.dart
diff --git a/dart/sdk/lib/_internal/compiler/implementation/mirrors_used.dart b/dart/sdk/lib/_internal/compiler/implementation/mirrors_used.dart
index fad167e91a36f76264ec9dc9ebb0550fb115970d..d9e860dd6b2fe8b4458a534d4937afe57f276d83 100644
--- a/dart/sdk/lib/_internal/compiler/implementation/mirrors_used.dart
+++ b/dart/sdk/lib/_internal/compiler/implementation/mirrors_used.dart
@@ -147,8 +147,7 @@ class MirrorUsageAnalyzerTask extends CompilerTask {
if (named.name.source == 'symbols') {
analyzer.cachedStrings[value] =
- builder.convertToListOfStrings(
- builder.convertConstantToUsageList(value, onlyStrings: true));
+ builder.convertConstantToUsageList(value, onlyStrings: true);
} else if (named.name.source == 'targets') {
analyzer.cachedElements[value] =
builder.resolveUsageList(builder.convertConstantToUsageList(value));
@@ -390,14 +389,17 @@ class MirrorUsageBuilder {
/// constant is a single [String], it is assumed to be a comma-separated list
/// of qualified names. If the constant is a [Type] t, the result is [:[t]:].
/// Otherwise, the constant is assumed to represent a list of strings (each a
- /// qualified name) and types, and such a list is constructed.
+ /// qualified name) and types, and such a list is constructed. If
+ /// [onlyStrings] is true, the returned list is a [:List<String>:] and any
+ /// [Type] values are treated as an error (meaning that the value is ignored
+ /// and a hint is emitted).
List convertConstantToUsageList(
Constant constant, { bool onlyStrings: false }) {
if (constant.isNull()) {
return null;
} else if (constant.isList()) {
ListConstant list = constant;
- List result = [];
+ List result = onlyStrings ? <String> [] : [];
for (Constant entry in list.entries) {
if (entry.isString()) {
StringConstant string = entry;
@@ -421,8 +423,9 @@ class MirrorUsageBuilder {
return [type.representedType];
} else if (constant.isString()) {
StringConstant string = constant;
- return
- string.value.slowToString().split(',').map((e) => e.trim()).toList();
+ var iterable =
+ string.value.slowToString().split(',').map((e) => e.trim());
+ return onlyStrings ? new List<String>.from(iterable) : iterable.toList();
} else {
Spannable node = positionOf(constant);
MessageKind kind = onlyStrings
@@ -452,18 +455,6 @@ class MirrorUsageBuilder {
return type;
}
- /// Ensure a list contains only strings.
- List<String> convertToListOfStrings(List list) {
- if (list == null) return null;
- List<String> result = new List<String>(list.length);
- int count = 0;
- for (var entry in list) {
- assert(invariant(spannable, entry is String));
- result[count++] = entry;
- }
- return result;
- }
-
/// Convert a list of strings and types to a list of elements. Types are
/// converted to their corresponding element, and strings are resolved as
/// follows:
« no previous file with comments | « no previous file | dart/tests/lib/mirrors/mirrors_used_merge_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698