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

Side by Side Diff: src/heap.cc

Issue 5963003: Clean up is-ASCII checks. (Closed)
Patch Set: Created 10 years 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 | « no previous file | src/heap-inl.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 2010 the V8 project authors. All rights reserved. 1 // Copyright 2010 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 2531 matching lines...) Expand 10 before | Expand all | Expand 10 after
2542 2542
2543 MaybeObject* Heap::AllocateExternalStringFromTwoByte( 2543 MaybeObject* Heap::AllocateExternalStringFromTwoByte(
2544 ExternalTwoByteString::Resource* resource) { 2544 ExternalTwoByteString::Resource* resource) {
2545 size_t length = resource->length(); 2545 size_t length = resource->length();
2546 if (length > static_cast<size_t>(String::kMaxLength)) { 2546 if (length > static_cast<size_t>(String::kMaxLength)) {
2547 Top::context()->mark_out_of_memory(); 2547 Top::context()->mark_out_of_memory();
2548 return Failure::OutOfMemoryException(); 2548 return Failure::OutOfMemoryException();
2549 } 2549 }
2550 2550
2551 // For small strings we check whether the resource contains only 2551 // For small strings we check whether the resource contains only
2552 // ascii characters. If yes, we use a different string map. 2552 // ASCII characters. If yes, we use a different string map.
2553 bool is_ascii = true; 2553 static const size_t kAsciiCheckLengthLimit = 32;
2554 if (length >= static_cast<size_t>(String::kMinNonFlatLength)) { 2554 bool is_ascii = length <= kAsciiCheckLengthLimit &&
2555 is_ascii = false; 2555 String::IsAscii(resource->data(), length);
Mads Ager (chromium) 2010/12/22 07:46:24 Four-space indent?
2556 } else {
2557 const uc16* data = resource->data();
2558 for (size_t i = 0; i < length; i++) {
2559 if (data[i] > String::kMaxAsciiCharCode) {
2560 is_ascii = false;
2561 break;
2562 }
2563 }
2564 }
2565
2566 Map* map = is_ascii ? 2556 Map* map = is_ascii ?
2567 Heap::external_string_with_ascii_data_map() : Heap::external_string_map(); 2557 Heap::external_string_with_ascii_data_map() : Heap::external_string_map();
2568 Object* result; 2558 Object* result;
2569 { MaybeObject* maybe_result = Allocate(map, NEW_SPACE); 2559 { MaybeObject* maybe_result = Allocate(map, NEW_SPACE);
2570 if (!maybe_result->ToObject(&result)) return maybe_result; 2560 if (!maybe_result->ToObject(&result)) return maybe_result;
2571 } 2561 }
2572 2562
2573 ExternalTwoByteString* external_string = ExternalTwoByteString::cast(result); 2563 ExternalTwoByteString* external_string = ExternalTwoByteString::cast(result);
2574 external_string->set_length(static_cast<int>(length)); 2564 external_string->set_length(static_cast<int>(length));
2575 external_string->set_hash_field(String::kEmptyHashField); 2565 external_string->set_hash_field(String::kEmptyHashField);
(...skipping 759 matching lines...) Expand 10 before | Expand all | Expand 10 after
3335 if (r > kMaxSupportedChar) { r = unibrow::Utf8::kBadChar; } 3325 if (r > kMaxSupportedChar) { r = unibrow::Utf8::kBadChar; }
3336 string_result->Set(i, r); 3326 string_result->Set(i, r);
3337 } 3327 }
3338 return result; 3328 return result;
3339 } 3329 }
3340 3330
3341 3331
3342 MaybeObject* Heap::AllocateStringFromTwoByte(Vector<const uc16> string, 3332 MaybeObject* Heap::AllocateStringFromTwoByte(Vector<const uc16> string,
3343 PretenureFlag pretenure) { 3333 PretenureFlag pretenure) {
3344 // Check if the string is an ASCII string. 3334 // Check if the string is an ASCII string.
3345 int i = 0;
3346 while (i < string.length() && string[i] <= String::kMaxAsciiCharCode) i++;
3347
3348 MaybeObject* maybe_result; 3335 MaybeObject* maybe_result;
3349 if (i == string.length()) { // It's an ASCII string. 3336 if (String::IsAscii(string.start(), string.length())) {
3350 maybe_result = AllocateRawAsciiString(string.length(), pretenure); 3337 maybe_result = AllocateRawAsciiString(string.length(), pretenure);
3351 } else { // It's not an ASCII string. 3338 } else { // It's not an ASCII string.
3352 maybe_result = AllocateRawTwoByteString(string.length(), pretenure); 3339 maybe_result = AllocateRawTwoByteString(string.length(), pretenure);
3353 } 3340 }
3354 Object* result; 3341 Object* result;
3355 if (!maybe_result->ToObject(&result)) return maybe_result; 3342 if (!maybe_result->ToObject(&result)) return maybe_result;
3356 3343
3357 // Copy the characters into the new object, which may be either ASCII or 3344 // Copy the characters into the new object, which may be either ASCII or
3358 // UTF-16. 3345 // UTF-16.
3359 String* string_result = String::cast(result); 3346 String* string_result = String::cast(result);
(...skipping 2153 matching lines...) Expand 10 before | Expand all | Expand 10 after
5513 void ExternalStringTable::TearDown() { 5500 void ExternalStringTable::TearDown() {
5514 new_space_strings_.Free(); 5501 new_space_strings_.Free();
5515 old_space_strings_.Free(); 5502 old_space_strings_.Free();
5516 } 5503 }
5517 5504
5518 5505
5519 List<Object*> ExternalStringTable::new_space_strings_; 5506 List<Object*> ExternalStringTable::new_space_strings_;
5520 List<Object*> ExternalStringTable::old_space_strings_; 5507 List<Object*> ExternalStringTable::old_space_strings_;
5521 5508
5522 } } // namespace v8::internal 5509 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | src/heap-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698