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

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: more cleanup 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
« no previous file with comments | « src/func-name-inferrer.h ('k') | src/heap.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/func-name-inferrer.cc
diff --git a/src/func-name-inferrer.cc b/src/func-name-inferrer.cc
index 370d6264dff8d1ad278f88841467b1fff1225f05..788bd82919a79bc100c040c5279ad3a75e6b7744 100644
--- a/src/func-name-inferrer.cc
+++ b/src/func-name-inferrer.cc
@@ -5,14 +5,15 @@
#include "v8.h"
#include "ast.h"
+#include "ast-string-table.h"
#include "func-name-inferrer.h"
#include "list-inl.h"
namespace v8 {
namespace internal {
-FuncNameInferrer::FuncNameInferrer(Isolate* isolate, Zone* zone)
- : isolate_(isolate),
+FuncNameInferrer::FuncNameInferrer(AstStringTable* string_table, Zone* zone)
+ : string_table_(string_table),
entries_stack_(10, zone),
names_stack_(5, zone),
funcs_to_infer_(4, zone),
@@ -20,66 +21,119 @@ FuncNameInferrer::FuncNameInferrer(Isolate* isolate, Zone* zone)
}
-void FuncNameInferrer::PushEnclosingName(Handle<String> name) {
+void FuncNameInferrer::PushEnclosingName(const AstString* 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->length() > 0 && unibrow::Uppercase::Is(name->raw_data()[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(const AstString* name) {
+ if (IsOpen() && name != string_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(const AstString* name) {
+ if (IsOpen() && name != string_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);
+const AstString* 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->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;
+ }
+ const AstString* to_return = NULL;
+ const char* dot = ".";
+ if (one_byte) {
+ Vector<uint8_t> new_name = Vector<uint8_t>::New(length);
+ int name_pos = 0;
+ 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) {
+ // Skip consecutive variable declarations.
+ 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->raw_data(),
+ names_stack_.at(i).name->length());
+ name_pos += names_stack_.at(i).name->length();
+ }
+ to_return = string_table_->GetOneByteString(Vector<const uint8_t>(
+ reinterpret_cast<const uint8_t*>(new_name.start()),
+ new_name.length()));
+ new_name.Dispose();
} 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);
+ Vector<uint16_t> new_name = Vector<uint16_t>::New(length);
+ int name_pos = 0;
+ 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) {
+ // Skip consecutive variable declarations.
+ continue;
+ }
+ if (name_pos != 0) {
+ CopyChars(new_name.start() + name_pos, dot, 1);
+ ++name_pos;
+ }
+ if (names_stack_.at(i).name->is_one_byte()) {
+ CopyChars(new_name.start() + name_pos,
+ names_stack_.at(i).name->raw_data(),
+ names_stack_.at(i).name->length());
+ } else {
+ CopyChars(new_name.start() + name_pos,
+ reinterpret_cast<const uint16_t*>(
+ names_stack_.at(i).name->raw_data()),
+ names_stack_.at(i).name->length());
+ }
+ name_pos += names_stack_.at(i).name->length();
}
+ to_return = string_table_->GetTwoByteString(Vector<const uint16_t>(
+ reinterpret_cast<const uint16_t*>(new_name.start()),
+ new_name.length()));
+ new_name.Dispose();
}
+ return to_return;
}
void FuncNameInferrer::InferFunctionsNames() {
- Handle<String> func_name = MakeNameFromStack();
+ const AstString* 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);
}
« no previous file with comments | « src/func-name-inferrer.h ('k') | src/heap.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698