Changeset 45545 in webkit for trunk/JavaScriptCore/runtime/RegExpConstructor.cpp
- Timestamp:
- Jul 4, 2009, 7:21:30 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/runtime/RegExpConstructor.cpp
r45269 r45545 2 2 * Copyright (C) 1999-2000 Harri Porten ([email protected]) 3 3 * Copyright (C) 2003, 2007, 2008 Apple Inc. All Rights Reserved. 4 * Copyright (C) 2009 Torch Mobile, Inc. 4 5 * 5 6 * This library is free software; you can redistribute it and/or … … 94 95 : lastNumSubPatterns(0) 95 96 , multiline(false) 97 , lastOvectorIndex(0) 96 98 { 97 99 } 100 101 const Vector<int, 32>& lastOvector() const { return ovector[lastOvectorIndex]; } 102 Vector<int, 32>& lastOvector() { return ovector[lastOvectorIndex]; } 103 Vector<int, 32>& tempOvector() { return ovector[lastOvectorIndex ? 0 : 1]; } 104 void changeLastOvector() { lastOvectorIndex = lastOvectorIndex ? 0 : 1; } 98 105 99 106 UString input; 100 107 UString lastInput; 101 OwnArrayPtr<int> lastOvector;102 unsigned lastNumSubPatterns : 3 1;108 Vector<int, 32> ovector[2]; 109 unsigned lastNumSubPatterns : 30; 103 110 bool multiline : 1; 111 unsigned lastOvectorIndex : 1; 104 112 }; 105 113 … … 122 130 void RegExpConstructor::performMatch(RegExp* r, const UString& s, int startOffset, int& position, int& length, int** ovector) 123 131 { 124 OwnArrayPtr<int> tmpOvector; 125 position = r->match(s, startOffset, &tmpOvector); 132 position = r->match(s, startOffset, &d->tempOvector()); 126 133 127 134 if (ovector) 128 *ovector = tmpOvector.get();135 *ovector = d->tempOvector().data(); 129 136 130 137 if (position != -1) { 131 ASSERT( tmpOvector);132 133 length = tmpOvector[1] - tmpOvector[0];138 ASSERT(!d->tempOvector().isEmpty()); 139 140 length = d->tempOvector()[1] - d->tempOvector()[0]; 134 141 135 142 d->input = s; 136 143 d->lastInput = s; 137 d-> lastOvector.set(tmpOvector.release());144 d->changeLastOvector(); 138 145 d->lastNumSubPatterns = r->numSubpatterns(); 139 146 } … … 148 155 d->lastNumSubPatterns = data->lastNumSubPatterns; 149 156 unsigned offsetVectorSize = (data->lastNumSubPatterns + 1) * 2; // only copying the result part of the vector 150 d->lastOvector .set(new int[offsetVectorSize]);151 memcpy(d->lastOvector .get(), data->lastOvector.get(), offsetVectorSize * sizeof(int));157 d->lastOvector().resize(offsetVectorSize); 158 memcpy(d->lastOvector().data(), data->lastOvector().data(), offsetVectorSize * sizeof(int)); 152 159 // d->multiline is not needed, and remains uninitialized 153 160 … … 168 175 169 176 for (unsigned i = 0; i <= lastNumSubpatterns; ++i) { 170 int start = d->lastOvector [2 * i];177 int start = d->lastOvector()[2 * i]; 171 178 if (start >= 0) 172 JSArray::put(exec, i, jsSubstring(exec, d->lastInput, start, d->lastOvector [2 * i + 1] - start));179 JSArray::put(exec, i, jsSubstring(exec, d->lastInput, start, d->lastOvector()[2 * i + 1] - start)); 173 180 } 174 181 175 182 PutPropertySlot slot; 176 JSArray::put(exec, exec->propertyNames().index, jsNumber(exec, d->lastOvector [0]), slot);183 JSArray::put(exec, exec->propertyNames().index, jsNumber(exec, d->lastOvector()[0]), slot); 177 184 JSArray::put(exec, exec->propertyNames().input, jsString(exec, d->input), slot); 178 185 … … 188 195 JSValue RegExpConstructor::getBackref(ExecState* exec, unsigned i) const 189 196 { 190 if ( d->lastOvector&& i <= d->lastNumSubPatterns) {191 int start = d->lastOvector [2 * i];197 if (!d->lastOvector().isEmpty() && i <= d->lastNumSubPatterns) { 198 int start = d->lastOvector()[2 * i]; 192 199 if (start >= 0) 193 return jsSubstring(exec, d->lastInput, start, d->lastOvector [2 * i + 1] - start);200 return jsSubstring(exec, d->lastInput, start, d->lastOvector()[2 * i + 1] - start); 194 201 } 195 202 return jsEmptyString(exec); … … 201 208 if (i > 0) { 202 209 ASSERT(d->lastOvector); 203 int start = d->lastOvector [2 * i];210 int start = d->lastOvector()[2 * i]; 204 211 if (start >= 0) 205 return jsSubstring(exec, d->lastInput, start, d->lastOvector [2 * i + 1] - start);212 return jsSubstring(exec, d->lastInput, start, d->lastOvector()[2 * i + 1] - start); 206 213 } 207 214 return jsEmptyString(exec); … … 210 217 JSValue RegExpConstructor::getLeftContext(ExecState* exec) const 211 218 { 212 if ( d->lastOvector)213 return jsSubstring(exec, d->lastInput, 0, d->lastOvector [0]);219 if (!d->lastOvector().isEmpty()) 220 return jsSubstring(exec, d->lastInput, 0, d->lastOvector()[0]); 214 221 return jsEmptyString(exec); 215 222 } … … 217 224 JSValue RegExpConstructor::getRightContext(ExecState* exec) const 218 225 { 219 if ( d->lastOvector)220 return jsSubstring(exec, d->lastInput, d->lastOvector [1], d->lastInput.size() - d->lastOvector[1]);226 if (!d->lastOvector().isEmpty()) 227 return jsSubstring(exec, d->lastInput, d->lastOvector()[1], d->lastInput.size() - d->lastOvector()[1]); 221 228 return jsEmptyString(exec); 222 229 }
Note:
See TracChangeset
for help on using the changeset viewer.