Commit c06d2482 authored by bmeurer@chromium.org's avatar bmeurer@chromium.org

Refactor fast path for empty constant strings in BinaryOp.

R=mvstanton@chromium.org

Review URL: https://codereview.chromium.org/143003005

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@18742 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 33d7e64b
...@@ -8951,11 +8951,16 @@ HValue* HGraphBuilder::BuildBinaryOperation( ...@@ -8951,11 +8951,16 @@ HValue* HGraphBuilder::BuildBinaryOperation(
return AddUncasted<HInvokeFunction>(function, 2); return AddUncasted<HInvokeFunction>(function, 2);
} }
// Inline the string addition into the stub when creating allocation // Fast path for empty constant strings.
// mementos to gather allocation site feedback. if (left->IsConstant() &&
if (graph()->info()->IsStub() && HConstant::cast(left)->HasStringValue() &&
allocation_mode.CreateAllocationMementos()) { HConstant::cast(left)->StringValue()->length() == 0) {
return BuildStringAdd(left, right, allocation_mode); return right;
}
if (right->IsConstant() &&
HConstant::cast(right)->HasStringValue() &&
HConstant::cast(right)->StringValue()->length() == 0) {
return left;
} }
// Register the dependent code with the allocation site. // Register the dependent code with the allocation site.
...@@ -8966,28 +8971,20 @@ HValue* HGraphBuilder::BuildBinaryOperation( ...@@ -8966,28 +8971,20 @@ HValue* HGraphBuilder::BuildBinaryOperation(
site, AllocationSite::TENURING, top_info()); site, AllocationSite::TENURING, top_info());
} }
// Inline string addition if we know that we'll create a cons string. // Inline the string addition into the stub when creating allocation
if (left->IsConstant()) { // mementos to gather allocation site feedback, or if we can statically
HConstant* c_left = HConstant::cast(left); // infer that we're going to create a cons string.
if (c_left->HasStringValue()) { if ((graph()->info()->IsStub() &&
int c_left_length = c_left->StringValue()->length(); allocation_mode.CreateAllocationMementos()) ||
if (c_left_length == 0) { (left->IsConstant() &&
return right; HConstant::cast(left)->HasStringValue() &&
} else if (c_left_length + 1 >= ConsString::kMinLength) { HConstant::cast(left)->StringValue()->length() + 1 >=
return BuildStringAdd(left, right, allocation_mode); ConsString::kMinLength) ||
} (right->IsConstant() &&
} HConstant::cast(right)->HasStringValue() &&
} HConstant::cast(right)->StringValue()->length() + 1 >=
if (right->IsConstant()) { ConsString::kMinLength)) {
HConstant* c_right = HConstant::cast(right); return BuildStringAdd(left, right, allocation_mode);
if (c_right->HasStringValue()) {
int c_right_length = c_right->StringValue()->length();
if (c_right_length == 0) {
return left;
} else if (c_right_length + 1 >= ConsString::kMinLength) {
return BuildStringAdd(left, right, allocation_mode);
}
}
} }
// Fallback to using the string add stub. // Fallback to using the string add stub.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment