Removed the Isolate* field from literal nodes.

Again 50MB less peak memory usage in the bug mentioned below...

BUG=417697
LOG=y
R=dcarney@chromium.org

Review URL: https://codereview.chromium.org/620113002

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@24396 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent c9c4b931
...@@ -117,14 +117,15 @@ bool AstRawString::IsOneByteEqualTo(const char* data) const { ...@@ -117,14 +117,15 @@ bool AstRawString::IsOneByteEqualTo(const char* data) const {
bool AstRawString::Compare(void* a, void* b) { bool AstRawString::Compare(void* a, void* b) {
AstRawString* string1 = reinterpret_cast<AstRawString*>(a); return *static_cast<AstRawString*>(a) == *static_cast<AstRawString*>(b);
AstRawString* string2 = reinterpret_cast<AstRawString*>(b); }
if (string1->is_one_byte_ != string2->is_one_byte_) return false;
if (string1->hash_ != string2->hash_) return false; bool AstRawString::operator==(const AstRawString& rhs) const {
int length = string1->literal_bytes_.length(); if (is_one_byte_ != rhs.is_one_byte_) return false;
if (string2->literal_bytes_.length() != length) return false; if (hash_ != rhs.hash_) return false;
return memcmp(string1->literal_bytes_.start(), int len = literal_bytes_.length();
string2->literal_bytes_.start(), length) == 0; if (rhs.literal_bytes_.length() != len) return false;
return memcmp(literal_bytes_.start(), rhs.literal_bytes_.start(), len) == 0;
} }
......
...@@ -94,6 +94,8 @@ class AstRawString : public AstString { ...@@ -94,6 +94,8 @@ class AstRawString : public AstString {
} }
static bool Compare(void* a, void* b); static bool Compare(void* a, void* b);
bool operator==(const AstRawString& rhs) const;
private: private:
friend class AstValueFactory; friend class AstValueFactory;
friend class AstRawStringInternalizationKey; friend class AstRawStringInternalizationKey;
......
...@@ -1126,20 +1126,19 @@ void AstConstructionVisitor::VisitCallRuntime(CallRuntime* node) { ...@@ -1126,20 +1126,19 @@ void AstConstructionVisitor::VisitCallRuntime(CallRuntime* node) {
#undef DONT_CACHE_NODE #undef DONT_CACHE_NODE
Handle<String> Literal::ToString() { uint32_t Literal::Hash() {
if (value_->IsString()) return value_->AsString()->string(); return raw_value()->IsString()
DCHECK(value_->IsNumber()); ? raw_value()->AsString()->hash()
char arr[100]; : ComputeLongHash(double_to_uint64(raw_value()->AsNumber()));
Vector<char> buffer(arr, arraysize(arr)); }
const char* str;
if (value()->IsSmi()) {
// Optimization only, the heap number case would subsume this. // static
SNPrintF(buffer, "%d", Smi::cast(*value())->value()); bool Literal::Match(void* literal1, void* literal2) {
str = arr; const AstValue* x = static_cast<Literal*>(literal1)->raw_value();
} else { const AstValue* y = static_cast<Literal*>(literal2)->raw_value();
str = DoubleToCString(value()->Number(), buffer); return (x->IsString() && y->IsString() && *x->AsString() == *y->AsString()) ||
} (x->IsNumber() && y->IsNumber() && x->AsNumber() == y->AsNumber());
return isolate_->factory()->NewStringFromAsciiChecked(str);
} }
......
...@@ -1385,28 +1385,17 @@ class Literal FINAL : public Expression { ...@@ -1385,28 +1385,17 @@ class Literal FINAL : public Expression {
// Support for using Literal as a HashMap key. NOTE: Currently, this works // Support for using Literal as a HashMap key. NOTE: Currently, this works
// only for string and number literals! // only for string and number literals!
uint32_t Hash() { return ToString()->Hash(); } uint32_t Hash();
static bool Match(void* literal1, void* literal2);
static bool Match(void* literal1, void* literal2) {
Handle<String> s1 = static_cast<Literal*>(literal1)->ToString();
Handle<String> s2 = static_cast<Literal*>(literal2)->ToString();
return String::Equals(s1, s2);
}
TypeFeedbackId LiteralFeedbackId() const { return reuse(id()); } TypeFeedbackId LiteralFeedbackId() const { return reuse(id()); }
protected: protected:
Literal(Zone* zone, const AstValue* value, int position, IdGen* id_gen) Literal(Zone* zone, const AstValue* value, int position, IdGen* id_gen)
: Expression(zone, position, id_gen), : Expression(zone, position, id_gen), value_(value) {}
value_(value),
isolate_(zone->isolate()) {}
private: private:
Handle<String> ToString();
const AstValue* value_; const AstValue* value_;
// TODO(dcarney): remove. this is only needed for Match and Hash.
Isolate* isolate_;
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment