OLD | NEW |
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 6736 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6747 // *AsciiStringReadBlock routines. | 6747 // *AsciiStringReadBlock routines. |
6748 const unibrow::byte* ConsString::ConsStringReadBlock(ReadBlockBuffer* rbb, | 6748 const unibrow::byte* ConsString::ConsStringReadBlock(ReadBlockBuffer* rbb, |
6749 unsigned* offset_ptr, | 6749 unsigned* offset_ptr, |
6750 unsigned max_chars) { | 6750 unsigned max_chars) { |
6751 ConsString* current = this; | 6751 ConsString* current = this; |
6752 unsigned offset = *offset_ptr; | 6752 unsigned offset = *offset_ptr; |
6753 int offset_correction = 0; | 6753 int offset_correction = 0; |
6754 | 6754 |
6755 while (true) { | 6755 while (true) { |
6756 String* left = current->first(); | 6756 String* left = current->first(); |
6757 unsigned left_length = (unsigned)left->length(); | 6757 unsigned left_length = static_cast<unsigned>(left->length()); |
6758 if (left_length > offset && | 6758 if (left_length > offset && |
6759 (max_chars <= left_length - offset || | 6759 (max_chars <= left_length - offset || |
6760 (rbb->capacity <= left_length - offset && | 6760 (rbb->capacity <= left_length - offset && |
6761 (max_chars = left_length - offset, true)))) { // comma operator! | 6761 (max_chars = left_length - offset, true)))) { // comma operator! |
6762 // Left hand side only - iterate unless we have reached the bottom of | 6762 // Left hand side only - iterate unless we have reached the bottom of |
6763 // the cons tree. The assignment on the left of the comma operator is | 6763 // the cons tree. The assignment on the left of the comma operator is |
6764 // in order to make use of the fact that the -IntoBuffer routines can | 6764 // in order to make use of the fact that the -IntoBuffer routines can |
6765 // produce at most 'capacity' characters. This enables us to postpone | 6765 // produce at most 'capacity' characters. This enables us to postpone |
6766 // the point where we switch to the -IntoBuffer routines (below) in order | 6766 // the point where we switch to the -IntoBuffer routines (below) in order |
6767 // to maximize the chances of delegating a big chunk of work to the | 6767 // to maximize the chances of delegating a big chunk of work to the |
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7122 *blew_stack = true; | 7122 *blew_stack = true; |
7123 return NULL; | 7123 return NULL; |
7124 } | 7124 } |
7125 // Go right. | 7125 // Go right. |
7126 ConsString* cons_string = frames_[OffsetForDepth(depth_ - 1)]; | 7126 ConsString* cons_string = frames_[OffsetForDepth(depth_ - 1)]; |
7127 String* string = cons_string->second(); | 7127 String* string = cons_string->second(); |
7128 int32_t type = string->map()->instance_type(); | 7128 int32_t type = string->map()->instance_type(); |
7129 if ((type & kStringRepresentationMask) != kConsStringTag) { | 7129 if ((type & kStringRepresentationMask) != kConsStringTag) { |
7130 // Pop stack so next iteration is in correct place. | 7130 // Pop stack so next iteration is in correct place. |
7131 Pop(); | 7131 Pop(); |
7132 unsigned length = (unsigned) string->length(); | 7132 unsigned length = static_cast<unsigned>(string->length()); |
7133 // Could be a flattened ConsString. | 7133 // Could be a flattened ConsString. |
7134 if (length == 0) continue; | 7134 if (length == 0) continue; |
7135 *length_out = length; | 7135 *length_out = length; |
7136 *type_out = type; | 7136 *type_out = type; |
7137 consumed_ += length; | 7137 consumed_ += length; |
7138 return string; | 7138 return string; |
7139 } | 7139 } |
7140 cons_string = ConsString::cast(string); | 7140 cons_string = ConsString::cast(string); |
7141 // TODO(dcarney) Add back root optimization. | 7141 // TODO(dcarney) Add back root optimization. |
7142 PushRight(cons_string); | 7142 PushRight(cons_string); |
7143 // Need to traverse all the way left. | 7143 // Need to traverse all the way left. |
7144 while (true) { | 7144 while (true) { |
7145 // Continue left. | 7145 // Continue left. |
7146 string = cons_string->first(); | 7146 string = cons_string->first(); |
7147 type = string->map()->instance_type(); | 7147 type = string->map()->instance_type(); |
7148 if ((type & kStringRepresentationMask) != kConsStringTag) { | 7148 if ((type & kStringRepresentationMask) != kConsStringTag) { |
7149 AdjustMaximumDepth(); | 7149 AdjustMaximumDepth(); |
7150 unsigned length = (unsigned) string->length(); | 7150 unsigned length = static_cast<unsigned>(string->length()); |
7151 ASSERT(length != 0); | 7151 ASSERT(length != 0); |
7152 *length_out = length; | 7152 *length_out = length; |
7153 *type_out = type; | 7153 *type_out = type; |
7154 consumed_ += length; | 7154 consumed_ += length; |
7155 return string; | 7155 return string; |
7156 } | 7156 } |
7157 cons_string = ConsString::cast(string); | 7157 cons_string = ConsString::cast(string); |
7158 PushLeft(cons_string); | 7158 PushLeft(cons_string); |
7159 } | 7159 } |
7160 } | 7160 } |
7161 UNREACHABLE(); | 7161 UNREACHABLE(); |
7162 return NULL; | 7162 return NULL; |
7163 } | 7163 } |
7164 | 7164 |
7165 | 7165 |
7166 // This method determines the type of string involved and then copies | 7166 // This method determines the type of string involved and then copies |
7167 // a whole chunk of characters into a buffer. It can be used with strings | 7167 // a whole chunk of characters into a buffer. It can be used with strings |
7168 // that have been glued together to form a ConsString and which must cooperate | 7168 // that have been glued together to form a ConsString and which must cooperate |
7169 // to fill up a buffer. | 7169 // to fill up a buffer. |
7170 void String::ReadBlockIntoBuffer(String* input, | 7170 void String::ReadBlockIntoBuffer(String* input, |
7171 ReadBlockBuffer* rbb, | 7171 ReadBlockBuffer* rbb, |
7172 unsigned* offset_ptr, | 7172 unsigned* offset_ptr, |
7173 unsigned max_chars) { | 7173 unsigned max_chars) { |
7174 ASSERT(*offset_ptr <= (unsigned)input->length()); | 7174 ASSERT(*offset_ptr <= static_cast<unsigned>(input->length())); |
7175 if (max_chars == 0) return; | 7175 if (max_chars == 0) return; |
7176 | 7176 |
7177 switch (StringShape(input).representation_tag()) { | 7177 switch (StringShape(input).representation_tag()) { |
7178 case kSeqStringTag: | 7178 case kSeqStringTag: |
7179 if (input->IsOneByteRepresentation()) { | 7179 if (input->IsOneByteRepresentation()) { |
7180 SeqOneByteString::cast(input)->SeqOneByteStringReadBlockIntoBuffer(rbb, | 7180 SeqOneByteString::cast(input)->SeqOneByteStringReadBlockIntoBuffer(rbb, |
7181 offset_ptr, | 7181 offset_ptr, |
7182 max_chars); | 7182 max_chars); |
7183 return; | 7183 return; |
7184 } else { | 7184 } else { |
(...skipping 30 matching lines...) Expand all Loading... |
7215 UNREACHABLE(); | 7215 UNREACHABLE(); |
7216 return; | 7216 return; |
7217 } | 7217 } |
7218 | 7218 |
7219 | 7219 |
7220 const unibrow::byte* String::ReadBlock(String* input, | 7220 const unibrow::byte* String::ReadBlock(String* input, |
7221 unibrow::byte* util_buffer, | 7221 unibrow::byte* util_buffer, |
7222 unsigned capacity, | 7222 unsigned capacity, |
7223 unsigned* remaining, | 7223 unsigned* remaining, |
7224 unsigned* offset_ptr) { | 7224 unsigned* offset_ptr) { |
7225 ASSERT(*offset_ptr <= (unsigned)input->length()); | 7225 ASSERT(*offset_ptr <= static_cast<unsigned>(input->length())); |
7226 unsigned chars = input->length() - *offset_ptr; | 7226 unsigned chars = input->length() - *offset_ptr; |
7227 ReadBlockBuffer rbb(util_buffer, 0, capacity, 0); | 7227 ReadBlockBuffer rbb(util_buffer, 0, capacity, 0); |
7228 const unibrow::byte* answer = ReadBlock(input, &rbb, offset_ptr, chars); | 7228 const unibrow::byte* answer = ReadBlock(input, &rbb, offset_ptr, chars); |
7229 ASSERT(rbb.remaining <= static_cast<unsigned>(input->length())); | 7229 ASSERT(rbb.remaining <= static_cast<unsigned>(input->length())); |
7230 *remaining = rbb.remaining; | 7230 *remaining = rbb.remaining; |
7231 return answer; | 7231 return answer; |
7232 } | 7232 } |
7233 | 7233 |
7234 | 7234 |
7235 const unibrow::byte* String::ReadBlock(String** raw_input, | 7235 const unibrow::byte* String::ReadBlock(String** raw_input, |
7236 unibrow::byte* util_buffer, | 7236 unibrow::byte* util_buffer, |
7237 unsigned capacity, | 7237 unsigned capacity, |
7238 unsigned* remaining, | 7238 unsigned* remaining, |
7239 unsigned* offset_ptr) { | 7239 unsigned* offset_ptr) { |
7240 Handle<String> input(raw_input); | 7240 Handle<String> input(raw_input); |
7241 ASSERT(*offset_ptr <= (unsigned)input->length()); | 7241 ASSERT(*offset_ptr <= static_cast<unsigned>(input->length())); |
7242 unsigned chars = input->length() - *offset_ptr; | 7242 unsigned chars = input->length() - *offset_ptr; |
7243 if (chars > capacity) chars = capacity; | 7243 if (chars > capacity) chars = capacity; |
7244 ReadBlockBuffer rbb(util_buffer, 0, capacity, 0); | 7244 ReadBlockBuffer rbb(util_buffer, 0, capacity, 0); |
7245 ReadBlockIntoBuffer(*input, &rbb, offset_ptr, chars); | 7245 ReadBlockIntoBuffer(*input, &rbb, offset_ptr, chars); |
7246 ASSERT(rbb.remaining <= static_cast<unsigned>(input->length())); | 7246 ASSERT(rbb.remaining <= static_cast<unsigned>(input->length())); |
7247 *remaining = rbb.remaining; | 7247 *remaining = rbb.remaining; |
7248 return rbb.util_buffer; | 7248 return rbb.util_buffer; |
7249 } | 7249 } |
7250 | 7250 |
7251 | 7251 |
7252 // This will iterate unless the block of string data spans two 'halves' of | 7252 // This will iterate unless the block of string data spans two 'halves' of |
7253 // a ConsString, in which case it will recurse. Since the block of string | 7253 // a ConsString, in which case it will recurse. Since the block of string |
7254 // data to be read has a maximum size this limits the maximum recursion | 7254 // data to be read has a maximum size this limits the maximum recursion |
7255 // depth to something sane. Since C++ does not have tail call recursion | 7255 // depth to something sane. Since C++ does not have tail call recursion |
7256 // elimination, the iteration must be explicit. | 7256 // elimination, the iteration must be explicit. |
7257 void ConsString::ConsStringReadBlockIntoBuffer(ReadBlockBuffer* rbb, | 7257 void ConsString::ConsStringReadBlockIntoBuffer(ReadBlockBuffer* rbb, |
7258 unsigned* offset_ptr, | 7258 unsigned* offset_ptr, |
7259 unsigned max_chars) { | 7259 unsigned max_chars) { |
7260 ConsString* current = this; | 7260 ConsString* current = this; |
7261 unsigned offset = *offset_ptr; | 7261 unsigned offset = *offset_ptr; |
7262 int offset_correction = 0; | 7262 int offset_correction = 0; |
7263 | 7263 |
7264 while (true) { | 7264 while (true) { |
7265 String* left = current->first(); | 7265 String* left = current->first(); |
7266 unsigned left_length = (unsigned)left->length(); | 7266 unsigned left_length = static_cast<unsigned>(left->length()); |
7267 if (left_length > offset && | 7267 if (left_length > offset && |
7268 max_chars <= left_length - offset) { | 7268 max_chars <= left_length - offset) { |
7269 // Left hand side only - iterate unless we have reached the bottom of | 7269 // Left hand side only - iterate unless we have reached the bottom of |
7270 // the cons tree. | 7270 // the cons tree. |
7271 if (StringShape(left).IsCons()) { | 7271 if (StringShape(left).IsCons()) { |
7272 current = ConsString::cast(left); | 7272 current = ConsString::cast(left); |
7273 continue; | 7273 continue; |
7274 } else { | 7274 } else { |
7275 String::ReadBlockIntoBuffer(left, rbb, &offset, max_chars); | 7275 String::ReadBlockIntoBuffer(left, rbb, &offset, max_chars); |
7276 *offset_ptr = offset + offset_correction; | 7276 *offset_ptr = offset + offset_correction; |
(...skipping 6865 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
14142 set_year(Smi::FromInt(year), SKIP_WRITE_BARRIER); | 14142 set_year(Smi::FromInt(year), SKIP_WRITE_BARRIER); |
14143 set_month(Smi::FromInt(month), SKIP_WRITE_BARRIER); | 14143 set_month(Smi::FromInt(month), SKIP_WRITE_BARRIER); |
14144 set_day(Smi::FromInt(day), SKIP_WRITE_BARRIER); | 14144 set_day(Smi::FromInt(day), SKIP_WRITE_BARRIER); |
14145 set_weekday(Smi::FromInt(weekday), SKIP_WRITE_BARRIER); | 14145 set_weekday(Smi::FromInt(weekday), SKIP_WRITE_BARRIER); |
14146 set_hour(Smi::FromInt(hour), SKIP_WRITE_BARRIER); | 14146 set_hour(Smi::FromInt(hour), SKIP_WRITE_BARRIER); |
14147 set_min(Smi::FromInt(min), SKIP_WRITE_BARRIER); | 14147 set_min(Smi::FromInt(min), SKIP_WRITE_BARRIER); |
14148 set_sec(Smi::FromInt(sec), SKIP_WRITE_BARRIER); | 14148 set_sec(Smi::FromInt(sec), SKIP_WRITE_BARRIER); |
14149 } | 14149 } |
14150 | 14150 |
14151 } } // namespace v8::internal | 14151 } } // namespace v8::internal |
OLD | NEW |