Changeset 72197 in webkit for trunk/JavaScriptCore/runtime/RegExp.cpp
- Timestamp:
- Nov 17, 2010, 5:15:56 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/runtime/RegExp.cpp
r68639 r72197 29 29 #include <wtf/OwnArrayPtr.h> 30 30 31 32 #if ENABLE(YARR)33 34 31 #include "yarr/RegexCompiler.h" 35 32 #if ENABLE(YARR_JIT) … … 39 36 #endif 40 37 41 #else42 43 #include <pcre/pcre.h>44 45 #endif46 47 38 namespace JSC { 48 39 … … 50 41 #if ENABLE(YARR_JIT) 51 42 Yarr::RegexCodeBlock m_regExpJITCode; 52 #el if ENABLE(YARR)43 #else 53 44 OwnPtr<Yarr::BytecodePattern> m_regExpBytecode; 54 #else55 JSRegExp* m_regExp;56 #endif57 58 #if !ENABLE(YARR)59 ~RegExpRepresentation()60 {61 jsRegExpFree(m_regExp);62 }63 45 #endif 64 46 }; … … 101 83 } 102 84 103 #if ENABLE(YARR)104 105 85 void RegExp::compile(JSGlobalData* globalData) 106 86 { 107 87 #if ENABLE(YARR_JIT) 108 Yarr::jitCompileRegex(globalData, m_representation->m_regExpJITCode, m_pattern, m_numSubpatterns, m_constructionError, ignoreCase(), multiline());88 Yarr::jitCompileRegex(globalData, m_representation->m_regExpJITCode, m_pattern, m_numSubpatterns, m_constructionError, &globalData->m_regexAllocator, ignoreCase(), multiline()); 109 89 #else 110 90 m_representation->m_regExpBytecode = Yarr::byteCompileRegex(m_pattern, m_numSubpatterns, m_constructionError, &globalData->m_regexAllocator, ignoreCase(), multiline()); … … 129 109 if (m_representation->m_regExpBytecode) { 130 110 #endif 131 int offsetVectorSize = (m_numSubpatterns + 1) * 3; // FIXME: should be 2 - but adding temporary fallback to pcre.111 int offsetVectorSize = (m_numSubpatterns + 1) * 2; 132 112 int* offsetVector; 133 113 Vector<int, 32> nonReturnedOvector; … … 148 128 149 129 #if ENABLE(YARR_JIT) 150 int result = Yarr::executeRegex(m_representation->m_regExpJITCode, s.characters(), startOffset, s.length(), offsetVector , offsetVectorSize);130 int result = Yarr::executeRegex(m_representation->m_regExpJITCode, s.characters(), startOffset, s.length(), offsetVector); 151 131 #else 152 132 int result = Yarr::interpretRegex(m_representation->m_regExpBytecode.get(), s.characters(), startOffset, s.length(), offsetVector); … … 171 151 return -1; 172 152 } 173 174 #else175 176 void RegExp::compile(JSGlobalData*)177 {178 m_representation->m_regExp = 0;179 JSRegExpIgnoreCaseOption ignoreCaseOption = ignoreCase() ? JSRegExpIgnoreCase : JSRegExpDoNotIgnoreCase;180 JSRegExpMultilineOption multilineOption = multiline() ? JSRegExpMultiline : JSRegExpSingleLine;181 m_representation->m_regExp = jsRegExpCompile(reinterpret_cast<const UChar*>(m_pattern.characters()), m_pattern.length(), ignoreCaseOption, multilineOption, &m_numSubpatterns, &m_constructionError);182 }183 184 int RegExp::match(const UString& s, int startOffset, Vector<int, 32>* ovector)185 {186 #if ENABLE(REGEXP_TRACING)187 m_rtMatchCallCount++;188 #endif189 190 if (startOffset < 0)191 startOffset = 0;192 if (ovector)193 ovector->clear();194 195 if (static_cast<unsigned>(startOffset) > s.length() || s.isNull())196 return -1;197 198 if (m_representation->m_regExp) {199 // Set up the offset vector for the result.200 // First 2/3 used for result, the last third used by PCRE.201 int* offsetVector;202 int offsetVectorSize;203 int fixedSizeOffsetVector[3];204 if (!ovector) {205 offsetVectorSize = 3;206 offsetVector = fixedSizeOffsetVector;207 } else {208 offsetVectorSize = (m_numSubpatterns + 1) * 3;209 ovector->resize(offsetVectorSize);210 offsetVector = ovector->data();211 }212 213 int numMatches = jsRegExpExecute(m_representation->m_regExp, reinterpret_cast<const UChar*>(s.characters()), s.length(), startOffset, offsetVector, offsetVectorSize);214 215 if (numMatches < 0) {216 #ifndef NDEBUG217 if (numMatches != JSRegExpErrorNoMatch)218 fprintf(stderr, "jsRegExpExecute failed with result %d\n", numMatches);219 #endif220 if (ovector)221 ovector->clear();222 return -1;223 }224 225 #if ENABLE(REGEXP_TRACING)226 m_rtMatchFoundCount++;227 #endif228 229 return offsetVector[0];230 }231 232 return -1;233 }234 235 #endif236 153 237 154 #if ENABLE(REGEXP_TRACING)
Note:
See TracChangeset
for help on using the changeset viewer.