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

Unified Diff: runtime/vm/kernel_to_il.cc

Issue 2753523002: VM: [KERNEL] handle single-argument string interpolation in VM (Closed)
Patch Set: Created 3 years, 9 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: runtime/vm/kernel_to_il.cc
diff --git a/runtime/vm/kernel_to_il.cc b/runtime/vm/kernel_to_il.cc
index e817840567c9ea8c9600bd56c5488da07098fe54..914ab10f54729d102a59e64d73b858f27a0e326e 100644
--- a/runtime/vm/kernel_to_il.cc
+++ b/runtime/vm/kernel_to_il.cc
@@ -2749,6 +2749,23 @@ Fragment FlowGraphBuilder::StringInterpolate(TokenPosition position) {
}
+Fragment FlowGraphBuilder::StringInterpolateSingle(TokenPosition position) {
+ const int kNumberOfArguments = 1;
+ const Array& kNoArgumentNames = Object::null_array();
+ const dart::Class& cls = dart::Class::Handle(
+ dart::Library::LookupCoreClass(Symbols::StringBase()));
+ ASSERT(!cls.IsNull());
+ const Function& function = dart::Function::ZoneHandle(
+ Z, dart::Resolver::ResolveStatic(cls, dart::Library::PrivateCoreLibName(
+ Symbols::InterpolateSingle()),
+ kNumberOfArguments, kNoArgumentNames));
+ Fragment instructions;
+ instructions += PushArgument();
+ instructions += StaticCall(position, function, 1);
+ return instructions;
+}
+
+
Fragment FlowGraphBuilder::ThrowTypeError() {
const dart::Class& klass = dart::Class::ZoneHandle(
Z, dart::Library::LookupCoreClass(Symbols::TypeError()));
@@ -5169,22 +5186,26 @@ void FlowGraphBuilder::VisitStringConcatenation(StringConcatenation* node) {
Fragment instructions;
- // The type arguments for CreateArray.
- instructions += Constant(TypeArguments::ZoneHandle(Z));
- instructions += IntConstant(expressions.length());
- instructions += CreateArray();
- LocalVariable* array = MakeTemporary();
-
- for (intptr_t i = 0; i < node->expressions().length(); i++) {
- instructions += LoadLocal(array);
- instructions += IntConstant(i);
- instructions += TranslateExpression(node->expressions()[i]);
- instructions += StoreIndexed(kArrayCid);
- instructions += Drop();
- }
+ if (node->expressions().length() == 1) {
+ instructions += TranslateExpression(node->expressions()[0]);
+ instructions += StringInterpolateSingle(node->position());
+ } else {
+ // The type arguments for CreateArray.
+ instructions += Constant(TypeArguments::ZoneHandle(Z));
+ instructions += IntConstant(expressions.length());
+ instructions += CreateArray();
+ LocalVariable* array = MakeTemporary();
- instructions += StringInterpolate(node->position());
+ for (intptr_t i = 0; i < node->expressions().length(); i++) {
+ instructions += LoadLocal(array);
+ instructions += IntConstant(i);
+ instructions += TranslateExpression(node->expressions()[i]);
+ instructions += StoreIndexed(kArrayCid);
+ instructions += Drop();
+ }
+ instructions += StringInterpolate(node->position());
+ }
fragment_ = instructions;
}
« pkg/front_end/lib/src/fasta/kernel/body_builder.dart ('K') | « runtime/vm/kernel_to_il.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698