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

Side by Side Diff: src/objects.cc

Issue 11428106: Add StringBufferStream (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Right traversal optimization 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
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 7000 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 void SafeStringInputBuffer::Seek(unsigned pos) { 7016 void SafeStringInputBuffer::Seek(unsigned pos) {
7017 Reset(pos, input_); 7017 Reset(pos, input_);
7018 } 7018 }
7019 7019
7020 7020
7021 String* ConsStringIteratorOp::Operate(ConsString* consString,
7022 unsigned* outerOffset, int32_t* typeOut, unsigned* lengthOut) {
7023 ASSERT(*lengthOut == (unsigned)consString->length());
7024 // Push the root string.
7025 PushLeft(consString);
7026 root = consString;
7027 rootType = *typeOut;
7028 rootLength = *lengthOut;
7029 unsigned targetOffset = *outerOffset;
7030 unsigned offset = 0;
7031 while (true) {
7032 // Loop until the string is found which contains the target offset.
7033 String* string = consString->first();
7034 unsigned length = string->length();
7035 int32_t type;
Yang 2012/12/04 14:49:11 the instance type is a byte value, so uint8_t woul
Yang 2012/12/04 14:49:11 Generally I wouldn't mind sprinkling ASSERTs aroun
7036 if (targetOffset < offset + length) {
7037 // Target offset is in the left branch.
7038 // Mark the descent.
7039 ClearRightDescent();
7040 // Keep going if we're still in a ConString.
Yang 2012/12/04 14:49:11 typo "ConsString"
7041 type = string->map()->instance_type();
7042 if ((type & kStringRepresentationMask) == kConsStringTag) {
7043 consString = ConsString::cast(string);
7044 PushLeft(consString);
7045 continue;
7046 }
7047 } else {
7048 // Descend right.
7049 // Update progress through the string.
7050 offset += length;
7051 // Keep going if we're still in a ConString.
Yang 2012/12/04 14:49:11 typo "ConsString"
7052 string = consString->second();
7053 type = string->map()->instance_type();
7054 if ((type & kStringRepresentationMask) == kConsStringTag) {
7055 consString = ConsString::cast(string);
7056 PushRight(consString, type);
7057 continue;
7058 }
7059 // Mark the descent.
7060 SetRightDescent();
7061 // Need this to be updated for the current string.
7062 length = string->length();
7063 // Account for the possibility of an empty right leaf.
7064 while (length == 0) {
7065 bool blewStack;
7066 // Need to adjust maximum depth for NextLeaf to work.
7067 AdjustMaximumDepth();
7068 string = NextLeaf(&blewStack, &type);
7069 if (string == NULL) {
7070 // Luckily, this case is impossible.
7071 ASSERT(!blewStack);
7072 return NULL;
7073 }
7074 length = string->length();
7075 }
7076 }
7077 // Tell the stack we're done decending.
7078 AdjustMaximumDepth();
7079 ASSERT(length != 0);
7080 // Adjust return values and exit.
7081 unsigned innerOffset = targetOffset - offset;
7082 consumed += length - innerOffset;
7083 *outerOffset = innerOffset;
7084 *typeOut = type;
7085 *lengthOut = length;
7086 return string;
7087 }
7088 UNREACHABLE();
7089 return NULL;
7090 }
7091
7092
7093 String* ConsStringIteratorOp::NextLeaf(bool* blewStack, int32_t* typeOut) {
7094 while (true) {
7095 // Tree traversal complete.
7096 if (depth == 0) {
7097 *blewStack = false;
7098 return NULL;
7099 }
7100 // We've lost track of higher nodes.
7101 if (maximumDepth - depth == stackSize) {
7102 *blewStack = true;
7103 return NULL;
7104 }
7105 // Check if we're done with this level.
7106 bool haveNotReadRight = trace & MaskForDepth(depth - 1);
Yang 2012/12/04 14:49:11 Should this actually be hasAlreadyReadRight? (We g
7107 if (haveNotReadRight) {
7108 Pop();
7109 continue;
7110 }
7111 // Go right.
7112 ConsString* consString = frames[OffsetForDepth(depth - 1)];
7113 String* string = consString->second();
7114 int32_t type = string->map()->instance_type();
7115 if ((type & kStringRepresentationMask) != kConsStringTag) {
7116 // Don't need to mark the descent here.
7117 // Pop stack so next iteration is in correct place.
7118 Pop();
7119 *typeOut = type;
7120 return string;
7121 }
7122 // No need to mark the descent.
7123 consString = ConsString::cast(string);
7124 PushRight(consString, type);
7125 // Need to traverse all the way left.
7126 while (true) {
7127 // Continue left.
7128 // Update marker.
7129 ClearRightDescent();
7130 string = consString->first();
7131 type = string->map()->instance_type();
7132 if ((type & kStringRepresentationMask) != kConsStringTag) {
7133 AdjustMaximumDepth();
7134 *typeOut = type;
7135 return string;
7136 }
7137 consString = ConsString::cast(string);
7138 PushLeft(consString);
7139 }
7140 }
7141 UNREACHABLE();
7142 return NULL;
7143 }
7144
7145
7021 // This method determines the type of string involved and then copies 7146 // This method determines the type of string involved and then copies
7022 // a whole chunk of characters into a buffer. It can be used with strings 7147 // a whole chunk of characters into a buffer. It can be used with strings
7023 // that have been glued together to form a ConsString and which must cooperate 7148 // that have been glued together to form a ConsString and which must cooperate
7024 // to fill up a buffer. 7149 // to fill up a buffer.
7025 void String::ReadBlockIntoBuffer(String* input, 7150 void String::ReadBlockIntoBuffer(String* input,
7026 ReadBlockBuffer* rbb, 7151 ReadBlockBuffer* rbb,
7027 unsigned* offset_ptr, 7152 unsigned* offset_ptr,
7028 unsigned max_chars) { 7153 unsigned max_chars) {
7029 ASSERT(*offset_ptr <= (unsigned)input->length()); 7154 ASSERT(*offset_ptr <= (unsigned)input->length());
7030 if (max_chars == 0) return; 7155 if (max_chars == 0) return;
(...skipping 6848 matching lines...) Expand 10 before | Expand all | Expand 10 after
13879 set_year(Smi::FromInt(year), SKIP_WRITE_BARRIER); 14004 set_year(Smi::FromInt(year), SKIP_WRITE_BARRIER);
13880 set_month(Smi::FromInt(month), SKIP_WRITE_BARRIER); 14005 set_month(Smi::FromInt(month), SKIP_WRITE_BARRIER);
13881 set_day(Smi::FromInt(day), SKIP_WRITE_BARRIER); 14006 set_day(Smi::FromInt(day), SKIP_WRITE_BARRIER);
13882 set_weekday(Smi::FromInt(weekday), SKIP_WRITE_BARRIER); 14007 set_weekday(Smi::FromInt(weekday), SKIP_WRITE_BARRIER);
13883 set_hour(Smi::FromInt(hour), SKIP_WRITE_BARRIER); 14008 set_hour(Smi::FromInt(hour), SKIP_WRITE_BARRIER);
13884 set_min(Smi::FromInt(min), SKIP_WRITE_BARRIER); 14009 set_min(Smi::FromInt(min), SKIP_WRITE_BARRIER);
13885 set_sec(Smi::FromInt(sec), SKIP_WRITE_BARRIER); 14010 set_sec(Smi::FromInt(sec), SKIP_WRITE_BARRIER);
13886 } 14011 }
13887 14012
13888 } } // namespace v8::internal 14013 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698