Commit bccef0c7 authored by yangguo@chromium.org's avatar yangguo@chromium.org

Reland r13275 and 13276 (Remove most uses of StringInputBuffer).

R=dcarney@chromium.org
BUG=

Review URL: https://chromiumcodereview.appspot.com/11727003
Patch from Dan Carney <dcarney@google.com>.

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@13291 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 45a012ec
...@@ -4044,10 +4044,9 @@ int String::WriteUtf8(char* buffer, ...@@ -4044,10 +4044,9 @@ int String::WriteUtf8(char* buffer,
} }
// Slow case. // Slow case.
i::StringInputBuffer& write_input_buffer = *isolate->write_input_buffer(); i::StringCharacterStream stream(*str, isolate->write_iterator());
isolate->string_tracker()->RecordWrite(str); isolate->string_tracker()->RecordWrite(str);
write_input_buffer.Reset(0, *str);
int len = str->length(); int len = str->length();
// Encode the first K - 3 bytes directly into the buffer since we // Encode the first K - 3 bytes directly into the buffer since we
// know there's room for them. If no capacity is given we copy all // know there's room for them. If no capacity is given we copy all
...@@ -4058,7 +4057,7 @@ int String::WriteUtf8(char* buffer, ...@@ -4058,7 +4057,7 @@ int String::WriteUtf8(char* buffer,
int nchars = 0; int nchars = 0;
int previous = unibrow::Utf16::kNoPreviousCharacter; int previous = unibrow::Utf16::kNoPreviousCharacter;
for (i = 0; i < len && (capacity == -1 || pos < fast_end); i++) { for (i = 0; i < len && (capacity == -1 || pos < fast_end); i++) {
i::uc32 c = write_input_buffer.GetNext(); i::uc32 c = stream.GetNext();
int written = unibrow::Utf8::Encode(buffer + pos, c, previous); int written = unibrow::Utf8::Encode(buffer + pos, c, previous);
pos += written; pos += written;
nchars++; nchars++;
...@@ -4070,7 +4069,7 @@ int String::WriteUtf8(char* buffer, ...@@ -4070,7 +4069,7 @@ int String::WriteUtf8(char* buffer,
// buffer. // buffer.
char intermediate[unibrow::Utf8::kMaxEncodedSize]; char intermediate[unibrow::Utf8::kMaxEncodedSize];
for (; i < len && pos < capacity; i++) { for (; i < len && pos < capacity; i++) {
i::uc32 c = write_input_buffer.GetNext(); i::uc32 c = stream.GetNext();
if (unibrow::Utf16::IsTrailSurrogate(c) && if (unibrow::Utf16::IsTrailSurrogate(c) &&
unibrow::Utf16::IsLeadSurrogate(previous)) { unibrow::Utf16::IsLeadSurrogate(previous)) {
// We can't use the intermediate buffer here because the encoding // We can't use the intermediate buffer here because the encoding
...@@ -4126,7 +4125,7 @@ int String::WriteAscii(char* buffer, ...@@ -4126,7 +4125,7 @@ int String::WriteAscii(char* buffer,
} }
if (str->IsOneByteRepresentation()) { if (str->IsOneByteRepresentation()) {
// WriteToFlat is faster than using the StringInputBuffer. // WriteToFlat is faster than using the StringCharacterStream.
if (length == -1) length = str->length() + 1; if (length == -1) length = str->length() + 1;
int len = i::Min(length, str->length() - start); int len = i::Min(length, str->length() - start);
i::String::WriteToFlat(*str, buffer, start, start + len); i::String::WriteToFlat(*str, buffer, start, start + len);
...@@ -4141,16 +4140,15 @@ int String::WriteAscii(char* buffer, ...@@ -4141,16 +4140,15 @@ int String::WriteAscii(char* buffer,
return len; return len;
} }
i::StringInputBuffer& write_input_buffer = *isolate->write_input_buffer();
int end = length; int end = length;
if ((length == -1) || (length > str->length() - start)) { if ((length == -1) || (length > str->length() - start)) {
end = str->length() - start; end = str->length() - start;
} }
if (end < 0) return 0; if (end < 0) return 0;
write_input_buffer.Reset(start, *str); i::StringCharacterStream write_stream(*str, isolate->write_iterator(), start);
int i; int i;
for (i = 0; i < end; i++) { for (i = 0; i < end; i++) {
char c = static_cast<char>(write_input_buffer.GetNext()); char c = static_cast<char>(write_stream.GetNext());
if (c == '\0' && !(options & PRESERVE_ASCII_NULL)) c = ' '; if (c == '\0' && !(options & PRESERVE_ASCII_NULL)) c = ' ';
buffer[i] = c; buffer[i] = c;
} }
...@@ -4174,7 +4172,7 @@ int String::Write(uint16_t* buffer, ...@@ -4174,7 +4172,7 @@ int String::Write(uint16_t* buffer,
isolate->string_tracker()->RecordWrite(str); isolate->string_tracker()->RecordWrite(str);
if (options & HINT_MANY_WRITES_EXPECTED) { if (options & HINT_MANY_WRITES_EXPECTED) {
// Flatten the string for efficiency. This applies whether we are // Flatten the string for efficiency. This applies whether we are
// using StringInputBuffer or Get(i) to access the characters. // using StringCharacterStream or Get(i) to access the characters.
FlattenString(str); FlattenString(str);
} }
int end = start + length; int end = start + length;
......
...@@ -131,14 +131,16 @@ void CodeGenerator::PrintCode(Handle<Code> code, CompilationInfo* info) { ...@@ -131,14 +131,16 @@ void CodeGenerator::PrintCode(Handle<Code> code, CompilationInfo* info) {
Handle<Script> script = info->script(); Handle<Script> script = info->script();
if (!script->IsUndefined() && !script->source()->IsUndefined()) { if (!script->IsUndefined() && !script->source()->IsUndefined()) {
PrintF("--- Raw source ---\n"); PrintF("--- Raw source ---\n");
StringInputBuffer stream(String::cast(script->source())); ConsStringIteratorOp op;
stream.Seek(function->start_position()); StringCharacterStream stream(String::cast(script->source()),
&op,
function->start_position());
// fun->end_position() points to the last character in the stream. We // fun->end_position() points to the last character in the stream. We
// need to compensate by adding one to calculate the length. // need to compensate by adding one to calculate the length.
int source_len = int source_len =
function->end_position() - function->start_position() + 1; function->end_position() - function->start_position() + 1;
for (int i = 0; i < source_len; i++) { for (int i = 0; i < source_len; i++) {
if (stream.has_more()) PrintF("%c", stream.GetNext()); if (stream.HasMore()) PrintF("%c", stream.GetNext());
} }
PrintF("\n\n"); PrintF("\n\n");
} }
......
...@@ -1634,7 +1634,7 @@ Isolate::Isolate() ...@@ -1634,7 +1634,7 @@ Isolate::Isolate()
free_list_(0), free_list_(0),
preallocated_storage_preallocated_(false), preallocated_storage_preallocated_(false),
inner_pointer_to_code_cache_(NULL), inner_pointer_to_code_cache_(NULL),
write_input_buffer_(NULL), write_iterator_(NULL),
global_handles_(NULL), global_handles_(NULL),
context_switcher_(NULL), context_switcher_(NULL),
thread_manager_(NULL), thread_manager_(NULL),
...@@ -1845,8 +1845,8 @@ Isolate::~Isolate() { ...@@ -1845,8 +1845,8 @@ Isolate::~Isolate() {
bootstrapper_ = NULL; bootstrapper_ = NULL;
delete inner_pointer_to_code_cache_; delete inner_pointer_to_code_cache_;
inner_pointer_to_code_cache_ = NULL; inner_pointer_to_code_cache_ = NULL;
delete write_input_buffer_; delete write_iterator_;
write_input_buffer_ = NULL; write_iterator_ = NULL;
delete context_switcher_; delete context_switcher_;
context_switcher_ = NULL; context_switcher_ = NULL;
...@@ -1964,7 +1964,7 @@ bool Isolate::Init(Deserializer* des) { ...@@ -1964,7 +1964,7 @@ bool Isolate::Init(Deserializer* des) {
descriptor_lookup_cache_ = new DescriptorLookupCache(); descriptor_lookup_cache_ = new DescriptorLookupCache();
unicode_cache_ = new UnicodeCache(); unicode_cache_ = new UnicodeCache();
inner_pointer_to_code_cache_ = new InnerPointerToCodeCache(this); inner_pointer_to_code_cache_ = new InnerPointerToCodeCache(this);
write_input_buffer_ = new StringInputBuffer(); write_iterator_ = new ConsStringIteratorOp();
global_handles_ = new GlobalHandles(this); global_handles_ = new GlobalHandles(this);
bootstrapper_ = new Bootstrapper(); bootstrapper_ = new Bootstrapper();
handle_scope_implementer_ = new HandleScopeImplementer(this); handle_scope_implementer_ = new HandleScopeImplementer(this);
......
...@@ -75,7 +75,7 @@ class PreallocatedMemoryThread; ...@@ -75,7 +75,7 @@ class PreallocatedMemoryThread;
class RegExpStack; class RegExpStack;
class SaveContext; class SaveContext;
class UnicodeCache; class UnicodeCache;
class StringInputBuffer; class ConsStringIteratorOp;
class StringTracker; class StringTracker;
class StubCache; class StubCache;
class ThreadManager; class ThreadManager;
...@@ -881,7 +881,7 @@ class Isolate { ...@@ -881,7 +881,7 @@ class Isolate {
return inner_pointer_to_code_cache_; return inner_pointer_to_code_cache_;
} }
StringInputBuffer* write_input_buffer() { return write_input_buffer_; } ConsStringIteratorOp* write_iterator() { return write_iterator_; }
GlobalHandles* global_handles() { return global_handles_; } GlobalHandles* global_handles() { return global_handles_; }
...@@ -903,16 +903,16 @@ class Isolate { ...@@ -903,16 +903,16 @@ class Isolate {
return &jsregexp_canonrange_; return &jsregexp_canonrange_;
} }
StringInputBuffer* objects_string_compare_buffer_a() { ConsStringIteratorOp* objects_string_compare_iterator_a() {
return &objects_string_compare_buffer_a_; return &objects_string_compare_iterator_a_;
} }
StringInputBuffer* objects_string_compare_buffer_b() { ConsStringIteratorOp* objects_string_compare_iterator_b() {
return &objects_string_compare_buffer_b_; return &objects_string_compare_iterator_b_;
} }
StaticResource<StringInputBuffer>* objects_string_input_buffer() { StaticResource<ConsStringIteratorOp>* objects_string_iterator() {
return &objects_string_input_buffer_; return &objects_string_iterator_;
} }
RuntimeState* runtime_state() { return &runtime_state_; } RuntimeState* runtime_state() { return &runtime_state_; }
...@@ -1225,7 +1225,7 @@ class Isolate { ...@@ -1225,7 +1225,7 @@ class Isolate {
PreallocatedStorage free_list_; PreallocatedStorage free_list_;
bool preallocated_storage_preallocated_; bool preallocated_storage_preallocated_;
InnerPointerToCodeCache* inner_pointer_to_code_cache_; InnerPointerToCodeCache* inner_pointer_to_code_cache_;
StringInputBuffer* write_input_buffer_; ConsStringIteratorOp* write_iterator_;
GlobalHandles* global_handles_; GlobalHandles* global_handles_;
ContextSwitcher* context_switcher_; ContextSwitcher* context_switcher_;
ThreadManager* thread_manager_; ThreadManager* thread_manager_;
...@@ -1236,9 +1236,9 @@ class Isolate { ...@@ -1236,9 +1236,9 @@ class Isolate {
StringTracker* string_tracker_; StringTracker* string_tracker_;
unibrow::Mapping<unibrow::Ecma262UnCanonicalize> jsregexp_uncanonicalize_; unibrow::Mapping<unibrow::Ecma262UnCanonicalize> jsregexp_uncanonicalize_;
unibrow::Mapping<unibrow::CanonicalizationRange> jsregexp_canonrange_; unibrow::Mapping<unibrow::CanonicalizationRange> jsregexp_canonrange_;
StringInputBuffer objects_string_compare_buffer_a_; ConsStringIteratorOp objects_string_compare_iterator_a_;
StringInputBuffer objects_string_compare_buffer_b_; ConsStringIteratorOp objects_string_compare_iterator_b_;
StaticResource<StringInputBuffer> objects_string_input_buffer_; StaticResource<ConsStringIteratorOp> objects_string_iterator_;
unibrow::Mapping<unibrow::Ecma262Canonicalize> unibrow::Mapping<unibrow::Ecma262Canonicalize>
regexp_macro_assembler_canonicalize_; regexp_macro_assembler_canonicalize_;
RegExpStack* regexp_stack_; RegExpStack* regexp_stack_;
......
...@@ -2845,21 +2845,31 @@ String* ConsStringIteratorOp::ContinueOperation(int32_t* type_out, ...@@ -2845,21 +2845,31 @@ String* ConsStringIteratorOp::ContinueOperation(int32_t* type_out,
uint16_t StringCharacterStream::GetNext() { uint16_t StringCharacterStream::GetNext() {
ASSERT((buffer8_ == NULL && end_ == NULL) || buffer8_ < end_); ASSERT(buffer8_ != NULL && end_ != NULL);
// Advance cursor if needed.
// TODO(dcarney): Ensure uses of the api call HasMore first and avoid this.
if (buffer8_ == end_) HasMore();
ASSERT(buffer8_ < end_);
return is_one_byte_ ? *buffer8_++ : *buffer16_++; return is_one_byte_ ? *buffer8_++ : *buffer16_++;
} }
StringCharacterStream::StringCharacterStream( StringCharacterStream::StringCharacterStream(String* string,
String* string, unsigned offset, ConsStringIteratorOp* op) ConsStringIteratorOp* op,
unsigned offset)
: is_one_byte_(false), : is_one_byte_(false),
buffer8_(NULL),
end_(NULL),
op_(op) { op_(op) {
op->Reset(); Reset(string, offset);
}
void StringCharacterStream::Reset(String* string, unsigned offset) {
op_->Reset();
buffer8_ = NULL;
end_ = NULL;
int32_t type = string->map()->instance_type(); int32_t type = string->map()->instance_type();
unsigned length = string->length(); unsigned length = string->length();
String::Visit(string, offset, *this, *op, type, length); String::Visit(string, offset, *this, *op_, type, length);
} }
......
This diff is collapsed.
...@@ -7200,9 +7200,7 @@ class String: public HeapObject { ...@@ -7200,9 +7200,7 @@ class String: public HeapObject {
// Returns a hash value used for the property table // Returns a hash value used for the property table
inline uint32_t Hash(); inline uint32_t Hash();
static bool ComputeArrayIndex(unibrow::CharacterStream* buffer, bool ComputeArrayIndex(uint32_t* index);
uint32_t* index,
int length);
// Externalization. // Externalization.
bool MakeExternal(v8::String::ExternalStringResource* resource); bool MakeExternal(v8::String::ExternalStringResource* resource);
...@@ -7898,11 +7896,11 @@ class ConsStringIteratorOp { ...@@ -7898,11 +7896,11 @@ class ConsStringIteratorOp {
class StringCharacterStream { class StringCharacterStream {
public: public:
inline StringCharacterStream(String* string, inline StringCharacterStream(String* string,
unsigned offset, ConsStringIteratorOp* op,
ConsStringIteratorOp* op); unsigned offset = 0);
inline uint16_t GetNext(); inline uint16_t GetNext();
inline bool HasMore(); inline bool HasMore();
inline void Reset(String* string, unsigned offset, ConsStringIteratorOp* op); inline void Reset(String* string, unsigned offset = 0);
inline void VisitOneByteString(const uint8_t* chars, unsigned length); inline void VisitOneByteString(const uint8_t* chars, unsigned length);
inline void VisitTwoByteString(const uint16_t* chars, unsigned length); inline void VisitTwoByteString(const uint16_t* chars, unsigned length);
......
...@@ -3489,17 +3489,17 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_StringLocaleCompare) { ...@@ -3489,17 +3489,17 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_StringLocaleCompare) {
str1->TryFlatten(); str1->TryFlatten();
str2->TryFlatten(); str2->TryFlatten();
StringInputBuffer& buf1 = ConsStringIteratorOp* op1 =
*isolate->runtime_state()->string_locale_compare_buf1(); isolate->runtime_state()->string_locale_compare_it1();
StringInputBuffer& buf2 = ConsStringIteratorOp* op2 =
*isolate->runtime_state()->string_locale_compare_buf2(); isolate->runtime_state()->string_locale_compare_it2();
// TODO(dcarney) Can do array compares here more efficiently.
buf1.Reset(str1); StringCharacterStream stream1(str1, op1);
buf2.Reset(str2); StringCharacterStream stream2(str2, op2);
for (int i = 0; i < end; i++) { for (int i = 0; i < end; i++) {
uint16_t char1 = buf1.GetNext(); uint16_t char1 = stream1.GetNext();
uint16_t char2 = buf2.GetNext(); uint16_t char2 = stream2.GetNext();
if (char1 != char2) return Smi::FromInt(char1 - char2); if (char1 != char2) return Smi::FromInt(char1 - char2);
} }
...@@ -5143,11 +5143,11 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_URIEscape) { ...@@ -5143,11 +5143,11 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_URIEscape) {
int escaped_length = 0; int escaped_length = 0;
int length = source->length(); int length = source->length();
{ {
Access<StringInputBuffer> buffer( Access<ConsStringIteratorOp> op(
isolate->runtime_state()->string_input_buffer()); isolate->runtime_state()->string_iterator());
buffer->Reset(source); StringCharacterStream stream(source, op.value());
while (buffer->has_more()) { while (stream.HasMore()) {
uint16_t character = buffer->GetNext(); uint16_t character = stream.GetNext();
if (character >= 256) { if (character >= 256) {
escaped_length += 6; escaped_length += 6;
} else if (IsNotEscaped(character)) { } else if (IsNotEscaped(character)) {
...@@ -5175,11 +5175,11 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_URIEscape) { ...@@ -5175,11 +5175,11 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_URIEscape) {
String* destination = String::cast(o); String* destination = String::cast(o);
int dest_position = 0; int dest_position = 0;
Access<StringInputBuffer> buffer( Access<ConsStringIteratorOp> op(
isolate->runtime_state()->string_input_buffer()); isolate->runtime_state()->string_iterator());
buffer->Rewind(); StringCharacterStream stream(source, op.value());
while (buffer->has_more()) { while (stream.HasMore()) {
uint16_t chr = buffer->GetNext(); uint16_t chr = stream.GetNext();
if (chr >= 256) { if (chr >= 256) {
destination->Set(dest_position, '%'); destination->Set(dest_position, '%');
destination->Set(dest_position+1, 'u'); destination->Set(dest_position+1, 'u');
...@@ -5717,15 +5717,15 @@ MUST_USE_RESULT static MaybeObject* ConvertCaseHelper( ...@@ -5717,15 +5717,15 @@ MUST_USE_RESULT static MaybeObject* ConvertCaseHelper(
// Convert all characters to upper case, assuming that they will fit // Convert all characters to upper case, assuming that they will fit
// in the buffer // in the buffer
Access<StringInputBuffer> buffer( Access<ConsStringIteratorOp> op(
isolate->runtime_state()->string_input_buffer()); isolate->runtime_state()->string_iterator());
buffer->Reset(s); StringCharacterStream stream(s, op.value());
unibrow::uchar chars[Converter::kMaxWidth]; unibrow::uchar chars[Converter::kMaxWidth];
// We can assume that the string is not empty // We can assume that the string is not empty
uc32 current = buffer->GetNext(); uc32 current = stream.GetNext();
for (int i = 0; i < length;) { for (int i = 0; i < length;) {
bool has_next = buffer->has_more(); bool has_next = stream.HasMore();
uc32 next = has_next ? buffer->GetNext() : 0; uc32 next = has_next ? stream.GetNext() : 0;
int char_length = mapping->get(current, next, chars); int char_length = mapping->get(current, next, chars);
if (char_length == 0) { if (char_length == 0) {
// The case conversion of this character is the character itself. // The case conversion of this character is the character itself.
...@@ -5755,8 +5755,8 @@ MUST_USE_RESULT static MaybeObject* ConvertCaseHelper( ...@@ -5755,8 +5755,8 @@ MUST_USE_RESULT static MaybeObject* ConvertCaseHelper(
if (next_length == 0) next_length = 1; if (next_length == 0) next_length = 1;
} }
int current_length = i + char_length + next_length; int current_length = i + char_length + next_length;
while (buffer->has_more()) { while (stream.HasMore()) {
current = buffer->GetNext(); current = stream.GetNext();
// NOTE: we use 0 as the next character here because, while // NOTE: we use 0 as the next character here because, while
// the next character may affect what a character converts to, // the next character may affect what a character converts to,
// it does not in any case affect the length of what it convert // it does not in any case affect the length of what it convert
...@@ -6960,23 +6960,21 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_SmiLexicographicCompare) { ...@@ -6960,23 +6960,21 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_SmiLexicographicCompare) {
} }
static Object* StringInputBufferCompare(RuntimeState* state, static Object* StringCharacterStreamCompare(RuntimeState* state,
String* x, String* x,
String* y) { String* y) {
StringInputBuffer& bufx = *state->string_input_buffer_compare_bufx(); StringCharacterStream stream_x(x, state->string_iterator_compare_x());
StringInputBuffer& bufy = *state->string_input_buffer_compare_bufy(); StringCharacterStream stream_y(y, state->string_iterator_compare_y());
bufx.Reset(x); while (stream_x.HasMore() && stream_y.HasMore()) {
bufy.Reset(y); int d = stream_x.GetNext() - stream_y.GetNext();
while (bufx.has_more() && bufy.has_more()) {
int d = bufx.GetNext() - bufy.GetNext();
if (d < 0) return Smi::FromInt(LESS); if (d < 0) return Smi::FromInt(LESS);
else if (d > 0) return Smi::FromInt(GREATER); else if (d > 0) return Smi::FromInt(GREATER);
} }
// x is (non-trivial) prefix of y: // x is (non-trivial) prefix of y:
if (bufy.has_more()) return Smi::FromInt(LESS); if (stream_y.HasMore()) return Smi::FromInt(LESS);
// y is prefix of x: // y is prefix of x:
return Smi::FromInt(bufx.has_more() ? GREATER : EQUAL); return Smi::FromInt(stream_x.HasMore() ? GREATER : EQUAL);
} }
...@@ -7020,7 +7018,7 @@ static Object* FlatStringCompare(String* x, String* y) { ...@@ -7020,7 +7018,7 @@ static Object* FlatStringCompare(String* x, String* y) {
result = (r < 0) ? Smi::FromInt(LESS) : Smi::FromInt(GREATER); result = (r < 0) ? Smi::FromInt(LESS) : Smi::FromInt(GREATER);
} }
ASSERT(result == ASSERT(result ==
StringInputBufferCompare(Isolate::Current()->runtime_state(), x, y)); StringCharacterStreamCompare(Isolate::Current()->runtime_state(), x, y));
return result; return result;
} }
...@@ -7056,7 +7054,7 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_StringCompare) { ...@@ -7056,7 +7054,7 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_StringCompare) {
} }
return (x->IsFlat() && y->IsFlat()) ? FlatStringCompare(x, y) return (x->IsFlat() && y->IsFlat()) ? FlatStringCompare(x, y)
: StringInputBufferCompare(isolate->runtime_state(), x, y); : StringCharacterStreamCompare(isolate->runtime_state(), x, y);
} }
...@@ -9885,9 +9883,10 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_GlobalPrint) { ...@@ -9885,9 +9883,10 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_GlobalPrint) {
ASSERT(args.length() == 1); ASSERT(args.length() == 1);
CONVERT_ARG_CHECKED(String, string, 0); CONVERT_ARG_CHECKED(String, string, 0);
StringInputBuffer buffer(string); ConsStringIteratorOp op;
while (buffer.has_more()) { StringCharacterStream stream(string, &op);
uint16_t character = buffer.GetNext(); while (stream.HasMore()) {
uint16_t character = stream.GetNext();
PrintF("%c", character); PrintF("%c", character);
} }
return string; return string;
......
...@@ -575,8 +575,8 @@ namespace internal { ...@@ -575,8 +575,8 @@ namespace internal {
class RuntimeState { class RuntimeState {
public: public:
StaticResource<StringInputBuffer>* string_input_buffer() { StaticResource<ConsStringIteratorOp>* string_iterator() {
return &string_input_buffer_; return &string_iterator_;
} }
unibrow::Mapping<unibrow::ToUppercase, 128>* to_upper_mapping() { unibrow::Mapping<unibrow::ToUppercase, 128>* to_upper_mapping() {
return &to_upper_mapping_; return &to_upper_mapping_;
...@@ -584,29 +584,29 @@ class RuntimeState { ...@@ -584,29 +584,29 @@ class RuntimeState {
unibrow::Mapping<unibrow::ToLowercase, 128>* to_lower_mapping() { unibrow::Mapping<unibrow::ToLowercase, 128>* to_lower_mapping() {
return &to_lower_mapping_; return &to_lower_mapping_;
} }
StringInputBuffer* string_input_buffer_compare_bufx() { ConsStringIteratorOp* string_iterator_compare_x() {
return &string_input_buffer_compare_bufx_; return &string_iterator_compare_x_;
} }
StringInputBuffer* string_input_buffer_compare_bufy() { ConsStringIteratorOp* string_iterator_compare_y() {
return &string_input_buffer_compare_bufy_; return &string_iterator_compare_y_;
} }
StringInputBuffer* string_locale_compare_buf1() { ConsStringIteratorOp* string_locale_compare_it1() {
return &string_locale_compare_buf1_; return &string_locale_compare_it1_;
} }
StringInputBuffer* string_locale_compare_buf2() { ConsStringIteratorOp* string_locale_compare_it2() {
return &string_locale_compare_buf2_; return &string_locale_compare_it2_;
} }
private: private:
RuntimeState() {} RuntimeState() {}
// Non-reentrant string buffer for efficient general use in the runtime. // Non-reentrant string buffer for efficient general use in the runtime.
StaticResource<StringInputBuffer> string_input_buffer_; StaticResource<ConsStringIteratorOp> string_iterator_;
unibrow::Mapping<unibrow::ToUppercase, 128> to_upper_mapping_; unibrow::Mapping<unibrow::ToUppercase, 128> to_upper_mapping_;
unibrow::Mapping<unibrow::ToLowercase, 128> to_lower_mapping_; unibrow::Mapping<unibrow::ToLowercase, 128> to_lower_mapping_;
StringInputBuffer string_input_buffer_compare_bufx_; ConsStringIteratorOp string_iterator_compare_x_;
StringInputBuffer string_input_buffer_compare_bufy_; ConsStringIteratorOp string_iterator_compare_y_;
StringInputBuffer string_locale_compare_buf1_; ConsStringIteratorOp string_locale_compare_it1_;
StringInputBuffer string_locale_compare_buf2_; ConsStringIteratorOp string_locale_compare_it2_;
friend class Isolate; friend class Isolate;
friend class Runtime; friend class Runtime;
......
...@@ -311,14 +311,14 @@ bool StringStream::Put(String* str) { ...@@ -311,14 +311,14 @@ bool StringStream::Put(String* str) {
bool StringStream::Put(String* str, int start, int end) { bool StringStream::Put(String* str, int start, int end) {
StringInputBuffer name_buffer(str); ConsStringIteratorOp op;
name_buffer.Seek(start); StringCharacterStream stream(str, &op, start);
for (int i = start; i < end && name_buffer.has_more(); i++) { for (int i = start; i < end && stream.HasMore(); i++) {
int c = name_buffer.GetNext(); uint16_t c = stream.GetNext();
if (c >= 127 || c < 32) { if (c >= 127 || c < 32) {
c = '?'; c = '?';
} }
if (!Put(c)) { if (!Put(static_cast<char>(c))) {
return false; // Output was truncated. return false; // Output was truncated.
} }
} }
......
...@@ -41,40 +41,40 @@ namespace internal { ...@@ -41,40 +41,40 @@ namespace internal {
namespace { namespace {
// C++-style iterator adaptor for StringInputBuffer // C++-style iterator adaptor for StringCharacterStream
// (unlike C++ iterators the end-marker has different type). // (unlike C++ iterators the end-marker has different type).
class StringInputBufferIterator { class StringCharacterStreamIterator {
public: public:
class EndMarker {}; class EndMarker {};
explicit StringInputBufferIterator(StringInputBuffer* buffer); explicit StringCharacterStreamIterator(StringCharacterStream* stream);
int operator*() const; uint16_t operator*() const;
void operator++(); void operator++();
bool operator==(EndMarker const&) const { return end_; } bool operator==(EndMarker const&) const { return end_; }
bool operator!=(EndMarker const& m) const { return !end_; } bool operator!=(EndMarker const& m) const { return !end_; }
private: private:
StringInputBuffer* const buffer_; StringCharacterStream* const stream_;
int current_; uint16_t current_;
bool end_; bool end_;
}; };
StringInputBufferIterator::StringInputBufferIterator( StringCharacterStreamIterator::StringCharacterStreamIterator(
StringInputBuffer* buffer) : buffer_(buffer) { StringCharacterStream* stream) : stream_(stream) {
++(*this); ++(*this);
} }
int StringInputBufferIterator::operator*() const { uint16_t StringCharacterStreamIterator::operator*() const {
return current_; return current_;
} }
void StringInputBufferIterator::operator++() { void StringCharacterStreamIterator::operator++() {
end_ = !buffer_->has_more(); end_ = !stream_->HasMore();
if (!end_) { if (!end_) {
current_ = buffer_->GetNext(); current_ = stream_->GetNext();
} }
} }
} // End anonymous namespace. } // End anonymous namespace.
...@@ -83,6 +83,7 @@ void StringInputBufferIterator::operator++() { ...@@ -83,6 +83,7 @@ void StringInputBufferIterator::operator++() {
double StringToDouble(UnicodeCache* unicode_cache, double StringToDouble(UnicodeCache* unicode_cache,
String* str, int flags, double empty_string_val) { String* str, int flags, double empty_string_val) {
StringShape shape(str); StringShape shape(str);
// TODO(dcarney): Use a Visitor here.
if (shape.IsSequentialAscii()) { if (shape.IsSequentialAscii()) {
const char* begin = SeqOneByteString::cast(str)->GetChars(); const char* begin = SeqOneByteString::cast(str)->GetChars();
const char* end = begin + str->length(); const char* end = begin + str->length();
...@@ -94,10 +95,11 @@ double StringToDouble(UnicodeCache* unicode_cache, ...@@ -94,10 +95,11 @@ double StringToDouble(UnicodeCache* unicode_cache,
return InternalStringToDouble(unicode_cache, begin, end, flags, return InternalStringToDouble(unicode_cache, begin, end, flags,
empty_string_val); empty_string_val);
} else { } else {
StringInputBuffer buffer(str); ConsStringIteratorOp op;
StringCharacterStream stream(str, &op);
return InternalStringToDouble(unicode_cache, return InternalStringToDouble(unicode_cache,
StringInputBufferIterator(&buffer), StringCharacterStreamIterator(&stream),
StringInputBufferIterator::EndMarker(), StringCharacterStreamIterator::EndMarker(),
flags, flags,
empty_string_val); empty_string_val);
} }
...@@ -108,6 +110,7 @@ double StringToInt(UnicodeCache* unicode_cache, ...@@ -108,6 +110,7 @@ double StringToInt(UnicodeCache* unicode_cache,
String* str, String* str,
int radix) { int radix) {
StringShape shape(str); StringShape shape(str);
// TODO(dcarney): Use a Visitor here.
if (shape.IsSequentialAscii()) { if (shape.IsSequentialAscii()) {
const char* begin = SeqOneByteString::cast(str)->GetChars(); const char* begin = SeqOneByteString::cast(str)->GetChars();
const char* end = begin + str->length(); const char* end = begin + str->length();
...@@ -117,10 +120,11 @@ double StringToInt(UnicodeCache* unicode_cache, ...@@ -117,10 +120,11 @@ double StringToInt(UnicodeCache* unicode_cache,
const uc16* end = begin + str->length(); const uc16* end = begin + str->length();
return InternalStringToInt(unicode_cache, begin, end, radix); return InternalStringToInt(unicode_cache, begin, end, radix);
} else { } else {
StringInputBuffer buffer(str); ConsStringIteratorOp op;
StringCharacterStream stream(str, &op);
return InternalStringToInt(unicode_cache, return InternalStringToInt(unicode_cache,
StringInputBufferIterator(&buffer), StringCharacterStreamIterator(&stream),
StringInputBufferIterator::EndMarker(), StringCharacterStreamIterator::EndMarker(),
radix); radix);
} }
} }
......
...@@ -56,6 +56,10 @@ test-profile-generator/RecordStackTraceAtStartProfiling: PASS || FAIL ...@@ -56,6 +56,10 @@ test-profile-generator/RecordStackTraceAtStartProfiling: PASS || FAIL
# We do not yet shrink weak maps after they have been emptied by the GC # We do not yet shrink weak maps after they have been emptied by the GC
test-weakmaps/Shrinking: FAIL test-weakmaps/Shrinking: FAIL
# Measurement of memory consumption seems bogus.
# Revision 13291 only slightly decreases the size of the isolate.
test-mark-compact/BootUpMemoryUse: PASS || FAIL
############################################################################## ##############################################################################
[ $arch == arm ] [ $arch == arm ]
......
...@@ -369,7 +369,7 @@ void AccumulateStatsWithOperator( ...@@ -369,7 +369,7 @@ void AccumulateStatsWithOperator(
void VerifyConsString(Handle<String> root, ConsStringGenerationData* data) { void VerifyConsString(Handle<String> root, ConsStringGenerationData* data) {
// Verify basic data. // Verify basic data.
CHECK(root->IsConsString()); CHECK(root->IsConsString());
CHECK((unsigned)root->length() == data->stats_.chars_); CHECK(static_cast<unsigned>(root->length()) == data->stats_.chars_);
// Recursive verify. // Recursive verify.
ConsStringStats stats; ConsStringStats stats;
AccumulateStats(ConsString::cast(*root), &stats); AccumulateStats(ConsString::cast(*root), &stats);
...@@ -521,8 +521,8 @@ static ConsStringIteratorOp cons_string_iterator_op_2; ...@@ -521,8 +521,8 @@ static ConsStringIteratorOp cons_string_iterator_op_2;
static void Traverse(Handle<String> s1, Handle<String> s2) { static void Traverse(Handle<String> s1, Handle<String> s2) {
int i = 0; int i = 0;
buffer.Reset(*s1); buffer.Reset(*s1);
StringCharacterStream character_stream_1(*s1, 0, &cons_string_iterator_op_1); StringCharacterStream character_stream_1(*s1, &cons_string_iterator_op_1);
StringCharacterStream character_stream_2(*s2, 0, &cons_string_iterator_op_2); StringCharacterStream character_stream_2(*s2, &cons_string_iterator_op_2);
StringInputBuffer buffer2(*s2); StringInputBuffer buffer2(*s2);
while (buffer.has_more()) { while (buffer.has_more()) {
CHECK(buffer2.has_more()); CHECK(buffer2.has_more());
...@@ -545,8 +545,8 @@ static void TraverseFirst(Handle<String> s1, Handle<String> s2, int chars) { ...@@ -545,8 +545,8 @@ static void TraverseFirst(Handle<String> s1, Handle<String> s2, int chars) {
int i = 0; int i = 0;
buffer.Reset(*s1); buffer.Reset(*s1);
StringInputBuffer buffer2(*s2); StringInputBuffer buffer2(*s2);
StringCharacterStream character_stream_1(*s1, 0, &cons_string_iterator_op_1); StringCharacterStream character_stream_1(*s1, &cons_string_iterator_op_1);
StringCharacterStream character_stream_2(*s2, 0, &cons_string_iterator_op_2); StringCharacterStream character_stream_2(*s2, &cons_string_iterator_op_2);
while (buffer.has_more() && i < chars) { while (buffer.has_more() && i < chars) {
CHECK(buffer2.has_more()); CHECK(buffer2.has_more());
CHECK(character_stream_1.HasMore()); CHECK(character_stream_1.HasMore());
...@@ -621,9 +621,9 @@ static void VerifyCharacterStream( ...@@ -621,9 +621,9 @@ static void VerifyCharacterStream(
// Want to test the offset == length case. // Want to test the offset == length case.
if (offset > length) offset = length; if (offset > length) offset = length;
StringCharacterStream flat_stream( StringCharacterStream flat_stream(
flat_string, (unsigned) offset, &cons_string_iterator_op_1); flat_string, &cons_string_iterator_op_1, static_cast<unsigned>(offset));
StringCharacterStream cons_stream( StringCharacterStream cons_stream(
cons_string, (unsigned) offset, &cons_string_iterator_op_2); cons_string, &cons_string_iterator_op_2, static_cast<unsigned>(offset));
for (int i = offset; i < length; i++) { for (int i = offset; i < length; i++) {
uint16_t c = flat_string->Get(i); uint16_t c = flat_string->Get(i);
CHECK(flat_stream.HasMore()); CHECK(flat_stream.HasMore());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment