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

Unified Diff: runtime/vm/object.cc

Issue 2952193002: VM: Speed up output of UTF8 for 1-byte strings.
Patch Set: Fix asserts Created 3 years, 5 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
Index: runtime/vm/object.cc
diff --git a/runtime/vm/object.cc b/runtime/vm/object.cc
index bb9334f92b4849e3ff4e40c8f7934707bfc5d433..d44ccb84d6ba9496209ba9034752084fabcacb51 100644
--- a/runtime/vm/object.cc
+++ b/runtime/vm/object.cc
@@ -21209,29 +21209,7 @@ 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);
- }
- }
+ NoSafepointScope no_safepoint;
const intptr_t len = Utf8::Length(*this);
Zone* zone = Thread::Current()->zone();
uint8_t* result = zone->Alloc<uint8_t>(len + 1);
« no previous file with comments | « runtime/vm/object.h ('k') | runtime/vm/unicode.cc » ('j') | runtime/vm/unicode.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698