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

Side by Side Diff: src/objects.cc

Issue 11428106: Add StringBufferStream (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Style update 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 6995 matching lines...) Expand 10 before | Expand all | Expand 10 after
7006 start_ = content.ToUC16Vector().start(); 7006 start_ = content.ToUC16Vector().start();
7007 } 7007 }
7008 } 7008 }
7009 7009
7010 7010
7011 void StringInputBuffer::Seek(unsigned pos) { 7011 void StringInputBuffer::Seek(unsigned pos) {
7012 Reset(pos, input_); 7012 Reset(pos, input_);
7013 } 7013 }
7014 7014
7015 7015
7016 String* ConsStringIteratorOp::Operate(ConsString* consString,
7017 unsigned* outerOffset, int32_t* typeOut, unsigned* lengthOut) {
7018 ASSERT(*lengthOut == (unsigned)consString->length());
7019 // Push the root string.
7020 PushLeft(consString);
7021 root_ = consString;
7022 root_type_ = *typeOut;
7023 root_length_ = *lengthOut;
7024 unsigned targetOffset = *outerOffset;
7025 unsigned offset = 0;
7026 while (true) {
7027 // Loop until the string is found which contains the target offset.
7028 String* string = consString->first();
7029 unsigned length = string->length();
7030 int32_t type;
7031 if (targetOffset < offset + length) {
7032 // Target offset is in the left branch.
7033 // Mark the descent.
7034 ClearRightDescent();
7035 // Keep going if we're still in a ConString.
7036 type = string->map()->instance_type();
7037 if ((type & kStringRepresentationMask) == kConsStringTag) {
7038 consString = ConsString::cast(string);
7039 PushLeft(consString);
7040 continue;
7041 }
7042 } else {
7043 // Descend right.
7044 // Update progress through the string.
7045 offset += length;
7046 // Keep going if we're still in a ConString.
7047 string = consString->second();
7048 type = string->map()->instance_type();
7049 if ((type & kStringRepresentationMask) == kConsStringTag) {
7050 consString = ConsString::cast(string);
7051 PushRight(consString, type);
7052 continue;
7053 }
7054 // Mark the descent.
7055 SetRightDescent();
7056 // Need this to be updated for the current string.
7057 length = string->length();
7058 // Account for the possibility of an empty right leaf.
7059 while (length == 0) {
7060 bool blewStack;
7061 // Need to adjust maximum depth for NextLeaf to work.
7062 AdjustMaximumDepth();
7063 string = NextLeaf(&blewStack, &type);
7064 if (string == NULL) {
7065 // Luckily, this case is impossible.
7066 ASSERT(!blewStack);
7067 return NULL;
7068 }
7069 length = string->length();
7070 }
7071 }
7072 // Tell the stack we're done decending.
7073 AdjustMaximumDepth();
7074 ASSERT(length != 0);
7075 // Adjust return values and exit.
7076 unsigned innerOffset = targetOffset - offset;
7077 consumed_ += length - innerOffset;
7078 *outerOffset = innerOffset;
7079 *typeOut = type;
7080 *lengthOut = length;
7081 return string;
7082 }
7083 UNREACHABLE();
7084 return NULL;
7085 }
7086
7087
7088 String* ConsStringIteratorOp::NextLeaf(bool* blewStack, int32_t* typeOut) {
7089 while (true) {
7090 // Tree traversal complete.
7091 if (depth_ == 0) {
7092 *blewStack = false;
7093 return NULL;
7094 }
7095 // We've lost track of higher nodes.
7096 if (maximum_depth_ - depth_ == kStackSize) {
7097 *blewStack = true;
7098 return NULL;
7099 }
7100 // Check if we're done with this level.
7101 bool haveNotReadRight = trace_ & MaskForDepth(depth_ - 1);
Yang 2012/12/06 10:18:47 I'm still somewhat confused about this. Shouldn't
7102 if (haveNotReadRight) {
7103 Pop();
7104 continue;
7105 }
7106 // Go right.
7107 ConsString* consString = frames_[OffsetForDepth(depth_ - 1)];
7108 String* string = consString->second();
7109 int32_t type = string->map()->instance_type();
7110 if ((type & kStringRepresentationMask) != kConsStringTag) {
7111 // Don't need to mark the descent here.
7112 // Pop stack so next iteration is in correct place.
7113 Pop();
7114 *typeOut = type;
7115 return string;
7116 }
7117 // No need to mark the descent.
7118 consString = ConsString::cast(string);
7119 PushRight(consString, type);
7120 // Need to traverse all the way left.
7121 while (true) {
7122 // Continue left.
7123 // Update marker.
7124 ClearRightDescent();
7125 string = consString->first();
7126 type = string->map()->instance_type();
7127 if ((type & kStringRepresentationMask) != kConsStringTag) {
7128 AdjustMaximumDepth();
7129 *typeOut = type;
7130 return string;
7131 }
7132 consString = ConsString::cast(string);
7133 PushLeft(consString);
7134 }
7135 }
7136 UNREACHABLE();
7137 return NULL;
7138 }
7139
7140
7016 // This method determines the type of string involved and then copies 7141 // This method determines the type of string involved and then copies
7017 // a whole chunk of characters into a buffer. It can be used with strings 7142 // a whole chunk of characters into a buffer. It can be used with strings
7018 // that have been glued together to form a ConsString and which must cooperate 7143 // that have been glued together to form a ConsString and which must cooperate
7019 // to fill up a buffer. 7144 // to fill up a buffer.
7020 void String::ReadBlockIntoBuffer(String* input, 7145 void String::ReadBlockIntoBuffer(String* input,
7021 ReadBlockBuffer* rbb, 7146 ReadBlockBuffer* rbb,
7022 unsigned* offset_ptr, 7147 unsigned* offset_ptr,
7023 unsigned max_chars) { 7148 unsigned max_chars) {
7024 ASSERT(*offset_ptr <= (unsigned)input->length()); 7149 ASSERT(*offset_ptr <= (unsigned)input->length());
7025 if (max_chars == 0) return; 7150 if (max_chars == 0) return;
(...skipping 6841 matching lines...) Expand 10 before | Expand all | Expand 10 after
13867 set_year(Smi::FromInt(year), SKIP_WRITE_BARRIER); 13992 set_year(Smi::FromInt(year), SKIP_WRITE_BARRIER);
13868 set_month(Smi::FromInt(month), SKIP_WRITE_BARRIER); 13993 set_month(Smi::FromInt(month), SKIP_WRITE_BARRIER);
13869 set_day(Smi::FromInt(day), SKIP_WRITE_BARRIER); 13994 set_day(Smi::FromInt(day), SKIP_WRITE_BARRIER);
13870 set_weekday(Smi::FromInt(weekday), SKIP_WRITE_BARRIER); 13995 set_weekday(Smi::FromInt(weekday), SKIP_WRITE_BARRIER);
13871 set_hour(Smi::FromInt(hour), SKIP_WRITE_BARRIER); 13996 set_hour(Smi::FromInt(hour), SKIP_WRITE_BARRIER);
13872 set_min(Smi::FromInt(min), SKIP_WRITE_BARRIER); 13997 set_min(Smi::FromInt(min), SKIP_WRITE_BARRIER);
13873 set_sec(Smi::FromInt(sec), SKIP_WRITE_BARRIER); 13998 set_sec(Smi::FromInt(sec), SKIP_WRITE_BARRIER);
13874 } 13999 }
13875 14000
13876 } } // namespace v8::internal 14001 } } // 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