LCOV - code coverage report
Current view: top level - src/regexp - jsregexp-inl.h (source / functions) Hit Total Coverage
Test: app.info Lines: 23 24 95.8 %
Date: 2017-10-20 Functions: 0 0 -

          Line data    Source code
       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.
       4             : 
       5             : 
       6             : #ifndef V8_REGEXP_JSREGEXP_INL_H_
       7             : #define V8_REGEXP_JSREGEXP_INL_H_
       8             : 
       9             : #include "src/allocation.h"
      10             : #include "src/objects.h"
      11             : #include "src/regexp/jsregexp.h"
      12             : 
      13             : namespace v8 {
      14             : namespace internal {
      15             : 
      16             : 
      17             : RegExpImpl::GlobalCache::~GlobalCache() {
      18             :   // Deallocate the register array if we allocated it in the constructor
      19             :   // (as opposed to using the existing jsregexp_static_offsets_vector).
      20      229574 :   if (register_array_size_ > Isolate::kJSRegexpStaticOffsetsVectorSize) {
      21        1209 :     DeleteArray(register_array_);
      22             :   }
      23             : }
      24             : 
      25             : 
      26             : int32_t* RegExpImpl::GlobalCache::FetchNext() {
      27    14943084 :   current_match_index_++;
      28    14943084 :   if (current_match_index_ >= num_matches_) {
      29             :     // Current batch of results exhausted.
      30             :     // Fail if last batch was not even fully filled.
      31      566932 :     if (num_matches_ < max_matches_) {
      32      101578 :       num_matches_ = 0;  // Signal failed match.
      33             :       return nullptr;
      34             :     }
      35             : 
      36             :     int32_t* last_match =
      37      465354 :         &register_array_[(current_match_index_ - 1) * registers_per_match_];
      38      465354 :     int last_end_index = last_match[1];
      39             : 
      40      465354 :     if (regexp_->TypeTag() == JSRegExp::ATOM) {
      41             :       num_matches_ = RegExpImpl::AtomExecRaw(regexp_,
      42             :                                              subject_,
      43             :                                              last_end_index,
      44             :                                              register_array_,
      45       90256 :                                              register_array_size_);
      46             :     } else {
      47      375098 :       int last_start_index = last_match[0];
      48      375098 :       if (last_start_index == last_end_index) {
      49             :         // Zero-length match. Advance by one code point.
      50         289 :         last_end_index = AdvanceZeroLength(last_end_index);
      51             :       }
      52      375098 :       if (last_end_index > subject_->length()) {
      53           0 :         num_matches_ = 0;  // Signal failed match.
      54             :         return nullptr;
      55             :       }
      56             :       num_matches_ = RegExpImpl::IrregexpExecRaw(regexp_,
      57             :                                                  subject_,
      58             :                                                  last_end_index,
      59             :                                                  register_array_,
      60      375098 :                                                  register_array_size_);
      61             :     }
      62             : 
      63      465354 :     if (num_matches_ <= 0) return nullptr;
      64      337578 :     current_match_index_ = 0;
      65      337578 :     return register_array_;
      66             :   } else {
      67    14376152 :     return &register_array_[current_match_index_ * registers_per_match_];
      68             :   }
      69             : }
      70             : 
      71             : 
      72             : int32_t* RegExpImpl::GlobalCache::LastSuccessfulMatch() {
      73      103426 :   int index = current_match_index_ * registers_per_match_;
      74      103426 :   if (num_matches_ == 0) {
      75             :     // After a failed match we shift back by one result.
      76      103426 :     index -= registers_per_match_;
      77             :   }
      78      103426 :   return &register_array_[index];
      79             : }
      80             : 
      81             : 
      82             : }  // namespace internal
      83             : }  // namespace v8
      84             : 
      85             : #endif  // V8_REGEXP_JSREGEXP_INL_H_

Generated by: LCOV version 1.10