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

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

Issue 585173002: dart2js: Support new const operations on strings. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add null check. Created 6 years, 3 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: sdk/lib/_internal/compiler/implementation/compile_time_constants.dart
diff --git a/sdk/lib/_internal/compiler/implementation/compile_time_constants.dart b/sdk/lib/_internal/compiler/implementation/compile_time_constants.dart
index e717c15d48684de33dc8b8c17e651c1046ac53b9..776e1a9b22e51dd7c30555b619acf9ee2a931892 100644
--- a/sdk/lib/_internal/compiler/implementation/compile_time_constants.dart
+++ b/sdk/lib/_internal/compiler/implementation/compile_time_constants.dart
@@ -409,6 +409,13 @@ class CompileTimeConstantEvaluator extends Visitor {
assert(elements.isTypeLiteral(send));
return makeTypeConstant(elements.getTypeLiteralType(send));
} else if (send.receiver != null) {
+ if (send.selector.asIdentifier().source == "length") {
+ Constant left = evaluate(send.receiver);
+ if (left != null && left.isString) {
+ StringConstant string = left;
+ return constantSystem.createInt(string.value.length);
+ }
+ }
// Fall through to error handling.
} else if (!Elements.isUnresolved(element)
&& element.isVariable
@@ -418,7 +425,7 @@ class CompileTimeConstantEvaluator extends Visitor {
}
return signalNotCompileTimeConstant(send);
} else if (send.isCall) {
- if (identical(element, compiler.identicalFunction)
+ if (element == compiler.identicalFunction
&& send.argumentCount() == 2) {
Constant left = evaluate(send.argumentsNode.nodes.head);
Constant right = evaluate(send.argumentsNode.nodes.tail.head);

Powered by Google App Engine
This is Rietveld 408576698