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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/heap-inl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/heap.cc
diff --git a/src/heap.cc b/src/heap.cc
index 2f70ef0188dbad295cb44622708e2dec3c4a4b24..4713f69e2f0e622b9e2ec9db99a28d24ef148ce5 100644
--- a/src/heap.cc
+++ b/src/heap.cc
@@ -2549,20 +2549,10 @@ MaybeObject* Heap::AllocateExternalStringFromTwoByte(
}
// For small strings we check whether the resource contains only
- // ascii characters. If yes, we use a different string map.
- bool is_ascii = true;
- if (length >= static_cast<size_t>(String::kMinNonFlatLength)) {
- is_ascii = false;
- } else {
- const uc16* data = resource->data();
- for (size_t i = 0; i < length; i++) {
- if (data[i] > String::kMaxAsciiCharCode) {
- is_ascii = false;
- break;
- }
- }
- }
-
+ // ASCII characters. If yes, we use a different string map.
+ static const size_t kAsciiCheckLengthLimit = 32;
+ bool is_ascii = length <= kAsciiCheckLengthLimit &&
+ String::IsAscii(resource->data(), length);
Mads Ager (chromium) 2010/12/22 07:46:24 Four-space indent?
Map* map = is_ascii ?
Heap::external_string_with_ascii_data_map() : Heap::external_string_map();
Object* result;
@@ -3342,11 +3332,8 @@ MaybeObject* Heap::AllocateStringFromUtf8Slow(Vector<const char> string,
MaybeObject* Heap::AllocateStringFromTwoByte(Vector<const uc16> string,
PretenureFlag pretenure) {
// Check if the string is an ASCII string.
- int i = 0;
- while (i < string.length() && string[i] <= String::kMaxAsciiCharCode) i++;
-
MaybeObject* maybe_result;
- if (i == string.length()) { // It's an ASCII string.
+ if (String::IsAscii(string.start(), string.length())) {
maybe_result = AllocateRawAsciiString(string.length(), pretenure);
} else { // It's not an ASCII string.
maybe_result = AllocateRawTwoByteString(string.length(), pretenure);
« 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