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

Unified Diff: runtime/vm/object.cc

Issue 2952193002: VM: Speed up output of UTF8 for 1-byte strings.
Patch Set: Add test that would have caught bug pointed out by Slava Created 3 years, 3 months 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 | « runtime/vm/object.h ('k') | runtime/vm/raw_object_snapshot.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/object.cc
diff --git a/runtime/vm/object.cc b/runtime/vm/object.cc
index cfd08f6c964c7df53dd6dcd9cfd761f14f4b44e4..e97eccc5442aeece7bf153c0c1de817b383259dc 100644
--- a/runtime/vm/object.cc
+++ b/runtime/vm/object.cc
@@ -19857,14 +19857,14 @@ RawString* String::FromUTF8(const uint8_t* utf8_array,
if (len > 0) {
NoSafepointScope no_safepoint;
Utf8::DecodeToLatin1(utf8_array, array_len,
- OneByteString::CharAddr(strobj, 0), len);
+ OneByteString::DataStart(strobj), len);
}
return strobj.raw();
}
ASSERT((type == Utf8::kBMP) || (type == Utf8::kSupplementary));
const String& strobj = String::Handle(TwoByteString::New(len, space));
NoSafepointScope no_safepoint;
- Utf8::DecodeToUTF16(utf8_array, array_len, TwoByteString::CharAddr(strobj, 0),
+ Utf8::DecodeToUTF16(utf8_array, array_len, TwoByteString::DataStart(strobj),
len);
return strobj.raw();
}
@@ -20301,29 +20301,6 @@ RawString* String::SubString(Thread* thread,
}
const char* String::ToCString() const {
- if (IsOneByteString()) {
- // Quick conversion if OneByteString contains only ASCII characters.
- intptr_t len = Length();
- if (len == 0) {
- return "";
- }
- Zone* zone = Thread::Current()->zone();
- uint8_t* result = zone->Alloc<uint8_t>(len + 1);
- NoSafepointScope no_safepoint;
- const uint8_t* original_str = OneByteString::CharAddr(*this, 0);
- for (intptr_t i = 0; i < len; i++) {
- if (original_str[i] <= Utf8::kMaxOneByteChar) {
- result[i] = original_str[i];
- } else {
- len = -1;
- break;
- }
- }
- if (len > 0) {
- result[len] = 0;
- return reinterpret_cast<const char*>(result);
- }
- }
const intptr_t len = Utf8::Length(*this);
Zone* zone = Thread::Current()->zone();
uint8_t* result = zone->Alloc<uint8_t>(len + 1);
@@ -20333,25 +20310,6 @@ const char* String::ToCString() const {
}
char* String::ToMallocCString() const {
- if (IsOneByteString()) {
- // Quick conversion if OneByteString contains only ASCII characters.
- intptr_t len = Length();
- uint8_t* result = reinterpret_cast<uint8_t*>(malloc(len + 1));
- NoSafepointScope no_safepoint;
- const uint8_t* original_str = OneByteString::CharAddr(*this, 0);
- for (intptr_t i = 0; i < len; i++) {
- if (original_str[i] <= Utf8::kMaxOneByteChar) {
- result[i] = original_str[i];
- } else {
- len = -1;
- break;
- }
- }
- if (len > 0) {
- result[len] = 0;
- return reinterpret_cast<char*>(result);
- }
- }
const intptr_t len = Utf8::Length(*this);
uint8_t* result = reinterpret_cast<uint8_t*>(malloc(len + 1));
ToUTF8(result, len);
@@ -20646,7 +20604,7 @@ RawOneByteString* OneByteString::New(const uint8_t* characters,
const String& result = String::Handle(OneByteString::New(len, space));
if (len > 0) {
NoSafepointScope no_safepoint;
- memmove(CharAddr(result, 0), characters, len);
+ memmove(DataStart(result), characters, len);
}
return OneByteString::raw(result);
}
@@ -20690,7 +20648,7 @@ RawOneByteString* OneByteString::New(const String& other_one_byte_string,
ASSERT(other_one_byte_string.IsOneByteString());
if (other_len > 0) {
NoSafepointScope no_safepoint;
- memmove(OneByteString::CharAddr(result, 0),
+ memmove(OneByteString::DataStart(result),
OneByteString::CharAddr(other_one_byte_string, other_start_index),
other_len);
}
@@ -20705,7 +20663,7 @@ RawOneByteString* OneByteString::New(const TypedData& other_typed_data,
ASSERT(other_typed_data.ElementSizeInBytes() == 1);
if (other_len > 0) {
NoSafepointScope no_safepoint;
- memmove(OneByteString::CharAddr(result, 0),
+ memmove(OneByteString::DataStart(result),
other_typed_data.DataAddr(other_start_index), other_len);
}
return OneByteString::raw(result);
@@ -20719,7 +20677,7 @@ RawOneByteString* OneByteString::New(const ExternalTypedData& other_typed_data,
ASSERT(other_typed_data.ElementSizeInBytes() == 1);
if (other_len > 0) {
NoSafepointScope no_safepoint;
- memmove(OneByteString::CharAddr(result, 0),
+ memmove(OneByteString::DataStart(result),
other_typed_data.DataAddr(other_start_index), other_len);
}
return OneByteString::raw(result);
@@ -20869,7 +20827,7 @@ RawTwoByteString* TwoByteString::New(const uint16_t* utf16_array,
const String& result = String::Handle(TwoByteString::New(array_len, space));
{
NoSafepointScope no_safepoint;
- memmove(CharAddr(result, 0), utf16_array, (array_len * 2));
+ memmove(DataStart(result), utf16_array, (array_len * 2));
}
return TwoByteString::raw(result);
}
@@ -20912,7 +20870,7 @@ RawTwoByteString* TwoByteString::New(const TypedData& other_typed_data,
const String& result = String::Handle(TwoByteString::New(other_len, space));
if (other_len > 0) {
NoSafepointScope no_safepoint;
- memmove(TwoByteString::CharAddr(result, 0),
+ memmove(TwoByteString::DataStart(result),
other_typed_data.DataAddr(other_start_index),
other_len * sizeof(uint16_t));
}
@@ -20926,7 +20884,7 @@ RawTwoByteString* TwoByteString::New(const ExternalTypedData& other_typed_data,
const String& result = String::Handle(TwoByteString::New(other_len, space));
if (other_len > 0) {
NoSafepointScope no_safepoint;
- memmove(TwoByteString::CharAddr(result, 0),
+ memmove(TwoByteString::DataStart(result),
other_typed_data.DataAddr(other_start_index),
other_len * sizeof(uint16_t));
}
« no previous file with comments | « runtime/vm/object.h ('k') | runtime/vm/raw_object_snapshot.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698