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

Unified Diff: runtime/vm/object.cc

Issue 12317076: Improve performance of String::ToCString for OneByteString and parsing of doubles. Leads to signifi… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 10 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
===================================================================
--- runtime/vm/object.cc (revision 18861)
+++ runtime/vm/object.cc (working copy)
@@ -10636,13 +10636,13 @@
ASSERT(RawObject::IsStringClassId(class_id));
NoGCScope no_gc;
if (class_id == kOneByteStringCid) {
- return *OneByteString::CharAddr(*this, index);
+ return *OneByteString::CharAddr(*this, index);
}
if (class_id == kTwoByteStringCid) {
- return *TwoByteString::CharAddr(*this, index);
+ return *TwoByteString::CharAddr(*this, index);
}
if (class_id == kExternalOneByteStringCid) {
- return *ExternalOneByteString::CharAddr(*this, index);
+ return *ExternalOneByteString::CharAddr(*this, index);
}
ASSERT(class_id == kExternalTwoByteStringCid);
return *ExternalTwoByteString::CharAddr(*this, index);
@@ -11115,7 +11115,29 @@
const char* String::ToCString() const {
- intptr_t len = Utf8::Length(*this);
+ if (IsOneByteString()) {
+ // Quick conversion if OneByteString contains one byte characters.
siva 2013/02/22 21:47:09 ... contains only ASCII characters.
srdjan 2013/02/22 22:27:37 Done.
+ intptr_t len = Length();
+ if (len == 0) {
+ return "";
+ }
+ Zone* zone = Isolate::Current()->current_zone();
+ uint8_t* result = zone->Alloc<uint8_t>(len + 1);
+ const uint8_t* original_str = OneByteString::CharAddr(*this, 0);
siva 2013/02/22 21:47:09 Since you are using the raw pointer here in a loop
srdjan 2013/02/22 22:27:37 Done.
+ 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 = Isolate::Current()->current_zone();
uint8_t* result = zone->Alloc<uint8_t>(len + 1);
ToUTF8(result, len);
« runtime/lib/double.cc ('K') | « runtime/lib/double.cc ('k') | runtime/vm/unicode.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698