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

Unified Diff: src/objects.cc

Issue 9536018: Faster WriteUtf8 for medium size strings? Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 8 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
« no previous file with comments | « src/objects.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/objects.cc
===================================================================
--- src/objects.cc (revision 10873)
+++ src/objects.cc (working copy)
@@ -6085,6 +6085,66 @@
}
+int String::RecursivelySerializeToUtf8(char* buffer, int start, int end) {
+ if (IsAsciiRepresentation()) {
+ WriteToFlat(this, buffer, start, end);
+ return end - start;
+ }
+ switch (StringShape(this).representation_tag()) {
+ case kExternalStringTag: {
+ const uc16* data =
+ ExternalTwoByteString::cast(this)->GetChars();
+ char* current = buffer;
+ for (int i = start; i < end; i++) {
+ uc16 character = data[i];
+ current +=
+ unibrow::Utf8::Encode(current, character);
+ }
+ return current - buffer;
+ }
+ case kSeqStringTag: {
+ const uc16* data =
+ SeqTwoByteString::cast(this)->GetChars();
+ char* current = buffer;
+ for (int i = start; i < end; i++) {
+ uc16 character = data[i];
+ current +=
+ unibrow::Utf8::Encode(current, character);
+ }
+ return current - buffer;
+ }
+ case kConsStringTag: {
+ ConsString* cons_string = ConsString::cast(this);
+ String* first = cons_string->first();
+ int boundary = first->length();
+ if (start >= boundary) {
+ // Only need RHS.
+ return cons_string->second()->RecursivelySerializeToUtf8(
+ buffer, start - boundary, end - boundary);
piscisaureus 2012/03/01 14:21:18 `start - boundary` does not look correct to me. If
piscisaureus 2012/03/01 14:54:28 Never mind, this is correct.
+ } else if (end <= boundary) {
+ // Only need LHS.
+ return first->RecursivelySerializeToUtf8(
+ buffer, start - boundary, end - boundary);
piscisaureus 2012/03/01 14:21:18 sic
piscisaureus 2012/03/01 14:54:28 This should read: `return first->RecursivelySerial
+ } else {
+ int utf8_bytes = first->RecursivelySerializeToUtf8(
+ buffer, start, boundary);
+ return utf8_bytes +
+ cons_string->second()->RecursivelySerializeToUtf8(
+ buffer + utf8_bytes, 0, end - boundary);
+ }
+ }
+ case kSlicedStringTag: {
+ SlicedString* slice = SlicedString::cast(this);
+ unsigned offset = slice->offset();
+ return slice->parent()->RecursivelySerializeToUtf8(
+ buffer, start + offset, end + offset);
+ }
+ }
+ UNREACHABLE();
+ return 0;
+}
+
+
SmartArrayPointer<char> String::ToCString(AllowNullsFlag allow_nulls,
RobustnessFlag robust_flag,
int offset,
« no previous file with comments | « src/objects.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698