diff options
Diffstat (limited to 'Source/JavaScriptCore/runtime/RegExp.cpp')
-rw-r--r-- | Source/JavaScriptCore/runtime/RegExp.cpp | 72 |
1 files changed, 28 insertions, 44 deletions
diff --git a/Source/JavaScriptCore/runtime/RegExp.cpp b/Source/JavaScriptCore/runtime/RegExp.cpp index 0d513d2cc..69bca5df0 100644 --- a/Source/JavaScriptCore/runtime/RegExp.cpp +++ b/Source/JavaScriptCore/runtime/RegExp.cpp @@ -330,68 +330,52 @@ void RegExp::compileIfNecessary(JSGlobalData& globalData, Yarr::YarrCharSize cha compile(&globalData, charSize); } - -int RegExp::match(JSGlobalData& globalData, const UString& s, int startOffset, Vector<int, 32>* ovector) +int RegExp::match(JSGlobalData& globalData, const UString& s, unsigned startOffset, Vector<int, 32>* ovector) { - if (startOffset < 0) - startOffset = 0; - #if ENABLE(REGEXP_TRACING) m_rtMatchCallCount++; #endif - if (static_cast<unsigned>(startOffset) > s.length() || s.isNull()) - return -1; - - if (m_state != ParseError) { - compileIfNecessary(globalData, s.is8Bit() ? Yarr::Char8 : Yarr::Char16); - - int offsetVectorSize = (m_numSubpatterns + 1) * 2; - int* offsetVector; - Vector<int, 32> nonReturnedOvector; - if (ovector) { - ovector->resize(offsetVectorSize); - offsetVector = ovector->data(); - } else { - nonReturnedOvector.resize(offsetVectorSize); - offsetVector = nonReturnedOvector.data(); - } + ASSERT(m_state != ParseError); + compileIfNecessary(globalData, s.is8Bit() ? Yarr::Char8 : Yarr::Char16); - ASSERT(offsetVector); - // Initialize offsetVector with the return value (index 0) and the - // first subpattern start indicies (even index values) set to -1. - // No need to init the subpattern end indicies. - for (unsigned j = 0, i = 0; i < m_numSubpatterns + 1; j += 2, i++) - offsetVector[j] = -1; + int offsetVectorSize = (m_numSubpatterns + 1) * 2; + int* offsetVector; + Vector<int, 32> nonReturnedOvector; + if (ovector) { + ovector->resize(offsetVectorSize); + offsetVector = ovector->data(); + } else { + nonReturnedOvector.resize(offsetVectorSize); + offsetVector = nonReturnedOvector.data(); + } + ASSERT(offsetVector); - int result; + int result; #if ENABLE(YARR_JIT) - if (m_state == JITCode) { - if (s.is8Bit()) - result = Yarr::execute(m_representation->m_regExpJITCode, s.characters8(), startOffset, s.length(), offsetVector); - else - result = Yarr::execute(m_representation->m_regExpJITCode, s.characters16(), startOffset, s.length(), offsetVector); + if (m_state == JITCode) { + if (s.is8Bit()) + result = Yarr::execute(m_representation->m_regExpJITCode, s.characters8(), startOffset, s.length(), offsetVector); + else + result = Yarr::execute(m_representation->m_regExpJITCode, s.characters16(), startOffset, s.length(), offsetVector); #if ENABLE(YARR_JIT_DEBUG) - matchCompareWithInterpreter(s, startOffset, offsetVector, result); + matchCompareWithInterpreter(s, startOffset, offsetVector, result); #endif - } else + } else #endif - result = Yarr::interpret(m_representation->m_regExpBytecode.get(), s, startOffset, s.length(), offsetVector); - ASSERT(result >= -1); + result = Yarr::interpret(m_representation->m_regExpBytecode.get(), s, startOffset, s.length(), offsetVector); + ASSERT(result >= -1); #if REGEXP_FUNC_TEST_DATA_GEN - RegExpFunctionalTestCollector::get()->outputOneTest(this, s, startOffset, offsetVector, result); + RegExpFunctionalTestCollector::get()->outputOneTest(this, s, startOffset, offsetVector, result); #endif #if ENABLE(REGEXP_TRACING) - if (result != -1) - m_rtMatchFoundCount++; + if (result != -1) + m_rtMatchFoundCount++; #endif - return result; - } - - return -1; + return result; } void RegExp::invalidateCode() |