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

Unified Diff: runtime/vm/object.cc

Issue 289893002: - Make use of the fact that idents and literals are symbols. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: 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 | « no previous file | runtime/vm/scanner.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/object.cc
===================================================================
--- runtime/vm/object.cc (revision 36194)
+++ runtime/vm/object.cc (working copy)
@@ -7411,8 +7411,6 @@
// Add an IDENT token into the stream and the token objects array.
void AddIdentToken(const String* ident) {
- ASSERT(ident != NULL);
- ASSERT(ident->IsSymbol());
// If the IDENT token is already in the tokens object array use the
// same index instead of duplicating it.
intptr_t index = FindIdentIndex(ident);
@@ -7427,20 +7425,16 @@
// Add a LITERAL token into the stream and the token objects array.
void AddLiteralToken(Token::Kind kind, const String* literal) {
- if (literal != NULL) {
- // If the literal token is already in the tokens object array use the
- // same index instead of duplicating it.
- intptr_t index = FindLiteralIndex(kind, literal);
- if (index == -1) {
- WriteIndex(token_objects_.Length());
- ASSERT(literal != NULL);
- literal_token_ = LiteralToken::New(kind, *literal);
- token_objects_.Add(literal_token_);
- } else {
- WriteIndex(index);
- }
+ // If the literal token is already in the tokens object array use the
+ // same index instead of duplicating it.
+ intptr_t index = FindLiteralIndex(kind, literal);
+ if (index == -1) {
+ WriteIndex(token_objects_.Length());
+ ASSERT(literal != NULL);
+ literal_token_ = LiteralToken::New(kind, *literal);
+ token_objects_.Add(literal_token_);
} else {
- WriteIndex(0);
+ WriteIndex(index);
}
}
@@ -7463,16 +7457,13 @@
private:
intptr_t FindIdentIndex(const String* ident) {
ASSERT(ident != NULL);
+ ASSERT(ident->IsSymbol());
intptr_t hash_value = ident->Hash() % kTableSize;
GrowableArray<intptr_t>& value = ident_table_[hash_value];
for (intptr_t i = 0; i < value.length(); i++) {
intptr_t index = value[i];
- token_obj_ = token_objects_.At(index);
- if (token_obj_.IsString()) {
- const String& ident_str = String::Cast(token_obj_);
- if (ident->Equals(ident_str)) {
- return index;
- }
+ if (token_objects_.At(index) == ident->raw()) {
+ return index;
}
}
value.Add(token_objects_.Length());
@@ -7481,17 +7472,15 @@
intptr_t FindLiteralIndex(Token::Kind kind, const String* literal) {
ASSERT(literal != NULL);
+ ASSERT(literal->IsSymbol());
intptr_t hash_value = literal->Hash() % kTableSize;
GrowableArray<intptr_t>& value = literal_table_[hash_value];
for (intptr_t i = 0; i < value.length(); i++) {
intptr_t index = value[i];
token_obj_ = token_objects_.At(index);
- if (token_obj_.IsLiteralToken()) {
- const LiteralToken& token = LiteralToken::Cast(token_obj_);
- literal_str_ = token.literal();
- if (kind == token.kind() && literal->Equals(literal_str_)) {
- return index;
- }
+ const LiteralToken& token = LiteralToken::Cast(token_obj_);
+ if ((kind == token.kind()) && (token.literal() == literal->raw())) {
+ return index;
}
}
value.Add(token_objects_.Length());
« no previous file with comments | « no previous file | runtime/vm/scanner.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698