Changeset 36244 in webkit for trunk/JavaScriptCore/kjs/regexp.cpp
- Timestamp:
- Sep 6, 2008, 10:44:58 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/regexp.cpp
r35027 r36244 22 22 #include "regexp.h" 23 23 24 #include "CTI.h" 24 25 #include "lexer.h" 25 26 #include <pcre/pcre.h> … … 32 33 namespace KJS { 33 34 34 inline RegExp::RegExp(const UString& pattern) 35 36 37 inline RegExp::RegExp(ExecState* exec, const UString& pattern) 35 38 : m_pattern(pattern) 36 39 , m_flagBits(0) 40 , m_regExp(0) 37 41 , m_constructionError(0) 38 42 , m_numSubpatterns(0) 39 43 { 40 m_regExp = jsRegExpCompile(reinterpret_cast<const UChar*>(pattern.data()), pattern.size(), 41 JSRegExpDoNotIgnoreCase, JSRegExpSingleLine, &m_numSubpatterns, &m_constructionError); 44 #if ENABLE(WREC) 45 if (!(m_wrecFunction = (WRECFunction)CTI::compileRegExp(exec, pattern, &m_numSubpatterns, &m_constructionError))) 46 #else 47 UNUSED_PARAM(exec); 48 #endif 49 { 50 m_regExp = jsRegExpCompile(reinterpret_cast<const UChar*>(pattern.data()), pattern.size(), 51 JSRegExpDoNotIgnoreCase, JSRegExpSingleLine, &m_numSubpatterns, &m_constructionError); 52 } 42 53 } 43 54 44 PassRefPtr<RegExp> RegExp::create( const UString& pattern)55 PassRefPtr<RegExp> RegExp::create(ExecState* exec, const UString& pattern) 45 56 { 46 return adoptRef(new RegExp( pattern));57 return adoptRef(new RegExp(exec, pattern)); 47 58 } 48 59 49 inline RegExp::RegExp( const UString& pattern, const UString& flags)60 inline RegExp::RegExp(ExecState* exec, const UString& pattern, const UString& flags) 50 61 : m_pattern(pattern) 51 62 , m_flags(flags) 52 63 , m_flagBits(0) 64 , m_regExp(0) 53 65 , m_constructionError(0) 54 66 , m_numSubpatterns(0) … … 72 84 } 73 85 74 m_regExp = jsRegExpCompile(reinterpret_cast<const UChar*>(pattern.data()), pattern.size(), 75 ignoreCaseOption, multilineOption, &m_numSubpatterns, &m_constructionError); 86 #if ENABLE(WREC) 87 if (!(m_wrecFunction = (WRECFunction)CTI::compileRegExp(exec, pattern, &m_numSubpatterns, &m_constructionError, (m_flagBits & IgnoreCase), (m_flagBits & Multiline)))) 88 #else 89 UNUSED_PARAM(exec); 90 #endif 91 { 92 m_regExp = jsRegExpCompile(reinterpret_cast<const UChar*>(pattern.data()), pattern.size(), 93 ignoreCaseOption, multilineOption, &m_numSubpatterns, &m_constructionError); 94 } 76 95 } 77 96 78 PassRefPtr<RegExp> RegExp::create( const UString& pattern, const UString& flags)97 PassRefPtr<RegExp> RegExp::create(ExecState* exec, const UString& pattern, const UString& flags) 79 98 { 80 return adoptRef(new RegExp( pattern, flags));99 return adoptRef(new RegExp(exec, pattern, flags)); 81 100 } 82 101 … … 84 103 { 85 104 jsRegExpFree(m_regExp); 105 #if ENABLE(WREC) 106 if (m_wrecFunction) 107 fastFree(reinterpret_cast<void*>(m_wrecFunction)); 108 #endif 86 109 } 87 110 … … 96 119 return -1; 97 120 98 if (!m_regExp) 99 return -1; 121 #if ENABLE(WREC) 122 if (m_wrecFunction) { 123 int offsetVectorSize = (m_numSubpatterns + 1) * 2; 124 int* offsetVector = new int [offsetVectorSize]; 125 for (int j = 0; j < offsetVectorSize; ++j) 126 offsetVector[j] = -1; 100 127 101 // Set up the offset vector for the result. 102 // First 2/3 used for result, the last third used by PCRE. 103 int* offsetVector; 104 int offsetVectorSize; 105 int fixedSizeOffsetVector[3]; 106 if (!ovector) { 107 offsetVectorSize = 3; 108 offsetVector = fixedSizeOffsetVector; 109 } else { 110 offsetVectorSize = (m_numSubpatterns + 1) * 3; 111 offsetVector = new int [offsetVectorSize]; 112 ovector->set(offsetVector); 128 OwnArrayPtr<int> nonReturnedOvector; 129 if (!ovector) 130 nonReturnedOvector.set(offsetVector); 131 else 132 ovector->set(offsetVector); 133 134 int result = m_wrecFunction(s.data(), i, s.size(), offsetVector); 135 136 if (result < 0) { 137 #ifndef NDEBUG 138 // TODO: define up a symbol, rather than magic -1 139 if (result != -1) 140 fprintf(stderr, "jsRegExpExecute failed with result %d\n", result); 141 #endif 142 if (ovector) 143 ovector->clear(); 144 } 145 return result; 146 } else 147 #endif 148 if (m_regExp) { 149 // Set up the offset vector for the result. 150 // First 2/3 used for result, the last third used by PCRE. 151 int* offsetVector; 152 int offsetVectorSize; 153 int fixedSizeOffsetVector[3]; 154 if (!ovector) { 155 offsetVectorSize = 3; 156 offsetVector = fixedSizeOffsetVector; 157 } else { 158 offsetVectorSize = (m_numSubpatterns + 1) * 3; 159 offsetVector = new int [offsetVectorSize]; 160 ovector->set(offsetVector); 161 } 162 163 int numMatches = jsRegExpExecute(m_regExp, reinterpret_cast<const UChar*>(s.data()), s.size(), i, offsetVector, offsetVectorSize); 164 165 if (numMatches < 0) { 166 #ifndef NDEBUG 167 if (numMatches != JSRegExpErrorNoMatch) 168 fprintf(stderr, "jsRegExpExecute failed with result %d\n", numMatches); 169 #endif 170 if (ovector) 171 ovector->clear(); 172 return -1; 173 } 174 175 return offsetVector[0]; 113 176 } 114 177 115 int numMatches = jsRegExpExecute(m_regExp, reinterpret_cast<const UChar*>(s.data()), s.size(), i, offsetVector, offsetVectorSize); 116 117 if (numMatches < 0) { 118 #ifndef NDEBUG 119 if (numMatches != JSRegExpErrorNoMatch) 120 fprintf(stderr, "jsRegExpExecute failed with result %d\n", numMatches); 121 #endif 122 if (ovector) 123 ovector->clear(); 124 return -1; 125 } 126 127 return offsetVector[0]; 178 return -1; 128 179 } 129 180
Note:
See TracChangeset
for help on using the changeset viewer.