Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 222 | 222 |
| 223 const AstRawString* AstValueFactory::GetTwoByteString( | 223 const AstRawString* AstValueFactory::GetTwoByteString( |
| 224 Vector<const uint16_t> literal) { | 224 Vector<const uint16_t> literal) { |
| 225 uint32_t hash = StringHasher::HashSequentialString<uint16_t>( | 225 uint32_t hash = StringHasher::HashSequentialString<uint16_t>( |
| 226 literal.start(), literal.length(), hash_seed_); | 226 literal.start(), literal.length(), hash_seed_); |
| 227 return GetString(hash, false, Vector<const byte>::cast(literal)); | 227 return GetString(hash, false, Vector<const byte>::cast(literal)); |
| 228 } | 228 } |
| 229 | 229 |
| 230 | 230 |
| 231 const AstRawString* AstValueFactory::GetString(Handle<String> literal) { | 231 const AstRawString* AstValueFactory::GetString(Handle<String> literal) { |
| 232 // For the FlatContent to stay valid, we shouldn't do any heap | |
| 233 // allocation. Make sure we won't try to internalize the string in GetString. | |
| 234 AstRawString* result = NULL; | |
| 235 Isolate* saved_isolate = isolate_; | |
| 236 isolate_ = NULL; | |
| 232 DisallowHeapAllocation no_gc; | 237 DisallowHeapAllocation no_gc; |
| 233 String::FlatContent content = literal->GetFlatContent(); | 238 String::FlatContent content = literal->GetFlatContent(); |
| 234 if (content.IsOneByte()) { | 239 if (content.IsOneByte()) { |
| 235 return GetOneByteString(content.ToOneByteVector()); | 240 Vector<const uint8_t> literal = content.ToOneByteVector(); |
|
rossberg
2014/11/05 12:39:51
I'm confused, what's the reason to inline these fu
marja
2014/11/05 12:41:41
constness.
Another option would be to make these
rossberg
2014/11/05 12:46:21
Why not make the functions non-const but private,
| |
| 241 uint32_t hash = StringHasher::HashSequentialString<uint8_t>( | |
| 242 literal.start(), literal.length(), hash_seed_); | |
| 243 result = GetString(hash, true, literal); | |
| 244 } else { | |
| 245 DCHECK(content.IsTwoByte()); | |
| 246 Vector<const uint16_t> literal = content.ToUC16Vector(); | |
| 247 uint32_t hash = StringHasher::HashSequentialString<uint16_t>( | |
| 248 literal.start(), literal.length(), hash_seed_); | |
| 249 result = GetString(hash, false, Vector<const byte>::cast(literal)); | |
| 236 } | 250 } |
| 237 DCHECK(content.IsTwoByte()); | 251 isolate_ = saved_isolate; |
| 238 return GetTwoByteString(content.ToUC16Vector()); | 252 result->string_ = literal; |
| 253 return result; | |
| 239 } | 254 } |
| 240 | 255 |
| 241 | 256 |
| 242 const AstConsString* AstValueFactory::NewConsString( | 257 const AstConsString* AstValueFactory::NewConsString( |
| 243 const AstString* left, const AstString* right) { | 258 const AstString* left, const AstString* right) { |
| 244 // This Vector will be valid as long as the Collector is alive (meaning that | 259 // This Vector will be valid as long as the Collector is alive (meaning that |
| 245 // the AstRawString will not be moved). | 260 // the AstRawString will not be moved). |
| 246 AstConsString* new_string = new (zone_) AstConsString(left, right); | 261 AstConsString* new_string = new (zone_) AstConsString(left, right); |
| 247 strings_.Add(new_string); | 262 strings_.Add(new_string); |
| 248 if (isolate_) { | 263 if (isolate_) { |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 341 } | 356 } |
| 342 | 357 |
| 343 | 358 |
| 344 const AstValue* AstValueFactory::NewTheHole() { | 359 const AstValue* AstValueFactory::NewTheHole() { |
| 345 GENERATE_VALUE_GETTER(the_hole_value_, AstValue::THE_HOLE); | 360 GENERATE_VALUE_GETTER(the_hole_value_, AstValue::THE_HOLE); |
| 346 } | 361 } |
| 347 | 362 |
| 348 | 363 |
| 349 #undef GENERATE_VALUE_GETTER | 364 #undef GENERATE_VALUE_GETTER |
| 350 | 365 |
| 351 const AstRawString* AstValueFactory::GetString( | 366 AstRawString* AstValueFactory::GetString(uint32_t hash, bool is_one_byte, |
| 352 uint32_t hash, bool is_one_byte, Vector<const byte> literal_bytes) { | 367 Vector<const byte> literal_bytes) { |
| 353 // literal_bytes here points to whatever the user passed, and this is OK | 368 // 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 | 369 // because we use vector_compare (which checks the contents) to compare |
| 355 // against the AstRawStrings which are in the string_table_. We should not | 370 // against the AstRawStrings which are in the string_table_. We should not |
| 356 // return this AstRawString. | 371 // return this AstRawString. |
| 357 AstRawString key(is_one_byte, literal_bytes, hash); | 372 AstRawString key(is_one_byte, literal_bytes, hash); |
| 358 HashMap::Entry* entry = string_table_.Lookup(&key, hash, true); | 373 HashMap::Entry* entry = string_table_.Lookup(&key, hash, true); |
| 359 if (entry->value == NULL) { | 374 if (entry->value == NULL) { |
| 360 // Copy literal contents for later comparison. | 375 // Copy literal contents for later comparison. |
| 361 int length = literal_bytes.length(); | 376 int length = literal_bytes.length(); |
| 362 byte* new_literal_bytes = zone_->NewArray<byte>(length); | 377 byte* new_literal_bytes = zone_->NewArray<byte>(length); |
| 363 memcpy(new_literal_bytes, literal_bytes.start(), length); | 378 memcpy(new_literal_bytes, literal_bytes.start(), length); |
| 364 AstRawString* new_string = new (zone_) AstRawString( | 379 AstRawString* new_string = new (zone_) AstRawString( |
| 365 is_one_byte, Vector<const byte>(new_literal_bytes, length), hash); | 380 is_one_byte, Vector<const byte>(new_literal_bytes, length), hash); |
| 366 entry->key = new_string; | 381 entry->key = new_string; |
| 367 strings_.Add(new_string); | 382 strings_.Add(new_string); |
| 368 if (isolate_) { | 383 if (isolate_) { |
| 369 new_string->Internalize(isolate_); | 384 new_string->Internalize(isolate_); |
| 370 } | 385 } |
| 371 entry->value = reinterpret_cast<void*>(1); | 386 entry->value = reinterpret_cast<void*>(1); |
| 372 } | 387 } |
| 373 return reinterpret_cast<AstRawString*>(entry->key); | 388 return reinterpret_cast<AstRawString*>(entry->key); |
| 374 } | 389 } |
| 375 | 390 |
| 376 | 391 |
| 377 } } // namespace v8::internal | 392 } } // namespace v8::internal |
| OLD | NEW |