Changeset 72207 in webkit for trunk/JavaScriptCore/runtime/RegExp.cpp
- Timestamp:
- Nov 17, 2010, 7:52:43 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/runtime/RegExp.cpp
r72197 r72207 29 29 #include <wtf/OwnArrayPtr.h> 30 30 31 32 #if ENABLE(YARR) 33 31 34 #include "yarr/RegexCompiler.h" 32 35 #if ENABLE(YARR_JIT) … … 36 39 #endif 37 40 41 #else 42 43 #include <pcre/pcre.h> 44 45 #endif 46 38 47 namespace JSC { 39 48 … … 41 50 #if ENABLE(YARR_JIT) 42 51 Yarr::RegexCodeBlock m_regExpJITCode; 43 #el se52 #elif ENABLE(YARR) 44 53 OwnPtr<Yarr::BytecodePattern> m_regExpBytecode; 54 #else 55 JSRegExp* m_regExp; 56 #endif 57 58 #if !ENABLE(YARR) 59 ~RegExpRepresentation() 60 { 61 jsRegExpFree(m_regExp); 62 } 45 63 #endif 46 64 }; … … 83 101 } 84 102 103 #if ENABLE(YARR) 104 85 105 void RegExp::compile(JSGlobalData* globalData) 86 106 { 87 107 #if ENABLE(YARR_JIT) 88 Yarr::jitCompileRegex(globalData, m_representation->m_regExpJITCode, m_pattern, m_numSubpatterns, m_constructionError, &globalData->m_regexAllocator,ignoreCase(), multiline());108 Yarr::jitCompileRegex(globalData, m_representation->m_regExpJITCode, m_pattern, m_numSubpatterns, m_constructionError, ignoreCase(), multiline()); 89 109 #else 90 110 m_representation->m_regExpBytecode = Yarr::byteCompileRegex(m_pattern, m_numSubpatterns, m_constructionError, &globalData->m_regexAllocator, ignoreCase(), multiline()); … … 109 129 if (m_representation->m_regExpBytecode) { 110 130 #endif 111 int offsetVectorSize = (m_numSubpatterns + 1) * 2;131 int offsetVectorSize = (m_numSubpatterns + 1) * 3; // FIXME: should be 2 - but adding temporary fallback to pcre. 112 132 int* offsetVector; 113 133 Vector<int, 32> nonReturnedOvector; … … 128 148 129 149 #if ENABLE(YARR_JIT) 130 int result = Yarr::executeRegex(m_representation->m_regExpJITCode, s.characters(), startOffset, s.length(), offsetVector );150 int result = Yarr::executeRegex(m_representation->m_regExpJITCode, s.characters(), startOffset, s.length(), offsetVector, offsetVectorSize); 131 151 #else 132 152 int result = Yarr::interpretRegex(m_representation->m_regExpBytecode.get(), s.characters(), startOffset, s.length(), offsetVector); … … 152 172 } 153 173 174 #else 175 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 #endif 189 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 NDEBUG 217 if (numMatches != JSRegExpErrorNoMatch) 218 fprintf(stderr, "jsRegExpExecute failed with result %d\n", numMatches); 219 #endif 220 if (ovector) 221 ovector->clear(); 222 return -1; 223 } 224 225 #if ENABLE(REGEXP_TRACING) 226 m_rtMatchFoundCount++; 227 #endif 228 229 return offsetVector[0]; 230 } 231 232 return -1; 233 } 234 235 #endif 236 154 237 #if ENABLE(REGEXP_TRACING) 155 238 void RegExp::printTraceData()
Note:
See TracChangeset
for help on using the changeset viewer.