Reviewers: mvstanton,
Message:
Hey Michael,
Here's a simple refactoring to ensure that the fast path for empty constants
strings is checked first.
PTAL
-- Benedikt
Description:
Refactor fast path for empty constant strings in BinaryOp.
Please review this at https://codereview.chromium.org/143003005/
SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge
Affected files (+24, -27 lines):
M src/hydrogen.cc
Index: src/hydrogen.cc
diff --git a/src/hydrogen.cc b/src/hydrogen.cc
index
63b6da7e8b29b792e9bb6403f365bb3bda325615..2af3c2d4e354f339c0ee56122b0e6ee79381781e
100644
--- a/src/hydrogen.cc
+++ b/src/hydrogen.cc
@@ -8954,11 +8954,16 @@ HValue* HGraphBuilder::BuildBinaryOperation(
return AddUncasted<HInvokeFunction>(function, 2);
}
- // Inline the string addition into the stub when creating allocation
- // mementos to gather allocation site feedback.
- if (graph()->info()->IsStub() &&
- allocation_mode.CreateAllocationMementos()) {
- return BuildStringAdd(left, right, allocation_mode);
+ // Fast path for empty constant strings.
+ if (left->IsConstant() &&
+ HConstant::cast(left)->HasStringValue() &&
+ HConstant::cast(left)->StringValue()->length() == 0) {
+ 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.
@@ -8969,28 +8974,20 @@ HValue* HGraphBuilder::BuildBinaryOperation(
site, AllocationSite::TENURING, top_info());
}
- // Inline string addition if we know that we'll create a cons string.
- if (left->IsConstant()) {
- HConstant* c_left = HConstant::cast(left);
- if (c_left->HasStringValue()) {
- int c_left_length = c_left->StringValue()->length();
- if (c_left_length == 0) {
- return right;
- } else if (c_left_length + 1 >= ConsString::kMinLength) {
- return BuildStringAdd(left, right, allocation_mode);
- }
- }
- }
- if (right->IsConstant()) {
- HConstant* c_right = HConstant::cast(right);
- 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);
- }
- }
+ // Inline the string addition into the stub when creating allocation
+ // mementos to gather allocation site feedback, or if we can statically
+ // infer that we're going to create a cons string.
+ if ((graph()->info()->IsStub() &&
+ allocation_mode.CreateAllocationMementos()) ||
+ (left->IsConstant() &&
+ HConstant::cast(left)->HasStringValue() &&
+ HConstant::cast(left)->StringValue()->length() + 1 >=
+ ConsString::kMinLength) ||
+ (right->IsConstant() &&
+ HConstant::cast(right)->HasStringValue() &&
+ HConstant::cast(right)->StringValue()->length() + 1 >=
+ ConsString::kMinLength)) {
+ return BuildStringAdd(left, right, allocation_mode);
}
// Fallback to using the string add stub.
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.