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

Unified Diff: src/full-codegen.cc

Issue 7216008: Better codegen for '<expression> === void <literal>'. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 9 years, 6 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: src/full-codegen.cc
diff --git a/src/full-codegen.cc b/src/full-codegen.cc
index 9353ab515617006609013744cb2035b04d38eae1..6cfe4ceb3354bc18440690545ace4e920f51f45f 100644
--- a/src/full-codegen.cc
+++ b/src/full-codegen.cc
@@ -1290,6 +1290,58 @@ int FullCodeGenerator::TryCatch::Exit(int stack_depth) {
}
+bool FullCodeGenerator::TryLiteralCompare(Token::Value op,
+ Expression* left,
+ Expression* right,
+ Label* if_true,
+ Label* if_false,
+ Label* fall_through) {
+ if (op != Token::EQ && op != Token::EQ_STRICT) return false;
+
+ UnaryOperation* left_unary = left->AsUnaryOperation();
+ UnaryOperation* right_unary = right->AsUnaryOperation();
+ Literal* left_literal = left->AsLiteral();
+ Literal* right_literal = right->AsLiteral();
+
+ // Check for the pattern: typeof <expression> == <string literal>.
+ if (left_unary != NULL && left_unary->op() == Token::TYPEOF &&
+ right_literal != NULL && right_literal->handle()->IsString()) {
+ EmitLiteralCompareTypeof(left_unary->expression(),
+ Handle<String>::cast(right_literal->handle()),
+ if_true, if_false, fall_through);
+ return true;
+ }
+
+ // Check for the pattern: <string literal> == typeof <expression>.
+ if (right_unary != NULL && right_unary->op() == Token::TYPEOF &&
+ left_literal != NULL && left_literal->handle()->IsString()) {
+ EmitLiteralCompareTypeof(right_unary->expression(),
+ Handle<String>::cast(left_literal->handle()),
+ if_true, if_false, fall_through);
+ return true;
+ }
+
fschneider 2011/06/21 11:36:08 Remove extra line.
Steven 2011/06/22 10:00:53 Done.
+
+ if (op != Token::EQ_STRICT) return false;
+
+ // Check for the pattern: <expression> === void <literal>.
+ if (right_unary != NULL && right_unary->op() == Token::VOID &&
+ right_unary->expression()->AsLiteral() != NULL) {
+ EmitLiteralCompareUndefined(left, if_true, if_false, fall_through);
+ return true;
+ }
+
+ // Check for the pattern: void <literal> === <expression>.
+ if (left_unary != NULL && left_unary->op() == Token::VOID &&
+ left_unary->expression()->AsLiteral() != NULL) {
+ EmitLiteralCompareUndefined(right, if_true, if_false, fall_through);
+ return true;
+ }
+
+ return false;
+}
+
+
#undef __

Powered by Google App Engine
This is Rietveld 408576698