Clean up is-ASCII checks.
Review URL: http://codereview.chromium.org/5963003 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@6109 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
parent
4330070e32
commit
52d2ce3b5a
@ -43,16 +43,14 @@ int Heap::MaxObjectSizeInPagedSpace() {
|
||||
MaybeObject* Heap::AllocateStringFromUtf8(Vector<const char> str,
|
||||
PretenureFlag pretenure) {
|
||||
// Check for ASCII first since this is the common case.
|
||||
for (int i = 0; i < str.length(); ++i) {
|
||||
if (static_cast<uint8_t>(str[i]) > String::kMaxAsciiCharCodeU) {
|
||||
// Non-ASCII and we need to decode.
|
||||
return AllocateStringFromUtf8Slow(str, pretenure);
|
||||
}
|
||||
}
|
||||
if (String::IsAscii(str.start(), str.length())) {
|
||||
// If the string is ASCII, we do not need to convert the characters
|
||||
// since UTF8 is backwards compatible with ASCII.
|
||||
return AllocateStringFromAscii(str, pretenure);
|
||||
}
|
||||
// Non-ASCII and we need to decode.
|
||||
return AllocateStringFromUtf8Slow(str, pretenure);
|
||||
}
|
||||
|
||||
|
||||
MaybeObject* Heap::AllocateSymbol(Vector<const char> str,
|
||||
|
23
src/heap.cc
23
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);
|
||||
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);
|
||||
|
@ -211,9 +211,7 @@ void RegExpMacroAssemblerIA32::CheckCharacters(Vector<const uc16> str,
|
||||
// If input is ASCII, don't even bother calling here if the string to
|
||||
// match contains a non-ascii character.
|
||||
if (mode_ == ASCII) {
|
||||
for (int i = 0; i < str.length(); i++) {
|
||||
ASSERT(str[i] <= String::kMaxAsciiCharCodeU);
|
||||
}
|
||||
ASSERT(String::IsAscii(str.start(), str.length()));
|
||||
}
|
||||
#endif
|
||||
int byte_length = str.length() * char_size();
|
||||
|
@ -5245,6 +5245,34 @@ class String: public HeapObject {
|
||||
int from,
|
||||
int to);
|
||||
|
||||
static inline bool IsAscii(const char* chars, int length) {
|
||||
const char* limit = chars + length;
|
||||
#ifdef V8_HOST_CAN_READ_UNALIGNED
|
||||
ASSERT(kMaxAsciiCharCode == 0x7F);
|
||||
const uintptr_t non_ascii_mask = kUintptrAllBitsSet / 0xFF * 0x80;
|
||||
while (chars <= limit - sizeof(uintptr_t)) {
|
||||
if (*reinterpret_cast<const uintptr_t*>(chars) & non_ascii_mask) {
|
||||
return false;
|
||||
}
|
||||
chars += sizeof(uintptr_t);
|
||||
}
|
||||
#endif
|
||||
while (chars < limit) {
|
||||
if (static_cast<uint8_t>(*chars) > kMaxAsciiCharCodeU) return false;
|
||||
++chars;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static inline bool IsAscii(const uc16* chars, int length) {
|
||||
const uc16* limit = chars + length;
|
||||
while (chars < limit) {
|
||||
if (*chars > kMaxAsciiCharCodeU) return false;
|
||||
++chars;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
protected:
|
||||
class ReadBlockBuffer {
|
||||
public:
|
||||
|
@ -66,12 +66,7 @@ class StringSearchBase {
|
||||
}
|
||||
|
||||
static inline bool IsAsciiString(Vector<const uc16> string) {
|
||||
for (int i = 0, n = string.length(); i < n; i++) {
|
||||
if (static_cast<unsigned>(string[i]) > String::kMaxAsciiCharCodeU) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
return String::IsAscii(string.start(), string.length());
|
||||
}
|
||||
|
||||
// The following tables are shared by all searches.
|
||||
|
@ -223,9 +223,7 @@ void RegExpMacroAssemblerX64::CheckCharacters(Vector<const uc16> str,
|
||||
// If input is ASCII, don't even bother calling here if the string to
|
||||
// match contains a non-ascii character.
|
||||
if (mode_ == ASCII) {
|
||||
for (int i = 0; i < str.length(); i++) {
|
||||
ASSERT(str[i] <= String::kMaxAsciiCharCodeU);
|
||||
}
|
||||
ASSERT(String::IsAscii(str.start(), str.length()));
|
||||
}
|
||||
#endif
|
||||
int byte_length = str.length() * char_size();
|
||||
|
Loading…
Reference in New Issue
Block a user