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

Side by Side Diff: src/api.cc

Issue 11688003: Revert r13275 and 13276 (Remove most uses of StringInputBuffer). (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 11 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 | « no previous file | src/codegen.cc » ('j') | 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 4025 matching lines...) Expand 10 before | Expand all | Expand 10 after
4036 // once without a capacity limit, which will get into the other branch of 4036 // once without a capacity limit, which will get into the other branch of
4037 // this 'if'. 4037 // this 'if'.
4038 int utf8_bytes = i::Utf8Length(str); 4038 int utf8_bytes = i::Utf8Length(str);
4039 if ((options & NO_NULL_TERMINATION) == 0) utf8_bytes++; 4039 if ((options & NO_NULL_TERMINATION) == 0) utf8_bytes++;
4040 if (utf8_bytes <= capacity) { 4040 if (utf8_bytes <= capacity) {
4041 return WriteUtf8(buffer, -1, nchars_ref, options); 4041 return WriteUtf8(buffer, -1, nchars_ref, options);
4042 } 4042 }
4043 } 4043 }
4044 4044
4045 // Slow case. 4045 // Slow case.
4046 i::StringCharacterStream stream(*str, isolate->write_iterator()); 4046 i::StringInputBuffer& write_input_buffer = *isolate->write_input_buffer();
4047 isolate->string_tracker()->RecordWrite(str); 4047 isolate->string_tracker()->RecordWrite(str);
4048 4048
4049 write_input_buffer.Reset(0, *str);
4049 int len = str->length(); 4050 int len = str->length();
4050 // Encode the first K - 3 bytes directly into the buffer since we 4051 // Encode the first K - 3 bytes directly into the buffer since we
4051 // know there's room for them. If no capacity is given we copy all 4052 // know there's room for them. If no capacity is given we copy all
4052 // of them here. 4053 // of them here.
4053 int fast_end = capacity - (unibrow::Utf8::kMaxEncodedSize - 1); 4054 int fast_end = capacity - (unibrow::Utf8::kMaxEncodedSize - 1);
4054 int i; 4055 int i;
4055 int pos = 0; 4056 int pos = 0;
4056 int nchars = 0; 4057 int nchars = 0;
4057 int previous = unibrow::Utf16::kNoPreviousCharacter; 4058 int previous = unibrow::Utf16::kNoPreviousCharacter;
4058 for (i = 0; i < len && (capacity == -1 || pos < fast_end); i++) { 4059 for (i = 0; i < len && (capacity == -1 || pos < fast_end); i++) {
4059 i::uc32 c = stream.GetNext(); 4060 i::uc32 c = write_input_buffer.GetNext();
4060 int written = unibrow::Utf8::Encode(buffer + pos, c, previous); 4061 int written = unibrow::Utf8::Encode(buffer + pos, c, previous);
4061 pos += written; 4062 pos += written;
4062 nchars++; 4063 nchars++;
4063 previous = c; 4064 previous = c;
4064 } 4065 }
4065 if (i < len) { 4066 if (i < len) {
4066 // For the last characters we need to check the length for each one 4067 // For the last characters we need to check the length for each one
4067 // because they may be longer than the remaining space in the 4068 // because they may be longer than the remaining space in the
4068 // buffer. 4069 // buffer.
4069 char intermediate[unibrow::Utf8::kMaxEncodedSize]; 4070 char intermediate[unibrow::Utf8::kMaxEncodedSize];
4070 for (; i < len && pos < capacity; i++) { 4071 for (; i < len && pos < capacity; i++) {
4071 i::uc32 c = stream.GetNext(); 4072 i::uc32 c = write_input_buffer.GetNext();
4072 if (unibrow::Utf16::IsTrailSurrogate(c) && 4073 if (unibrow::Utf16::IsTrailSurrogate(c) &&
4073 unibrow::Utf16::IsLeadSurrogate(previous)) { 4074 unibrow::Utf16::IsLeadSurrogate(previous)) {
4074 // We can't use the intermediate buffer here because the encoding 4075 // We can't use the intermediate buffer here because the encoding
4075 // of surrogate pairs is done under assumption that you can step 4076 // of surrogate pairs is done under assumption that you can step
4076 // back and fix the UTF8 stream. Luckily we only need space for one 4077 // back and fix the UTF8 stream. Luckily we only need space for one
4077 // more byte, so there is always space. 4078 // more byte, so there is always space.
4078 ASSERT(pos < capacity); 4079 ASSERT(pos < capacity);
4079 int written = unibrow::Utf8::Encode(buffer + pos, c, previous); 4080 int written = unibrow::Utf8::Encode(buffer + pos, c, previous);
4080 ASSERT(written == 1); 4081 ASSERT(written == 1);
4081 pos += written; 4082 pos += written;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
4117 LOG_API(isolate, "String::WriteAscii"); 4118 LOG_API(isolate, "String::WriteAscii");
4118 ENTER_V8(isolate); 4119 ENTER_V8(isolate);
4119 ASSERT(start >= 0 && length >= -1); 4120 ASSERT(start >= 0 && length >= -1);
4120 i::Handle<i::String> str = Utils::OpenHandle(this); 4121 i::Handle<i::String> str = Utils::OpenHandle(this);
4121 isolate->string_tracker()->RecordWrite(str); 4122 isolate->string_tracker()->RecordWrite(str);
4122 if (options & HINT_MANY_WRITES_EXPECTED) { 4123 if (options & HINT_MANY_WRITES_EXPECTED) {
4123 FlattenString(str); // Flatten the string for efficiency. 4124 FlattenString(str); // Flatten the string for efficiency.
4124 } 4125 }
4125 4126
4126 if (str->IsOneByteRepresentation()) { 4127 if (str->IsOneByteRepresentation()) {
4127 // WriteToFlat is faster than using the StringCharacterStream. 4128 // WriteToFlat is faster than using the StringInputBuffer.
4128 if (length == -1) length = str->length() + 1; 4129 if (length == -1) length = str->length() + 1;
4129 int len = i::Min(length, str->length() - start); 4130 int len = i::Min(length, str->length() - start);
4130 i::String::WriteToFlat(*str, buffer, start, start + len); 4131 i::String::WriteToFlat(*str, buffer, start, start + len);
4131 if (!(options & PRESERVE_ASCII_NULL)) { 4132 if (!(options & PRESERVE_ASCII_NULL)) {
4132 for (int i = 0; i < len; i++) { 4133 for (int i = 0; i < len; i++) {
4133 if (buffer[i] == '\0') buffer[i] = ' '; 4134 if (buffer[i] == '\0') buffer[i] = ' ';
4134 } 4135 }
4135 } 4136 }
4136 if (!(options & NO_NULL_TERMINATION) && length > len) { 4137 if (!(options & NO_NULL_TERMINATION) && length > len) {
4137 buffer[len] = '\0'; 4138 buffer[len] = '\0';
4138 } 4139 }
4139 return len; 4140 return len;
4140 } 4141 }
4141 4142
4143 i::StringInputBuffer& write_input_buffer = *isolate->write_input_buffer();
4142 int end = length; 4144 int end = length;
4143 if ((length == -1) || (length > str->length() - start)) { 4145 if ((length == -1) || (length > str->length() - start)) {
4144 end = str->length() - start; 4146 end = str->length() - start;
4145 } 4147 }
4146 if (end < 0) return 0; 4148 if (end < 0) return 0;
4147 i::StringCharacterStream write_stream(*str, isolate->write_iterator(), start); 4149 write_input_buffer.Reset(start, *str);
4148 int i; 4150 int i;
4149 for (i = 0; i < end; i++) { 4151 for (i = 0; i < end; i++) {
4150 char c = static_cast<char>(write_stream.GetNext()); 4152 char c = static_cast<char>(write_input_buffer.GetNext());
4151 if (c == '\0' && !(options & PRESERVE_ASCII_NULL)) c = ' '; 4153 if (c == '\0' && !(options & PRESERVE_ASCII_NULL)) c = ' ';
4152 buffer[i] = c; 4154 buffer[i] = c;
4153 } 4155 }
4154 if (!(options & NO_NULL_TERMINATION) && (length == -1 || i < length)) { 4156 if (!(options & NO_NULL_TERMINATION) && (length == -1 || i < length)) {
4155 buffer[i] = '\0'; 4157 buffer[i] = '\0';
4156 } 4158 }
4157 return i; 4159 return i;
4158 } 4160 }
4159 4161
4160 4162
4161 int String::Write(uint16_t* buffer, 4163 int String::Write(uint16_t* buffer,
4162 int start, 4164 int start,
4163 int length, 4165 int length,
4164 int options) const { 4166 int options) const {
4165 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); 4167 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
4166 if (IsDeadCheck(isolate, "v8::String::Write()")) return 0; 4168 if (IsDeadCheck(isolate, "v8::String::Write()")) return 0;
4167 LOG_API(isolate, "String::Write"); 4169 LOG_API(isolate, "String::Write");
4168 ENTER_V8(isolate); 4170 ENTER_V8(isolate);
4169 ASSERT(start >= 0 && length >= -1); 4171 ASSERT(start >= 0 && length >= -1);
4170 i::Handle<i::String> str = Utils::OpenHandle(this); 4172 i::Handle<i::String> str = Utils::OpenHandle(this);
4171 isolate->string_tracker()->RecordWrite(str); 4173 isolate->string_tracker()->RecordWrite(str);
4172 if (options & HINT_MANY_WRITES_EXPECTED) { 4174 if (options & HINT_MANY_WRITES_EXPECTED) {
4173 // Flatten the string for efficiency. This applies whether we are 4175 // Flatten the string for efficiency. This applies whether we are
4174 // using StringCharacterStream or Get(i) to access the characters. 4176 // using StringInputBuffer or Get(i) to access the characters.
4175 FlattenString(str); 4177 FlattenString(str);
4176 } 4178 }
4177 int end = start + length; 4179 int end = start + length;
4178 if ((length == -1) || (length > str->length() - start) ) 4180 if ((length == -1) || (length > str->length() - start) )
4179 end = str->length(); 4181 end = str->length();
4180 if (end < 0) return 0; 4182 if (end < 0) return 0;
4181 i::String::WriteToFlat(*str, buffer, start, end); 4183 i::String::WriteToFlat(*str, buffer, start, end);
4182 if (!(options & NO_NULL_TERMINATION) && 4184 if (!(options & NO_NULL_TERMINATION) &&
4183 (length == -1 || end - start < length)) { 4185 (length == -1 || end - start < length)) {
4184 buffer[end - start] = '\0'; 4186 buffer[end - start] = '\0';
(...skipping 2526 matching lines...) Expand 10 before | Expand all | Expand 10 after
6711 6713
6712 v->VisitPointers(blocks_.first(), first_block_limit_); 6714 v->VisitPointers(blocks_.first(), first_block_limit_);
6713 6715
6714 for (int i = 1; i < blocks_.length(); i++) { 6716 for (int i = 1; i < blocks_.length(); i++) {
6715 v->VisitPointers(blocks_[i], &blocks_[i][kHandleBlockSize]); 6717 v->VisitPointers(blocks_[i], &blocks_[i][kHandleBlockSize]);
6716 } 6718 }
6717 } 6719 }
6718 6720
6719 6721
6720 } } // namespace v8::internal 6722 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | src/codegen.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698