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

Unified Diff: src/hydrogen.cc

Issue 1287203002: [strong] Simplify (and sortof optimize) string addition for strong mode. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Small beautification. Created 5 years, 4 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
« no previous file with comments | « src/builtins.h ('k') | src/runtime.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/hydrogen.cc
diff --git a/src/hydrogen.cc b/src/hydrogen.cc
index 559eca6e5847eb8d3503a1f2426a74e60d5c8026..9b2a2f6a078341f7cacbc40eaec9557450444801 100644
--- a/src/hydrogen.cc
+++ b/src/hydrogen.cc
@@ -10903,40 +10903,43 @@ HValue* HGraphBuilder::BuildBinaryOperation(
// Special case for string addition here.
if (op == Token::ADD &&
(left_type->Is(Type::String()) || right_type->Is(Type::String()))) {
- // Validate type feedback for left argument.
- if (left_type->Is(Type::String())) {
+ if (is_strong(strength)) {
+ // In strong mode, if the one side of an addition is a string,
+ // the other side must be a string too.
left = BuildCheckString(left);
- }
-
- // Validate type feedback for right argument.
- if (right_type->Is(Type::String())) {
right = BuildCheckString(right);
- }
+ } else {
+ // Validate type feedback for left argument.
+ if (left_type->Is(Type::String())) {
+ left = BuildCheckString(left);
+ }
- // Convert left argument as necessary.
- if (left_type->Is(Type::Number()) && !is_strong(strength)) {
- DCHECK(right_type->Is(Type::String()));
- left = BuildNumberToString(left, left_type);
- } else if (!left_type->Is(Type::String())) {
- DCHECK(right_type->Is(Type::String()));
- HValue* function = AddLoadJSBuiltin(
- is_strong(strength) ? Builtins::STRING_ADD_RIGHT_STRONG
- : Builtins::STRING_ADD_RIGHT);
- Add<HPushArguments>(left, right);
- return AddUncasted<HInvokeFunction>(function, 2);
- }
-
- // Convert right argument as necessary.
- if (right_type->Is(Type::Number()) && !is_strong(strength)) {
- DCHECK(left_type->Is(Type::String()));
- right = BuildNumberToString(right, right_type);
- } else if (!right_type->Is(Type::String())) {
- DCHECK(left_type->Is(Type::String()));
- HValue* function = AddLoadJSBuiltin(is_strong(strength)
- ? Builtins::STRING_ADD_LEFT_STRONG
- : Builtins::STRING_ADD_LEFT);
- Add<HPushArguments>(left, right);
- return AddUncasted<HInvokeFunction>(function, 2);
+ // Validate type feedback for right argument.
+ if (right_type->Is(Type::String())) {
+ right = BuildCheckString(right);
+ }
+
+ // Convert left argument as necessary.
+ if (left_type->Is(Type::Number())) {
+ DCHECK(right_type->Is(Type::String()));
+ left = BuildNumberToString(left, left_type);
+ } else if (!left_type->Is(Type::String())) {
+ DCHECK(right_type->Is(Type::String()));
+ HValue* function = AddLoadJSBuiltin(Builtins::STRING_ADD_RIGHT);
+ Add<HPushArguments>(left, right);
+ return AddUncasted<HInvokeFunction>(function, 2);
+ }
+
+ // Convert right argument as necessary.
+ if (right_type->Is(Type::Number())) {
+ DCHECK(left_type->Is(Type::String()));
+ right = BuildNumberToString(right, right_type);
+ } else if (!right_type->Is(Type::String())) {
+ DCHECK(left_type->Is(Type::String()));
+ HValue* function = AddLoadJSBuiltin(Builtins::STRING_ADD_LEFT);
+ Add<HPushArguments>(left, right);
+ return AddUncasted<HInvokeFunction>(function, 2);
+ }
}
// Fast paths for empty constant strings.
« no previous file with comments | « src/builtins.h ('k') | src/runtime.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698