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

Unified Diff: src/func-name-inferrer.cc

Issue 231073002: WIP: Parser: delay string internalization. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: internalizing better Created 6 years, 7 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/func-name-inferrer.cc
diff --git a/src/func-name-inferrer.cc b/src/func-name-inferrer.cc
index 370d6264dff8d1ad278f88841467b1fff1225f05..cc4c9d44345b69b6a33e3460ef48dff568442705 100644
--- a/src/func-name-inferrer.cc
+++ b/src/func-name-inferrer.cc
@@ -7,12 +7,13 @@
#include "ast.h"
#include "func-name-inferrer.h"
#include "list-inl.h"
+#include "parser-symbol-table.h"
namespace v8 {
namespace internal {
-FuncNameInferrer::FuncNameInferrer(Isolate* isolate, Zone* zone)
- : isolate_(isolate),
+FuncNameInferrer::FuncNameInferrer(ParserSymbolTable* symbol_table, Zone* zone)
+ : symbol_table_(symbol_table),
entries_stack_(10, zone),
names_stack_(5, zone),
funcs_to_infer_(4, zone),
@@ -20,66 +21,90 @@ FuncNameInferrer::FuncNameInferrer(Isolate* isolate, Zone* zone)
}
-void FuncNameInferrer::PushEnclosingName(Handle<String> name) {
+void FuncNameInferrer::PushEnclosingName(ParserSymbolTable::Symbol* name) {
// Enclosing name is a name of a constructor function. To check
// that it is really a constructor, we check that it is not empty
// and starts with a capital letter.
- if (name->length() > 0 && Runtime::IsUpperCaseChar(
- isolate()->runtime_state(), name->Get(0))) {
+ if (name->literal_bytes.length() > 0 &&
+ unibrow::Uppercase::Is(name->literal_bytes[0])) {
names_stack_.Add(Name(name, kEnclosingConstructorName), zone());
}
}
-void FuncNameInferrer::PushLiteralName(Handle<String> name) {
- if (IsOpen() &&
- !String::Equals(isolate()->factory()->prototype_string(), name)) {
+void FuncNameInferrer::PushLiteralName(ParserSymbolTable::Symbol* name) {
+ if (IsOpen() && name != symbol_table_->prototype_string()) {
names_stack_.Add(Name(name, kLiteralName), zone());
}
}
-void FuncNameInferrer::PushVariableName(Handle<String> name) {
- if (IsOpen() &&
- !String::Equals(isolate()->factory()->dot_result_string(), name)) {
+void FuncNameInferrer::PushVariableName(ParserSymbolTable::Symbol* name) {
+ if (IsOpen() && name != symbol_table_->dot_result_string()) {
names_stack_.Add(Name(name, kVariableName), zone());
}
}
-Handle<String> FuncNameInferrer::MakeNameFromStack() {
- return MakeNameFromStackHelper(0, isolate()->factory()->empty_string());
-}
-
-
-Handle<String> FuncNameInferrer::MakeNameFromStackHelper(int pos,
- Handle<String> prev) {
- if (pos >= names_stack_.length()) return prev;
- if (pos < names_stack_.length() - 1 &&
- names_stack_.at(pos).type == kVariableName &&
- names_stack_.at(pos + 1).type == kVariableName) {
- // Skip consecutive variable declarations.
- return MakeNameFromStackHelper(pos + 1, prev);
- } else {
- if (prev->length() > 0) {
- Handle<String> name = names_stack_.at(pos).name;
- if (prev->length() + name->length() + 1 > String::kMaxLength) return prev;
- Factory* factory = isolate()->factory();
- Handle<String> curr =
- factory->NewConsString(factory->dot_string(), name).ToHandleChecked();
- curr = factory->NewConsString(prev, curr).ToHandleChecked();
- return MakeNameFromStackHelper(pos + 1, curr);
- } else {
- return MakeNameFromStackHelper(pos + 1, names_stack_.at(pos).name);
+ParserSymbolTable::Symbol* FuncNameInferrer::MakeNameFromStack() {
+ // First see how many names we will use.
+ int length = 0;
+ bool one_byte = true;
+ int pos = 0;
+ while (pos < names_stack_.length()) {
+ if (pos < names_stack_.length() - 1 &&
+ names_stack_.at(pos).type == kVariableName &&
+ names_stack_.at(pos + 1).type == kVariableName) {
+ // Skip consecutive variable declarations.
+ ++pos;
+ continue;
+ }
+ int cur_length = names_stack_.at(pos).name->literal_bytes.length();
+ if (length + 1 + cur_length > String::kMaxLength) {
+ break;
+ }
+ if (length == 0) {
+ length = cur_length;
+ } else { // Add the . between names.
+ length += (1 + cur_length);
+ }
+ one_byte = one_byte && names_stack_.at(pos).name->is_one_byte;
+ ++pos;
+ }
+ ParserSymbolTable::Symbol* to_return = NULL;
+ if (one_byte) {
+ Vector<uint8_t> new_name = Vector<uint8_t>::New(length);
+ int name_pos = 0;
+ const char* dot = ".";
+ for (int i = 0; i < pos; ++i) {
+ if (i < names_stack_.length() - 1 &&
+ names_stack_.at(i).type == kVariableName &&
+ names_stack_.at(i + 1).type == kVariableName) {
+ continue;
+ }
+ if (name_pos != 0) {
+ CopyChars(new_name.start() + name_pos, dot, 1);
+ ++name_pos;
+ }
+ CopyChars(new_name.start() + name_pos,
+ names_stack_.at(i).name->literal_bytes.start(),
+ names_stack_.at(i).name->literal_bytes.length());
+ name_pos += names_stack_.at(i).name->literal_bytes.length();
}
+ to_return = symbol_table_->GetOneByteSymbol(Vector<const uint8_t>(
+ reinterpret_cast<const uint8_t*>(new_name.start()),
+ new_name.length()));
+ new_name.Dispose();
}
+ // FIXME: do it for two-byte too.
+ return to_return;
}
void FuncNameInferrer::InferFunctionsNames() {
- Handle<String> func_name = MakeNameFromStack();
+ ParserSymbolTable::Symbol* func_name = MakeNameFromStack();
for (int i = 0; i < funcs_to_infer_.length(); ++i) {
- funcs_to_infer_[i]->set_inferred_name(func_name);
+ funcs_to_infer_[i]->set_raw_inferred_name(func_name);
}
funcs_to_infer_.Rewind(0);
}

Powered by Google App Engine
This is Rietveld 408576698