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

Side by Side Diff: src/ast/ast-value-factory.cc

Issue 2687933003: [Parser] Cache and clone initial AstValueFactory string_table_. (Closed)
Patch Set: Address comments Created 3 years, 10 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 unified diff | Download patch
« no previous file with comments | « src/ast/ast-value-factory.h ('k') | src/base/hashmap.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 122
123 bool AstRawString::IsOneByteEqualTo(const char* data) const { 123 bool AstRawString::IsOneByteEqualTo(const char* data) const {
124 int length = static_cast<int>(strlen(data)); 124 int length = static_cast<int>(strlen(data));
125 if (is_one_byte() && literal_bytes_.length() == length) { 125 if (is_one_byte() && literal_bytes_.length() == length) {
126 const char* token = reinterpret_cast<const char*>(literal_bytes_.start()); 126 const char* token = reinterpret_cast<const char*>(literal_bytes_.start());
127 return !strncmp(token, data, length); 127 return !strncmp(token, data, length);
128 } 128 }
129 return false; 129 return false;
130 } 130 }
131 131
132 bool AstRawString::Compare(void* a, void* b) {
133 const AstRawString* lhs = static_cast<AstRawString*>(a);
134 const AstRawString* rhs = static_cast<AstRawString*>(b);
135 DCHECK_EQ(lhs->hash(), rhs->hash());
136 if (lhs->length() != rhs->length()) return false;
137 const unsigned char* l = lhs->raw_data();
138 const unsigned char* r = rhs->raw_data();
139 size_t length = rhs->length();
140 if (lhs->is_one_byte()) {
141 if (rhs->is_one_byte()) {
142 return CompareCharsUnsigned(reinterpret_cast<const uint8_t*>(l),
143 reinterpret_cast<const uint8_t*>(r),
144 length) == 0;
145 } else {
146 return CompareCharsUnsigned(reinterpret_cast<const uint8_t*>(l),
147 reinterpret_cast<const uint16_t*>(r),
148 length) == 0;
149 }
150 } else {
151 if (rhs->is_one_byte()) {
152 return CompareCharsUnsigned(reinterpret_cast<const uint16_t*>(l),
153 reinterpret_cast<const uint8_t*>(r),
154 length) == 0;
155 } else {
156 return CompareCharsUnsigned(reinterpret_cast<const uint16_t*>(l),
157 reinterpret_cast<const uint16_t*>(r),
158 length) == 0;
159 }
160 }
161 }
132 162
133 void AstConsString::Internalize(Isolate* isolate) { 163 void AstConsString::Internalize(Isolate* isolate) {
134 // AstRawStrings are internalized before AstConsStrings so left and right are 164 // AstRawStrings are internalized before AstConsStrings so left and right are
135 // already internalized. 165 // already internalized.
136 set_string(isolate->factory() 166 set_string(isolate->factory()
137 ->NewConsString(left_->string(), right_->string()) 167 ->NewConsString(left_->string(), right_->string())
138 .ToHandleChecked()); 168 .ToHandleChecked());
139 } 169 }
140 170
141 bool AstValue::IsPropertyName() const { 171 bool AstValue::IsPropertyName() const {
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 #undef GENERATE_VALUE_GETTER 379 #undef GENERATE_VALUE_GETTER
350 380
351 AstRawString* AstValueFactory::GetString(uint32_t hash, bool is_one_byte, 381 AstRawString* AstValueFactory::GetString(uint32_t hash, bool is_one_byte,
352 Vector<const byte> literal_bytes) { 382 Vector<const byte> literal_bytes) {
353 // literal_bytes here points to whatever the user passed, and this is OK 383 // literal_bytes here points to whatever the user passed, and this is OK
354 // because we use vector_compare (which checks the contents) to compare 384 // because we use vector_compare (which checks the contents) to compare
355 // against the AstRawStrings which are in the string_table_. We should not 385 // against the AstRawStrings which are in the string_table_. We should not
356 // return this AstRawString. 386 // return this AstRawString.
357 AstRawString key(is_one_byte, literal_bytes, hash); 387 AstRawString key(is_one_byte, literal_bytes, hash);
358 base::HashMap::Entry* entry = string_table_.LookupOrInsert(&key, hash); 388 base::HashMap::Entry* entry = string_table_.LookupOrInsert(&key, hash);
359 if (entry->value == NULL) { 389 if (entry->value == nullptr) {
360 // Copy literal contents for later comparison. 390 // Copy literal contents for later comparison.
361 int length = literal_bytes.length(); 391 int length = literal_bytes.length();
362 byte* new_literal_bytes = zone_->NewArray<byte>(length); 392 byte* new_literal_bytes = zone_->NewArray<byte>(length);
363 memcpy(new_literal_bytes, literal_bytes.start(), length); 393 memcpy(new_literal_bytes, literal_bytes.start(), length);
364 AstRawString* new_string = new (zone_) AstRawString( 394 AstRawString* new_string = new (zone_) AstRawString(
365 is_one_byte, Vector<const byte>(new_literal_bytes, length), hash); 395 is_one_byte, Vector<const byte>(new_literal_bytes, length), hash);
366 CHECK_NOT_NULL(new_string); 396 CHECK_NOT_NULL(new_string);
367 AddString(new_string); 397 AddString(new_string);
368 entry->key = new_string; 398 entry->key = new_string;
369 entry->value = reinterpret_cast<void*>(1); 399 entry->value = reinterpret_cast<void*>(1);
370 } 400 }
371 return reinterpret_cast<AstRawString*>(entry->key); 401 return reinterpret_cast<AstRawString*>(entry->key);
372 } 402 }
373 403
374
375 bool AstValueFactory::AstRawStringCompare(void* a, void* b) {
376 const AstRawString* lhs = static_cast<AstRawString*>(a);
377 const AstRawString* rhs = static_cast<AstRawString*>(b);
378 DCHECK_EQ(lhs->hash(), rhs->hash());
379 if (lhs->length() != rhs->length()) return false;
380 const unsigned char* l = lhs->raw_data();
381 const unsigned char* r = rhs->raw_data();
382 size_t length = rhs->length();
383 if (lhs->is_one_byte()) {
384 if (rhs->is_one_byte()) {
385 return CompareCharsUnsigned(reinterpret_cast<const uint8_t*>(l),
386 reinterpret_cast<const uint8_t*>(r),
387 length) == 0;
388 } else {
389 return CompareCharsUnsigned(reinterpret_cast<const uint8_t*>(l),
390 reinterpret_cast<const uint16_t*>(r),
391 length) == 0;
392 }
393 } else {
394 if (rhs->is_one_byte()) {
395 return CompareCharsUnsigned(reinterpret_cast<const uint16_t*>(l),
396 reinterpret_cast<const uint8_t*>(r),
397 length) == 0;
398 } else {
399 return CompareCharsUnsigned(reinterpret_cast<const uint16_t*>(l),
400 reinterpret_cast<const uint16_t*>(r),
401 length) == 0;
402 }
403 }
404 }
405 } // namespace internal 404 } // namespace internal
406 } // namespace v8 405 } // namespace v8
OLDNEW
« no previous file with comments | « src/ast/ast-value-factory.h ('k') | src/base/hashmap.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698