Handle<Script> script = info->script();
if (!script->IsUndefined() && !script->source()->IsUndefined()) {
os << "--- Raw source ---\n";
- ConsStringIteratorOp op;
StringCharacterStream stream(String::cast(script->source()),
- &op,
function->start_position());
// fun->end_position() points to the last character in the stream. We
// need to compensate by adding one to calculate the length.
os << "--- FUNCTION SOURCE (" << shared->DebugName()->ToCString().get()
<< ") id{" << info()->optimization_id() << "," << id << "} ---\n";
{
- ConsStringIteratorOp op;
StringCharacterStream stream(String::cast(script->source()),
- &op,
shared->start_position());
// fun->end_position() points to the last character in the stream. We
// need to compensate by adding one to calculate the length.
unicode_cache_(NULL),
runtime_zone_(this),
inner_pointer_to_code_cache_(NULL),
- write_iterator_(NULL),
global_handles_(NULL),
eternal_handles_(NULL),
thread_manager_(NULL),
bootstrapper_ = NULL;
delete inner_pointer_to_code_cache_;
inner_pointer_to_code_cache_ = NULL;
- delete write_iterator_;
- write_iterator_ = NULL;
delete thread_manager_;
thread_manager_ = NULL;
descriptor_lookup_cache_ = new DescriptorLookupCache();
unicode_cache_ = new UnicodeCache();
inner_pointer_to_code_cache_ = new InnerPointerToCodeCache(this);
- write_iterator_ = new ConsStringIteratorOp();
global_handles_ = new GlobalHandles(this);
eternal_handles_ = new EternalHandles();
bootstrapper_ = new Bootstrapper(this);
class CodeStubDescriptor;
class CodeTracer;
class CompilationCache;
-class ConsStringIteratorOp;
class ContextSlotCache;
class Counters;
class CpuFeatures;
return inner_pointer_to_code_cache_;
}
- ConsStringIteratorOp* write_iterator() { return write_iterator_; }
-
GlobalHandles* global_handles() { return global_handles_; }
EternalHandles* eternal_handles() { return eternal_handles_; }
return &jsregexp_canonrange_;
}
- ConsStringIteratorOp* objects_string_compare_iterator_a() {
- return &objects_string_compare_iterator_a_;
- }
-
- ConsStringIteratorOp* objects_string_compare_iterator_b() {
- return &objects_string_compare_iterator_b_;
- }
-
- StaticResource<ConsStringIteratorOp>* objects_string_iterator() {
- return &objects_string_iterator_;
- }
-
RuntimeState* runtime_state() { return &runtime_state_; }
Builtins* builtins() { return &builtins_; }
UnicodeCache* unicode_cache_;
Zone runtime_zone_;
InnerPointerToCodeCache* inner_pointer_to_code_cache_;
- ConsStringIteratorOp* write_iterator_;
GlobalHandles* global_handles_;
EternalHandles* eternal_handles_;
ThreadManager* thread_manager_;
StringTracker* string_tracker_;
unibrow::Mapping<unibrow::Ecma262UnCanonicalize> jsregexp_uncanonicalize_;
unibrow::Mapping<unibrow::CanonicalizationRange> jsregexp_canonrange_;
- ConsStringIteratorOp objects_string_compare_iterator_a_;
- ConsStringIteratorOp objects_string_compare_iterator_b_;
- StaticResource<ConsStringIteratorOp> objects_string_iterator_;
unibrow::Mapping<unibrow::Ecma262Canonicalize>
regexp_macro_assembler_canonicalize_;
RegExpStack* regexp_stack_;
}
-int ConsStringIteratorOp::OffsetForDepth(int depth) {
- return depth & kDepthMask;
-}
+int ConsStringIterator::OffsetForDepth(int depth) { return depth & kDepthMask; }
-void ConsStringIteratorOp::PushLeft(ConsString* string) {
+void ConsStringIterator::PushLeft(ConsString* string) {
frames_[depth_++ & kDepthMask] = string;
}
-void ConsStringIteratorOp::PushRight(ConsString* string) {
+void ConsStringIterator::PushRight(ConsString* string) {
// Inplace update.
frames_[(depth_-1) & kDepthMask] = string;
}
-void ConsStringIteratorOp::AdjustMaximumDepth() {
+void ConsStringIterator::AdjustMaximumDepth() {
if (depth_ > maximum_depth_) maximum_depth_ = depth_;
}
-void ConsStringIteratorOp::Pop() {
+void ConsStringIterator::Pop() {
DCHECK(depth_ > 0);
DCHECK(depth_ <= maximum_depth_);
depth_--;
}
-StringCharacterStream::StringCharacterStream(String* string,
- ConsStringIteratorOp* op,
- int offset)
- : is_one_byte_(false),
- op_(op) {
+StringCharacterStream::StringCharacterStream(String* string, int offset)
+ : is_one_byte_(false) {
Reset(string, offset);
}
buffer8_ = NULL;
end_ = NULL;
ConsString* cons_string = String::VisitFlat(this, string, offset);
- op_->Reset(cons_string, offset);
+ iter_.Reset(cons_string, offset);
if (cons_string != NULL) {
- string = op_->Next(&offset);
+ string = iter_.Next(&offset);
if (string != NULL) String::VisitFlat(this, string, offset);
}
}
bool StringCharacterStream::HasMore() {
if (buffer8_ != end_) return true;
int offset;
- String* string = op_->Next(&offset);
+ String* string = iter_.Next(&offset);
DCHECK_EQ(offset, 0);
if (string == NULL) return false;
String::VisitFlat(this, string);
// The string was flat.
if (cons_string == NULL) return hasher.GetHashField();
// This is a ConsString, iterate across it.
- ConsStringIteratorOp op(cons_string);
+ ConsStringIterator iter(cons_string);
int offset;
- while (NULL != (string = op.Next(&offset))) {
+ while (NULL != (string = iter.Next(&offset))) {
String::VisitFlat(&hasher, string, offset);
}
return hasher.GetHashField();
return;
}
- ConsStringIteratorOp op;
- StringCharacterStream stream(this, &op);
+ StringCharacterStream stream(this);
bool truncated = false;
if (len > kMaxShortPrintLength) {
void String::PrintUC16(std::ostream& os, int start, int end) { // NOLINT
if (end < 0) end = length();
- ConsStringIteratorOp op;
- StringCharacterStream stream(this, &op, start);
+ StringCharacterStream stream(this, start);
for (int i = start; i < end && stream.HasMore(); i++) {
os << AsUC16(stream.GetNext());
}
if (robust_flag == ROBUST_STRING_TRAVERSAL && !LooksValid()) {
return SmartArrayPointer<char>(NULL);
}
- Heap* heap = GetHeap();
-
// Negative length means the to the end of the string.
if (length < 0) length = kMaxInt - offset;
// Compute the size of the UTF-8 string. Start at the specified offset.
- Access<ConsStringIteratorOp> op(
- heap->isolate()->objects_string_iterator());
- StringCharacterStream stream(this, op.value(), offset);
+ StringCharacterStream stream(this, offset);
int character_position = offset;
int utf8_bytes = 0;
int last = unibrow::Utf16::kNoPreviousCharacter;
if (robust_flag == ROBUST_STRING_TRAVERSAL && !LooksValid()) {
return SmartArrayPointer<uc16>();
}
- Heap* heap = GetHeap();
-
- Access<ConsStringIteratorOp> op(
- heap->isolate()->objects_string_iterator());
- StringCharacterStream stream(this, op.value());
+ StringCharacterStream stream(this);
uc16* result = NewArray<uc16>(length() + 1);
}
-void ConsStringIteratorOp::Initialize(ConsString* cons_string, int offset) {
+void ConsStringIterator::Initialize(ConsString* cons_string, int offset) {
DCHECK(cons_string != NULL);
root_ = cons_string;
consumed_ = offset;
}
-String* ConsStringIteratorOp::Continue(int* offset_out) {
+String* ConsStringIterator::Continue(int* offset_out) {
DCHECK(depth_ != 0);
DCHECK_EQ(0, *offset_out);
bool blew_stack = StackBlown();
}
-String* ConsStringIteratorOp::Search(int* offset_out) {
+String* ConsStringIterator::Search(int* offset_out) {
ConsString* cons_string = root_;
// Reset the stack, pushing the root string.
depth_ = 1;
}
-String* ConsStringIteratorOp::NextLeaf(bool* blew_stack) {
+String* ConsStringIterator::NextLeaf(bool* blew_stack) {
while (true) {
// Tree traversal complete.
if (depth_ == 0) {
class StringComparator {
class State {
public:
- explicit inline State(ConsStringIteratorOp* op)
- : op_(op), is_one_byte_(true), length_(0), buffer8_(NULL) {}
+ State() : is_one_byte_(true), length_(0), buffer8_(NULL) {}
- inline void Init(String* string) {
+ void Init(String* string) {
ConsString* cons_string = String::VisitFlat(this, string);
- op_->Reset(cons_string);
+ iter_.Reset(cons_string);
if (cons_string != NULL) {
int offset;
- string = op_->Next(&offset);
+ string = iter_.Next(&offset);
String::VisitFlat(this, string, offset);
}
}
}
// Advance state.
int offset;
- String* next = op_->Next(&offset);
+ String* next = iter_.Next(&offset);
DCHECK_EQ(0, offset);
DCHECK(next != NULL);
String::VisitFlat(this, next);
}
- ConsStringIteratorOp* const op_;
+ ConsStringIterator iter_;
bool is_one_byte_;
int length_;
union {
};
private:
- DISALLOW_IMPLICIT_CONSTRUCTORS(State);
+ DISALLOW_COPY_AND_ASSIGN(State);
};
public:
- inline StringComparator(ConsStringIteratorOp* op_1,
- ConsStringIteratorOp* op_2)
- : state_1_(op_1),
- state_2_(op_2) {
- }
+ inline StringComparator() {}
template<typename Chars1, typename Chars2>
static inline bool Equals(State* state_1, State* state_2, int to_check) {
private:
State state_1_;
State state_2_;
- DISALLOW_IMPLICIT_CONSTRUCTORS(StringComparator);
+
+ DISALLOW_COPY_AND_ASSIGN(StringComparator);
};
return CompareRawStringContents(str1, str2, len);
}
- Isolate* isolate = GetIsolate();
- StringComparator comparator(isolate->objects_string_compare_iterator_a(),
- isolate->objects_string_compare_iterator_b());
-
+ StringComparator comparator;
return comparator.Equals(this, other);
}
bool String::ComputeArrayIndex(uint32_t* index) {
int length = this->length();
if (length == 0 || length > kMaxArrayIndexSize) return false;
- ConsStringIteratorOp op;
- StringCharacterStream stream(this, &op);
+ StringCharacterStream stream(this);
return StringToArrayIndex(&stream, index);
}
};
-// A ConsStringOp that returns null.
-// Useful when the operation to apply on a ConsString
-// requires an expensive data structure.
-class ConsStringNullOp {
- public:
- inline ConsStringNullOp() {}
- static inline String* Operate(String*, unsigned*, int32_t*, unsigned*);
- private:
- DISALLOW_COPY_AND_ASSIGN(ConsStringNullOp);
-};
-
-
// This maintains an off-stack representation of the stack frames required
// to traverse a ConsString, allowing an entirely iterative and restartable
// traversal of the entire string
-class ConsStringIteratorOp {
+class ConsStringIterator {
public:
- inline ConsStringIteratorOp() {}
- inline explicit ConsStringIteratorOp(ConsString* cons_string,
- int offset = 0) {
+ inline ConsStringIterator() {}
+ inline explicit ConsStringIterator(ConsString* cons_string, int offset = 0) {
Reset(cons_string, offset);
}
inline void Reset(ConsString* cons_string, int offset = 0) {
int depth_;
int maximum_depth_;
int consumed_;
- DISALLOW_COPY_AND_ASSIGN(ConsStringIteratorOp);
+ DISALLOW_COPY_AND_ASSIGN(ConsStringIterator);
};
class StringCharacterStream {
public:
inline StringCharacterStream(String* string,
- ConsStringIteratorOp* op,
int offset = 0);
inline uint16_t GetNext();
inline bool HasMore();
inline void VisitTwoByteString(const uint16_t* chars, int length);
private:
+ ConsStringIterator iter_;
bool is_one_byte_;
union {
const uint8_t* buffer8_;
const uint16_t* buffer16_;
};
const uint8_t* end_;
- ConsStringIteratorOp* op_;
DISALLOW_COPY_AND_ASSIGN(StringCharacterStream);
};
// Convert all characters to upper case, assuming that they will fit
// in the buffer
- Access<ConsStringIteratorOp> op(isolate->runtime_state()->string_iterator());
- StringCharacterStream stream(string, op.value());
+ StringCharacterStream stream(string);
unibrow::uchar chars[Converter::kMaxWidth];
// We can assume that the string is not empty
uc32 current = stream.GetNext();
DCHECK(args.length() == 1);
CONVERT_ARG_CHECKED(String, string, 0);
- ConsStringIteratorOp op;
- StringCharacterStream stream(string, &op);
+ StringCharacterStream stream(string);
while (stream.HasMore()) {
uint16_t character = stream.GetNext();
PrintF("%c", character);
class RuntimeState {
public:
- StaticResource<ConsStringIteratorOp>* string_iterator() {
- return &string_iterator_;
- }
unibrow::Mapping<unibrow::ToUppercase, 128>* to_upper_mapping() {
return &to_upper_mapping_;
}
unibrow::Mapping<unibrow::ToLowercase, 128>* to_lower_mapping() {
return &to_lower_mapping_;
}
- ConsStringIteratorOp* string_iterator_compare_x() {
- return &string_iterator_compare_x_;
- }
- ConsStringIteratorOp* string_iterator_compare_y() {
- return &string_iterator_compare_y_;
- }
- ConsStringIteratorOp* string_locale_compare_it1() {
- return &string_locale_compare_it1_;
- }
- ConsStringIteratorOp* string_locale_compare_it2() {
- return &string_locale_compare_it2_;
- }
private:
RuntimeState() {}
- // Non-reentrant string buffer for efficient general use in the runtime.
- StaticResource<ConsStringIteratorOp> string_iterator_;
unibrow::Mapping<unibrow::ToUppercase, 128> to_upper_mapping_;
unibrow::Mapping<unibrow::ToLowercase, 128> to_lower_mapping_;
- ConsStringIteratorOp string_iterator_compare_x_;
- ConsStringIteratorOp string_iterator_compare_y_;
- ConsStringIteratorOp string_locale_compare_it1_;
- ConsStringIteratorOp string_locale_compare_it2_;
friend class Isolate;
friend class Runtime;
bool StringStream::Put(String* str, int start, int end) {
- ConsStringIteratorOp op;
- StringCharacterStream stream(str, &op, start);
+ StringCharacterStream stream(str, start);
for (int i = start; i < end && stream.HasMore(); i++) {
uint16_t c = stream.GetNext();
if (c >= 127 || c < 32) {
void AccumulateStatsWithOperator(
ConsString* cons_string, ConsStringStats* stats) {
- ConsStringIteratorOp op(cons_string);
+ ConsStringIterator iter(cons_string);
String* string;
int offset;
- while (NULL != (string = op.Next(&offset))) {
+ while (NULL != (string = iter.Next(&offset))) {
// Accumulate stats.
CHECK_EQ(0, offset);
stats->leaves_++;
}
-static ConsStringIteratorOp cons_string_iterator_op_1;
-static ConsStringIteratorOp cons_string_iterator_op_2;
-
static void Traverse(Handle<String> s1, Handle<String> s2) {
int i = 0;
- StringCharacterStream character_stream_1(*s1, &cons_string_iterator_op_1);
- StringCharacterStream character_stream_2(*s2, &cons_string_iterator_op_2);
+ StringCharacterStream character_stream_1(*s1);
+ StringCharacterStream character_stream_2(*s2);
while (character_stream_1.HasMore()) {
CHECK(character_stream_2.HasMore());
uint16_t c = character_stream_1.GetNext();
static void TraverseFirst(Handle<String> s1, Handle<String> s2, int chars) {
int i = 0;
- StringCharacterStream character_stream_1(*s1, &cons_string_iterator_op_1);
- StringCharacterStream character_stream_2(*s2, &cons_string_iterator_op_2);
+ StringCharacterStream character_stream_1(*s1);
+ StringCharacterStream character_stream_2(*s2);
while (character_stream_1.HasMore() && i < chars) {
CHECK(character_stream_2.HasMore());
uint16_t c = character_stream_1.GetNext();
if (offset < 0) offset = 0;
// Want to test the offset == length case.
if (offset > length) offset = length;
- StringCharacterStream flat_stream(
- flat_string, &cons_string_iterator_op_1, offset);
- StringCharacterStream cons_stream(
- cons_string, &cons_string_iterator_op_2, offset);
+ StringCharacterStream flat_stream(flat_string, offset);
+ StringCharacterStream cons_stream(cons_string, offset);
for (int i = offset; i < length; i++) {
uint16_t c = flat_string->Get(i);
CHECK(flat_stream.HasMore());