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

Side by Side 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, 9 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/objects.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 6067 matching lines...) Expand 10 before | Expand all | Expand 10 after
6078 if (shape.representation_tag() == kSeqStringTag) { 6078 if (shape.representation_tag() == kSeqStringTag) {
6079 start = SeqTwoByteString::cast(string)->GetChars(); 6079 start = SeqTwoByteString::cast(string)->GetChars();
6080 } else { 6080 } else {
6081 start = ExternalTwoByteString::cast(string)->GetChars(); 6081 start = ExternalTwoByteString::cast(string)->GetChars();
6082 } 6082 }
6083 return FlatContent(Vector<const uc16>(start + offset, length)); 6083 return FlatContent(Vector<const uc16>(start + offset, length));
6084 } 6084 }
6085 } 6085 }
6086 6086
6087 6087
6088 int String::RecursivelySerializeToUtf8(char* buffer, int start, int end) {
6089 if (IsAsciiRepresentation()) {
6090 WriteToFlat(this, buffer, start, end);
6091 return end - start;
6092 }
6093 switch (StringShape(this).representation_tag()) {
6094 case kExternalStringTag: {
6095 const uc16* data =
6096 ExternalTwoByteString::cast(this)->GetChars();
6097 char* current = buffer;
6098 for (int i = start; i < end; i++) {
6099 uc16 character = data[i];
6100 current +=
6101 unibrow::Utf8::Encode(current, character);
6102 }
6103 return current - buffer;
6104 }
6105 case kSeqStringTag: {
6106 const uc16* data =
6107 SeqTwoByteString::cast(this)->GetChars();
6108 char* current = buffer;
6109 for (int i = start; i < end; i++) {
6110 uc16 character = data[i];
6111 current +=
6112 unibrow::Utf8::Encode(current, character);
6113 }
6114 return current - buffer;
6115 }
6116 case kConsStringTag: {
6117 ConsString* cons_string = ConsString::cast(this);
6118 String* first = cons_string->first();
6119 int boundary = first->length();
6120 if (start >= boundary) {
6121 // Only need RHS.
6122 return cons_string->second()->RecursivelySerializeToUtf8(
6123 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.
6124 } else if (end <= boundary) {
6125 // Only need LHS.
6126 return first->RecursivelySerializeToUtf8(
6127 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
6128 } else {
6129 int utf8_bytes = first->RecursivelySerializeToUtf8(
6130 buffer, start, boundary);
6131 return utf8_bytes +
6132 cons_string->second()->RecursivelySerializeToUtf8(
6133 buffer + utf8_bytes, 0, end - boundary);
6134 }
6135 }
6136 case kSlicedStringTag: {
6137 SlicedString* slice = SlicedString::cast(this);
6138 unsigned offset = slice->offset();
6139 return slice->parent()->RecursivelySerializeToUtf8(
6140 buffer, start + offset, end + offset);
6141 }
6142 }
6143 UNREACHABLE();
6144 return 0;
6145 }
6146
6147
6088 SmartArrayPointer<char> String::ToCString(AllowNullsFlag allow_nulls, 6148 SmartArrayPointer<char> String::ToCString(AllowNullsFlag allow_nulls,
6089 RobustnessFlag robust_flag, 6149 RobustnessFlag robust_flag,
6090 int offset, 6150 int offset,
6091 int length, 6151 int length,
6092 int* length_return) { 6152 int* length_return) {
6093 if (robust_flag == ROBUST_STRING_TRAVERSAL && !LooksValid()) { 6153 if (robust_flag == ROBUST_STRING_TRAVERSAL && !LooksValid()) {
6094 return SmartArrayPointer<char>(NULL); 6154 return SmartArrayPointer<char>(NULL);
6095 } 6155 }
6096 Heap* heap = GetHeap(); 6156 Heap* heap = GetHeap();
6097 6157
(...skipping 7071 matching lines...) Expand 10 before | Expand all | Expand 10 after
13169 if (break_point_objects()->IsUndefined()) return 0; 13229 if (break_point_objects()->IsUndefined()) return 0;
13170 // Single break point. 13230 // Single break point.
13171 if (!break_point_objects()->IsFixedArray()) return 1; 13231 if (!break_point_objects()->IsFixedArray()) return 1;
13172 // Multiple break points. 13232 // Multiple break points.
13173 return FixedArray::cast(break_point_objects())->length(); 13233 return FixedArray::cast(break_point_objects())->length();
13174 } 13234 }
13175 #endif // ENABLE_DEBUGGER_SUPPORT 13235 #endif // ENABLE_DEBUGGER_SUPPORT
13176 13236
13177 13237
13178 } } // namespace v8::internal 13238 } } // namespace v8::internal
OLDNEW
« 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