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

Side by Side Diff: src/api.cc

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