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

Side by Side Diff: src/objects.cc

Issue 11438046: Cleanup StringCharacterStream and add initial test cases. (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 | « src/objects.h ('k') | src/objects-inl.h » ('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 6998 matching lines...) Expand 10 before | Expand all | Expand 10 after
7009 start_ = content.ToUC16Vector().start(); 7009 start_ = content.ToUC16Vector().start();
7010 } 7010 }
7011 } 7011 }
7012 7012
7013 7013
7014 void StringInputBuffer::Seek(unsigned pos) { 7014 void StringInputBuffer::Seek(unsigned pos) {
7015 Reset(pos, input_); 7015 Reset(pos, input_);
7016 } 7016 }
7017 7017
7018 7018
7019 String* ConsStringIteratorOp::Operate(ConsString* consString, 7019 String* ConsStringIteratorOp::Operate(ConsString* cons_string,
7020 unsigned* outerOffset, int32_t* typeOut, unsigned* lengthOut) { 7020 unsigned* offset_out, int32_t* type_out, unsigned* length_out) {
7021 ASSERT(*lengthOut == (unsigned)consString->length()); 7021 ASSERT(*length_out == (unsigned)cons_string->length());
7022 ASSERT(depth_ == 0);
7022 // Push the root string. 7023 // Push the root string.
7023 PushLeft(consString); 7024 PushLeft(cons_string);
7024 root_ = consString; 7025 root_ = cons_string;
7025 root_type_ = *typeOut; 7026 root_type_ = *type_out;
7026 root_length_ = *lengthOut; 7027 root_length_ = *length_out;
7027 unsigned targetOffset = *outerOffset; 7028 consumed_ = *offset_out;
7029 unsigned targetOffset = *offset_out;
7028 unsigned offset = 0; 7030 unsigned offset = 0;
7029 while (true) { 7031 while (true) {
7030 // Loop until the string is found which contains the target offset. 7032 // Loop until the string is found which contains the target offset.
7031 String* string = consString->first(); 7033 String* string = cons_string->first();
7032 unsigned length = string->length(); 7034 unsigned length = string->length();
7033 int32_t type; 7035 int32_t type;
7034 if (targetOffset < offset + length) { 7036 if (targetOffset < offset + length) {
7035 // Target offset is in the left branch. 7037 // Target offset is in the left branch.
7036 // Mark the descent.
7037 ClearRightDescent();
7038 // Keep going if we're still in a ConString. 7038 // Keep going if we're still in a ConString.
7039 type = string->map()->instance_type(); 7039 type = string->map()->instance_type();
7040 if ((type & kStringRepresentationMask) == kConsStringTag) { 7040 if ((type & kStringRepresentationMask) == kConsStringTag) {
7041 consString = ConsString::cast(string); 7041 cons_string = ConsString::cast(string);
7042 PushLeft(consString); 7042 PushLeft(cons_string);
7043 continue; 7043 continue;
7044 } 7044 }
7045 // Tell the stack we're done decending.
7046 AdjustMaximumDepth();
7045 } else { 7047 } else {
7046 // Descend right. 7048 // Descend right.
7047 // Update progress through the string. 7049 // Update progress through the string.
7048 offset += length; 7050 offset += length;
7049 // Keep going if we're still in a ConString. 7051 // Keep going if we're still in a ConString.
7050 string = consString->second(); 7052 string = cons_string->second();
7051 type = string->map()->instance_type(); 7053 type = string->map()->instance_type();
7052 if ((type & kStringRepresentationMask) == kConsStringTag) { 7054 if ((type & kStringRepresentationMask) == kConsStringTag) {
7053 consString = ConsString::cast(string); 7055 cons_string = ConsString::cast(string);
7054 PushRight(consString, type); 7056 PushRight(cons_string);
7057 // TODO(dcarney) Add back root optimization.
7055 continue; 7058 continue;
7056 } 7059 }
7057 // Mark the descent.
7058 SetRightDescent();
7059 // Need this to be updated for the current string. 7060 // Need this to be updated for the current string.
7060 length = string->length(); 7061 length = string->length();
7061 // Account for the possibility of an empty right leaf. 7062 // Account for the possibility of an empty right leaf.
7062 while (length == 0) { 7063 // This happens only if we have asked for an offset outside the string.
7063 bool blewStack; 7064 if (length == 0) {
7064 // Need to adjust maximum depth for NextLeaf to work. 7065 Reset();
7065 AdjustMaximumDepth(); 7066 return NULL;
7066 string = NextLeaf(&blewStack, &type);
7067 if (string == NULL) {
7068 // Luckily, this case is impossible.
7069 ASSERT(!blewStack);
7070 return NULL;
7071 }
7072 length = string->length();
7073 } 7067 }
7068 // Tell the stack we're done decending.
7069 AdjustMaximumDepth();
7070 // Pop stack so next iteration is in correct place.
7071 Pop();
7074 } 7072 }
7075 // Tell the stack we're done decending.
7076 AdjustMaximumDepth();
7077 ASSERT(length != 0); 7073 ASSERT(length != 0);
7078 // Adjust return values and exit. 7074 // Adjust return values and exit.
7079 unsigned innerOffset = targetOffset - offset; 7075 unsigned innerOffset = targetOffset - offset;
7080 consumed_ += length - innerOffset; 7076 consumed_ += length - innerOffset;
7081 *outerOffset = innerOffset; 7077 *offset_out = innerOffset;
7082 *typeOut = type; 7078 *type_out = type;
7083 *lengthOut = length; 7079 *length_out = length;
7084 return string; 7080 return string;
7085 } 7081 }
7086 UNREACHABLE(); 7082 UNREACHABLE();
7087 return NULL; 7083 return NULL;
7088 } 7084 }
7089 7085
7090 7086
7091 String* ConsStringIteratorOp::NextLeaf(bool* blewStack, int32_t* typeOut) { 7087 String* ConsStringIteratorOp::NextLeaf(
7088 bool* blew_stack, int32_t* type_out, unsigned* length_out) {
7092 while (true) { 7089 while (true) {
7093 // Tree traversal complete. 7090 // Tree traversal complete.
7094 if (depth_ == 0) { 7091 if (depth_ == 0) {
7095 *blewStack = false; 7092 *blew_stack = false;
7096 return NULL; 7093 return NULL;
7097 } 7094 }
7098 // We've lost track of higher nodes. 7095 // We've lost track of higher nodes.
7099 if (maximum_depth_ - depth_ == kStackSize) { 7096 if (maximum_depth_ - depth_ == kStackSize) {
7100 *blewStack = true; 7097 *blew_stack = true;
7101 return NULL; 7098 return NULL;
7102 } 7099 }
7103 // Check if we're done with this level.
7104 bool haveAlreadyReadRight = trace_ & MaskForDepth(depth_ - 1);
7105 if (haveAlreadyReadRight) {
7106 Pop();
7107 continue;
7108 }
7109 // Go right. 7100 // Go right.
7110 ConsString* consString = frames_[OffsetForDepth(depth_ - 1)]; 7101 ConsString* cons_string = frames_[OffsetForDepth(depth_ - 1)];
7111 String* string = consString->second(); 7102 String* string = cons_string->second();
7112 int32_t type = string->map()->instance_type(); 7103 int32_t type = string->map()->instance_type();
7113 if ((type & kStringRepresentationMask) != kConsStringTag) { 7104 if ((type & kStringRepresentationMask) != kConsStringTag) {
7114 // Don't need to mark the descent here.
7115 // Pop stack so next iteration is in correct place. 7105 // Pop stack so next iteration is in correct place.
7116 Pop(); 7106 Pop();
7117 *typeOut = type; 7107 unsigned length = (unsigned) string->length();
7108 // Could be a flattened ConsString.
7109 if (length == 0) continue;
7110 *length_out = length;
7111 *type_out = type;
7118 return string; 7112 return string;
7119 } 7113 }
7120 // No need to mark the descent. 7114 cons_string = ConsString::cast(string);
7121 consString = ConsString::cast(string); 7115 // TODO(dcarney) Add back root optimization.
7122 PushRight(consString, type); 7116 PushRight(cons_string);
7123 // Need to traverse all the way left. 7117 // Need to traverse all the way left.
7124 while (true) { 7118 while (true) {
7125 // Continue left. 7119 // Continue left.
7126 // Update marker. 7120 string = cons_string->first();
7127 ClearRightDescent();
7128 string = consString->first();
7129 type = string->map()->instance_type(); 7121 type = string->map()->instance_type();
7130 if ((type & kStringRepresentationMask) != kConsStringTag) { 7122 if ((type & kStringRepresentationMask) != kConsStringTag) {
7131 AdjustMaximumDepth(); 7123 AdjustMaximumDepth();
7132 *typeOut = type; 7124 *type_out = type;
7125 *length_out = string->length();
7133 return string; 7126 return string;
7134 } 7127 }
7135 consString = ConsString::cast(string); 7128 cons_string = ConsString::cast(string);
7136 PushLeft(consString); 7129 PushLeft(cons_string);
7137 } 7130 }
7138 } 7131 }
7139 UNREACHABLE(); 7132 UNREACHABLE();
7140 return NULL; 7133 return NULL;
7141 } 7134 }
7142 7135
7143 7136
7144 // This method determines the type of string involved and then copies 7137 // This method determines the type of string involved and then copies
7145 // a whole chunk of characters into a buffer. It can be used with strings 7138 // a whole chunk of characters into a buffer. It can be used with strings
7146 // that have been glued together to form a ConsString and which must cooperate 7139 // that have been glued together to form a ConsString and which must cooperate
(...skipping 6884 matching lines...) Expand 10 before | Expand all | Expand 10 after
14031 set_year(Smi::FromInt(year), SKIP_WRITE_BARRIER); 14024 set_year(Smi::FromInt(year), SKIP_WRITE_BARRIER);
14032 set_month(Smi::FromInt(month), SKIP_WRITE_BARRIER); 14025 set_month(Smi::FromInt(month), SKIP_WRITE_BARRIER);
14033 set_day(Smi::FromInt(day), SKIP_WRITE_BARRIER); 14026 set_day(Smi::FromInt(day), SKIP_WRITE_BARRIER);
14034 set_weekday(Smi::FromInt(weekday), SKIP_WRITE_BARRIER); 14027 set_weekday(Smi::FromInt(weekday), SKIP_WRITE_BARRIER);
14035 set_hour(Smi::FromInt(hour), SKIP_WRITE_BARRIER); 14028 set_hour(Smi::FromInt(hour), SKIP_WRITE_BARRIER);
14036 set_min(Smi::FromInt(min), SKIP_WRITE_BARRIER); 14029 set_min(Smi::FromInt(min), SKIP_WRITE_BARRIER);
14037 set_sec(Smi::FromInt(sec), SKIP_WRITE_BARRIER); 14030 set_sec(Smi::FromInt(sec), SKIP_WRITE_BARRIER);
14038 } 14031 }
14039 14032
14040 } } // namespace v8::internal 14033 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/objects.h ('k') | src/objects-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698