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

Unified Diff: runtime/vm/intermediate_language.cc

Issue 563973004: Call special VM interpolate for single element interpolation. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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: runtime/vm/intermediate_language.cc
diff --git a/runtime/vm/intermediate_language.cc b/runtime/vm/intermediate_language.cc
index 43f30a79b2ed87c83cedd6f2554ff9f932a4e870..a85c66099a8dfca1a240714623ad1be9b803d1a4 100644
--- a/runtime/vm/intermediate_language.cc
+++ b/runtime/vm/intermediate_language.cc
@@ -2885,7 +2885,9 @@ const Function& StringInterpolateInstr::CallFunction() const {
function_ =
Resolver::ResolveStatic(
cls,
- Library::PrivateCoreLibName(Symbols::Interpolate()),
+ singleton_
+ ? Library::PrivateCoreLibName(Symbols::InterpolateSingle())
+ : Library::PrivateCoreLibName(Symbols::Interpolate()),
kNumberOfArguments,
kNoArgumentNames);
}
@@ -2904,12 +2906,35 @@ Definition* StringInterpolateInstr::Canonicalize(FlowGraph* flow_graph) {
// StoreIndexed(v2, v3, v4) -- v3:constant index, v4: value.
// ..
// v8 <- StringInterpolate(v2)
+ // or for a single element:
+ // v2 <- StringInterpolateSingle(v0)
// Don't compile-time fold when optimizing the interpolation function itself.
if (flow_graph->parsed_function().function().raw() == CallFunction().raw()) {
return this;
}
+ if (singleton_) {
+ Value* value = this->value();
+ if (!value->definition()->IsConstant()) return this;
+ const Object& obj = value->definition()->AsConstant()->value();
+ if (!obj.IsNumber() && !obj.IsString() && !obj.IsBool() && !obj.IsNull()) {
+ return this;
+ }
+ // This is only really useful for numbers, so we don't bother optimizing
Florian Schneider 2014/09/12 10:33:37 I dont' understand this comment because you do rea
Lasse Reichstein Nielsen 2014/09/12 12:49:39 The point is that we don't expect to reach here ve
+ // for strings, bool or null.
+ const Array& interpolate_arg = Array::Handle(Array::New(1));
+ interpolate_arg.SetAt(0, obj);
+ const Object& result = Object::Handle(
+ DartEntry::InvokeFunction(CallFunction(), interpolate_arg));
+ if (result.IsUnhandledException()) {
+ return this;
+ }
+ ASSERT(result.IsString());
+ const String& converted =
+ String::ZoneHandle(Symbols::New(String::Cast(result)));
+ return flow_graph->GetConstant(converted);
+ }
CreateArrayInstr* create_array = value()->definition()->AsCreateArray();
ASSERT(create_array != NULL);
// Check if the string interpolation has only constant inputs.

Powered by Google App Engine
This is Rietveld 408576698