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

Side by Side Diff: src/api.cc

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