Changeset 21031 in webkit for trunk/JavaScriptCore/kjs/regexp_object.cpp
- Timestamp:
- Apr 23, 2007, 2:45:35 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/regexp_object.cpp
r20310 r21031 181 181 */ 182 182 183 struct KJS::RegExpObjectImpPrivate { 184 // Global search cache / settings 185 RegExpObjectImpPrivate() : lastInput(""), lastNumSubPatterns(0), multiline(false) { } 186 UString lastInput; 187 OwnArrayPtr<int> lastOvector; 188 unsigned lastNumSubPatterns : 31; 189 bool multiline : 1; 190 }; 191 183 192 RegExpObjectImp::RegExpObjectImp(ExecState* exec, FunctionPrototype* funcProto, RegExpPrototype* regProto) 184 185 : InternalFunctionImp(funcProto), lastInput(""), lastNumSubPatterns(0), multiline(false)193 : InternalFunctionImp(funcProto) 194 , d(new RegExpObjectImpPrivate) 186 195 { 187 196 // ECMA 15.10.5.1 RegExp.prototype … … 211 220 ASSERT(tmpOvector); 212 221 213 lastInput = s;214 lastOvector.set(tmpOvector);215 lastNumSubPatterns = r->subPatterns();222 d->lastInput = s; 223 d->lastOvector.set(tmpOvector); 224 d->lastNumSubPatterns = r->subPatterns(); 216 225 } 217 226 … … 224 233 // The returned array contains 'result' as first item, followed by the list of matches 225 234 list.append(jsString(result)); 226 if ( lastOvector)227 for ( unsigned i = 1 ; i < lastNumSubPatterns + 1 ; ++i)235 if (d->lastOvector) 236 for (unsigned i = 1 ; i < d->lastNumSubPatterns + 1 ; ++i) 228 237 { 229 int start = lastOvector[2*i];238 int start = d->lastOvector[2*i]; 230 239 if (start == -1) 231 240 list.append(jsUndefined()); 232 241 else { 233 UString substring = lastInput.substr( start, lastOvector[2*i+1] - start);242 UString substring = d->lastInput.substr(start, d->lastOvector[2*i+1] - start); 234 243 list.append(jsString(substring)); 235 244 } 236 245 } 237 246 JSObject *arr = exec->lexicalInterpreter()->builtinArray()->construct(exec, list); 238 arr->put(exec, "index", jsNumber( lastOvector[0]));239 arr->put(exec, "input", jsString( lastInput));247 arr->put(exec, "index", jsNumber(d->lastOvector[0])); 248 arr->put(exec, "input", jsString(d->lastInput)); 240 249 return arr; 241 250 } … … 243 252 JSValue *RegExpObjectImp::getBackref(unsigned i) const 244 253 { 245 if ( lastOvector && i <lastNumSubPatterns + 1) {246 UString substring = lastInput.substr(lastOvector[2*i], lastOvector[2*i+1] -lastOvector[2*i] );254 if (d->lastOvector && i < d->lastNumSubPatterns + 1) { 255 UString substring = d->lastInput.substr(d->lastOvector[2*i], d->lastOvector[2*i+1] - d->lastOvector[2*i] ); 247 256 return jsString(substring); 248 257 } … … 253 262 JSValue *RegExpObjectImp::getLastMatch() const 254 263 { 255 if ( lastOvector) {256 UString substring = lastInput.substr(lastOvector[0], lastOvector[1] -lastOvector[0]);264 if (d->lastOvector) { 265 UString substring = d->lastInput.substr(d->lastOvector[0], d->lastOvector[1] - d->lastOvector[0]); 257 266 return jsString(substring); 258 267 } … … 263 272 JSValue *RegExpObjectImp::getLastParen() const 264 273 { 265 int i = lastNumSubPatterns;274 int i = d->lastNumSubPatterns; 266 275 if (i > 0) { 267 ASSERT( lastOvector);268 UString substring = lastInput.substr(lastOvector[2*i], lastOvector[2*i+1] -lastOvector[2*i]);276 ASSERT(d->lastOvector); 277 UString substring = d->lastInput.substr(d->lastOvector[2*i], d->lastOvector[2*i+1] - d->lastOvector[2*i]); 269 278 return jsString(substring); 270 279 } … … 275 284 JSValue *RegExpObjectImp::getLeftContext() const 276 285 { 277 if ( lastOvector) {278 UString substring = lastInput.substr(0,lastOvector[0]);286 if (d->lastOvector) { 287 UString substring = d->lastInput.substr(0, d->lastOvector[0]); 279 288 return jsString(substring); 280 289 } … … 285 294 JSValue *RegExpObjectImp::getRightContext() const 286 295 { 287 if ( lastOvector) {288 UString s = lastInput;289 UString substring = s.substr( lastOvector[1], s.size() -lastOvector[1]);296 if (d->lastOvector) { 297 UString s = d->lastInput; 298 UString substring = s.substr(d->lastOvector[1], s.size() - d->lastOvector[1]); 290 299 return jsString(substring); 291 300 } … … 321 330 return getBackref(9); 322 331 case Input: 323 return jsString( lastInput);332 return jsString(d->lastInput); 324 333 case Multiline: 325 return jsBoolean( multiline);334 return jsBoolean(d->multiline); 326 335 case LastMatch: 327 336 return getLastMatch(); … … 348 357 switch (token) { 349 358 case Input: 350 lastInput = value->toString(exec);359 d->lastInput = value->toString(exec); 351 360 break; 352 361 case Multiline: 353 multiline = value->toBoolean(exec);362 d->multiline = value->toBoolean(exec); 354 363 break; 355 364 default:
Note:
See TracChangeset
for help on using the changeset viewer.