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 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 const AstConsString* AstValueFactory::NewConsString( | 253 const AstConsString* AstValueFactory::NewConsString( |
254 const AstString* left, const AstString* right) { | 254 const AstString* left, const AstString* right) { |
255 // This Vector will be valid as long as the Collector is alive (meaning that | 255 // This Vector will be valid as long as the Collector is alive (meaning that |
256 // the AstRawString will not be moved). | 256 // the AstRawString will not be moved). |
257 AstConsString* new_string = new (zone_) AstConsString(left, right); | 257 AstConsString* new_string = new (zone_) AstConsString(left, right); |
258 CHECK(new_string != nullptr); | 258 CHECK(new_string != nullptr); |
259 AddString(new_string); | 259 AddString(new_string); |
260 return new_string; | 260 return new_string; |
261 } | 261 } |
262 | 262 |
263 const AstRawString* AstValueFactory::ConcatStrings(const AstRawString* left, | |
264 const AstRawString* right) { | |
265 int left_length = left->length(); | |
266 int right_length = right->length(); | |
267 const unsigned char* left_data = left->raw_data(); | |
268 const unsigned char* right_data = right->raw_data(); | |
269 if (left->is_one_byte() && right->is_one_byte()) { | |
270 uint8_t* buffer = zone_->NewArray<uint8_t>(left_length + right_length); | |
271 memcpy(buffer, left_data, left_length); | |
272 memcpy(buffer + left_length, right_data, right_length); | |
273 Vector<const uint8_t> literal(buffer, left_length + right_length); | |
274 return GetOneByteStringInternal(literal); | |
275 } else { | |
276 uint16_t* buffer = zone_->NewArray<uint16_t>(left_length + right_length); | |
277 if (left->is_one_byte()) { | |
278 for (int i = 0; i < left_length; ++i) { | |
279 buffer[i] = left_data[i]; | |
280 } | |
281 } else { | |
282 memcpy(buffer, left_data, 2 * left_length); | |
283 } | |
284 if (right->is_one_byte()) { | |
285 for (int i = 0; i < right_length; ++i) { | |
286 buffer[i + left_length] = right_data[i]; | |
287 } | |
288 } else { | |
289 memcpy(buffer + left_length, right_data, 2 * right_length); | |
290 } | |
291 Vector<const uint16_t> literal(buffer, left_length + right_length); | |
292 return GetTwoByteStringInternal(literal); | |
293 } | |
294 } | |
295 | |
296 void AstValueFactory::Internalize(Isolate* isolate) { | 263 void AstValueFactory::Internalize(Isolate* isolate) { |
297 // Strings need to be internalized before values, because values refer to | 264 // Strings need to be internalized before values, because values refer to |
298 // strings. | 265 // strings. |
299 for (AstString* current = strings_; current != nullptr;) { | 266 for (AstString* current = strings_; current != nullptr;) { |
300 AstString* next = current->next(); | 267 AstString* next = current->next(); |
301 current->Internalize(isolate); | 268 current->Internalize(isolate); |
302 current = next; | 269 current = next; |
303 } | 270 } |
304 | 271 |
305 for (AstValue* current = values_; current != nullptr;) { | 272 for (AstValue* current = values_; current != nullptr;) { |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
420 length) == 0; | 387 length) == 0; |
421 } else { | 388 } else { |
422 return CompareCharsUnsigned(reinterpret_cast<const uint16_t*>(l), | 389 return CompareCharsUnsigned(reinterpret_cast<const uint16_t*>(l), |
423 reinterpret_cast<const uint16_t*>(r), | 390 reinterpret_cast<const uint16_t*>(r), |
424 length) == 0; | 391 length) == 0; |
425 } | 392 } |
426 } | 393 } |
427 } | 394 } |
428 } // namespace internal | 395 } // namespace internal |
429 } // namespace v8 | 396 } // namespace v8 |
OLD | NEW |