1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
6 #ifndef V8_REGEXP_JSREGEXP_INL_H_
7 #define V8_REGEXP_JSREGEXP_INL_H_
9 #include "src/allocation.h"
10 #include "src/handles.h"
11 #include "src/heap/heap.h"
12 #include "src/objects.h"
13 #include "src/regexp/jsregexp.h"
19 RegExpImpl::GlobalCache::~GlobalCache() {
20 // Deallocate the register array if we allocated it in the constructor
21 // (as opposed to using the existing jsregexp_static_offsets_vector).
22 if (register_array_size_ > Isolate::kJSRegexpStaticOffsetsVectorSize) {
23 DeleteArray(register_array_);
28 int32_t* RegExpImpl::GlobalCache::FetchNext() {
29 current_match_index_++;
30 if (current_match_index_ >= num_matches_) {
31 // Current batch of results exhausted.
32 // Fail if last batch was not even fully filled.
33 if (num_matches_ < max_matches_) {
34 num_matches_ = 0; // Signal failed match.
39 ®ister_array_[(current_match_index_ - 1) * registers_per_match_];
40 int last_end_index = last_match[1];
42 if (regexp_->TypeTag() == JSRegExp::ATOM) {
43 num_matches_ = RegExpImpl::AtomExecRaw(regexp_,
47 register_array_size_);
49 int last_start_index = last_match[0];
50 if (last_start_index == last_end_index) last_end_index++;
51 if (last_end_index > subject_->length()) {
52 num_matches_ = 0; // Signal failed match.
55 num_matches_ = RegExpImpl::IrregexpExecRaw(regexp_,
59 register_array_size_);
62 if (num_matches_ <= 0) return NULL;
63 current_match_index_ = 0;
64 return register_array_;
66 return ®ister_array_[current_match_index_ * registers_per_match_];
71 int32_t* RegExpImpl::GlobalCache::LastSuccessfulMatch() {
72 int index = current_match_index_ * registers_per_match_;
73 if (num_matches_ == 0) {
74 // After a failed match we shift back by one result.
75 index -= registers_per_match_;
77 return ®ister_array_[index];
81 } } // namespace v8::internal
83 #endif // V8_REGEXP_JSREGEXP_INL_H_