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 {
bool AstRawString::Compare(void* a, void* b) {
AstRawString* string1 = reinterpret_cast<AstRawString*>(a);
AstRawString* string2 = reinterpret_cast<AstRawString*>(b);
if (string1->is_one_byte_ != string2->is_one_byte_) return false;
if (string1->hash_ != string2->hash_) return false;
int length = string1->literal_bytes_.length();
if (string2->literal_bytes_.length() != length) return false;
return memcmp(string1->literal_bytes_.start(),
string2->literal_bytes_.start(), length) == 0;
return *static_cast<AstRawString*>(a) == *static_cast<AstRawString*>(b);
}
bool AstRawString::operator==(const AstRawString& rhs) const {
if (is_one_byte_ != rhs.is_one_byte_) return false;
if (hash_ != rhs.hash_) return false;
int len = literal_bytes_.length();
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 {
}
static bool Compare(void* a, void* b);
bool operator==(const AstRawString& rhs) const;
private:
friend class AstValueFactory;
friend class AstRawStringInternalizationKey;
......
......@@ -1126,20 +1126,19 @@ void AstConstructionVisitor::VisitCallRuntime(CallRuntime* node) {
#undef DONT_CACHE_NODE
Handle<String> Literal::ToString() {
if (value_->IsString()) return value_->AsString()->string();
DCHECK(value_->IsNumber());
char arr[100];
Vector<char> buffer(arr, arraysize(arr));
const char* str;
if (value()->IsSmi()) {
// Optimization only, the heap number case would subsume this.
SNPrintF(buffer, "%d", Smi::cast(*value())->value());
str = arr;
} else {
str = DoubleToCString(value()->Number(), buffer);
}
return isolate_->factory()->NewStringFromAsciiChecked(str);
uint32_t Literal::Hash() {
return raw_value()->IsString()
? raw_value()->AsString()->hash()
: ComputeLongHash(double_to_uint64(raw_value()->AsNumber()));
}
// static
bool Literal::Match(void* literal1, void* literal2) {
const AstValue* x = static_cast<Literal*>(literal1)->raw_value();
const AstValue* y = static_cast<Literal*>(literal2)->raw_value();
return (x->IsString() && y->IsString() && *x->AsString() == *y->AsString()) ||
(x->IsNumber() && y->IsNumber() && x->AsNumber() == y->AsNumber());
}
......
......@@ -1385,28 +1385,17 @@ class Literal FINAL : public Expression {
// Support for using Literal as a HashMap key. NOTE: Currently, this works
// only for string and number literals!
uint32_t Hash() { return ToString()->Hash(); }
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);
}
uint32_t Hash();
static bool Match(void* literal1, void* literal2);
TypeFeedbackId LiteralFeedbackId() const { return reuse(id()); }
protected:
Literal(Zone* zone, const AstValue* value, int position, IdGen* id_gen)
: Expression(zone, position, id_gen),
value_(value),
isolate_(zone->isolate()) {}
: Expression(zone, position, id_gen), value_(value) {}
private:
Handle<String> ToString();
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