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

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: 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..9354266d768c656bfe5db0e1acb89d9cb5aedd04 100644
--- a/src/hydrogen.cc
+++ b/src/hydrogen.cc
@@ -10914,29 +10914,35 @@ HValue* HGraphBuilder::BuildBinaryOperation(
}
// Convert left argument as necessary.
- if (left_type->Is(Type::Number()) && !is_strong(strength)) {
+ if (!left_type->Is(Type::String())) {
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);
+ if (is_strong(strength)) {
+ // In strong mode, if the left hand side of an additition is a string,
Jarin 2015/08/13 06:23:50 additition -> addition (Here and below.)
Benedikt Meurer 2015/08/13 06:31:13 Done.
+ // the right hand side must be a string too.
+ left = BuildCheckString(left);
+ } else if (left_type->Is(Type::Number())) {
+ left = BuildNumberToString(left, left_type);
+ } else {
+ 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()) && !is_strong(strength)) {
+ if (!right_type->Is(Type::String())) {
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);
+ if (is_strong(strength)) {
+ // In strong mode, if the right hand side of an additition is a string,
+ // the left hand side must be a string too.
+ right = BuildCheckString(right);
+ } else if (right_type->Is(Type::Number())) {
+ right = BuildNumberToString(right, right_type);
+ } else {
+ 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