Changeset 69590 in webkit
- Timestamp:
- Oct 12, 2010 11:34:18 AM (13 years ago)
- Location:
- trunk/JavaScriptCore
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/ChangeLog
r69535 r69590 1 2010-10-12 Michael Saboff <msaboff@apple.com> 2 3 Reviewed by Oliver Hunt. 4 5 Cleaned up the processing of replacements after regular expression 6 processing, especially the case where there wasn't a match. 7 Changed to use empty strings instead of computing a zero length sub 8 string. 9 https://bugs.webkit.org/show_bug.cgi?id=47506 10 11 * runtime/StringPrototype.cpp: 12 (JSC::jsSpliceSubstringsWithSeparators): 13 (JSC::stringProtoFuncReplace): 14 1 15 2010-10-11 Patrick Gansterer <paroga@webkit.org> 2 16 -
trunk/JavaScriptCore/runtime/StringPrototype.cpp
r69422 r69590 277 277 for (int i = 0; i < maxCount; i++) { 278 278 if (i < rangeCount) { 279 StringImpl::copyChars(buffer + bufferPos, source.characters() + substringRanges[i].position, substringRanges[i].length); 280 bufferPos += substringRanges[i].length; 279 if (int srcLen = substringRanges[i].length) { 280 StringImpl::copyChars(buffer + bufferPos, source.characters() + substringRanges[i].position, srcLen); 281 bufferPos += srcLen; 282 } 281 283 } 282 284 if (i < separatorCount) { 283 StringImpl::copyChars(buffer + bufferPos, separators[i].characters(), separators[i].length()); 284 bufferPos += separators[i].length(); 285 if (int sepLen = separators[i].length()) { 286 StringImpl::copyChars(buffer + bufferPos, separators[i].characters(), sepLen); 287 bufferPos += sepLen; 288 } 285 289 } 286 290 } … … 304 308 if (pattern.inherits(&RegExpObject::info)) { 305 309 const UString& source = sourceVal->value(exec); 310 unsigned sourceLen = source.length(); 306 311 if (exec->hadException()) 307 312 return JSValue::encode(JSValue()); … … 332 337 if (matchIndex < 0) 333 338 break; 334 339 335 340 sourceRanges.append(StringRange(lastIndex, matchIndex - lastIndex)); 336 341 … … 349 354 cachedCall.setArgument(i++, jsNumber(exec, completeMatchStart)); 350 355 cachedCall.setArgument(i++, sourceVal); 351 356 352 357 cachedCall.setThis(exec->globalThisValue()); 353 358 JSValue result = cachedCall.call(); … … 365 370 if (matchLen == 0) { 366 371 startPosition++; 367 if (startPosition > source .length())372 if (startPosition > sourceLen) 368 373 break; 369 374 } 370 } 375 } 371 376 } else { 372 377 do { … … 378 383 break; 379 384 380 sourceRanges.append(StringRange(lastIndex, matchIndex - lastIndex));381 382 385 if (callType != CallTypeNone) { 386 sourceRanges.append(StringRange(lastIndex, matchIndex - lastIndex)); 387 383 388 int completeMatchStart = ovector[0]; 384 389 MarkedArgumentBuffer args; … … 387 392 int matchStart = ovector[i * 2]; 388 393 int matchLen = ovector[i * 2 + 1] - matchStart; 389 394 390 395 if (matchStart < 0) 391 396 args.append(jsUndefined()); … … 400 405 if (exec->hadException()) 401 406 break; 402 } else 403 replacements.append(substituteBackreferences(replacementString, source, ovector, reg)); 407 } else { 408 int replLen = replacementString.length(); 409 if (lastIndex < matchIndex || replLen) { 410 sourceRanges.append(StringRange(lastIndex, matchIndex - lastIndex)); 411 412 if (replLen) 413 replacements.append(substituteBackreferences(replacementString, source, ovector, reg)); 414 else 415 replacements.append(UString()); 416 } 417 } 404 418 405 419 lastIndex = matchIndex + matchLen; … … 409 423 if (matchLen == 0) { 410 424 startPosition++; 411 if (startPosition > source .length())425 if (startPosition > sourceLen) 412 426 break; 413 427 } … … 418 432 return JSValue::encode(sourceVal); 419 433 420 if (static_cast<unsigned>(lastIndex) < source .length())421 sourceRanges.append(StringRange(lastIndex, source .length()- lastIndex));434 if (static_cast<unsigned>(lastIndex) < sourceLen) 435 sourceRanges.append(StringRange(lastIndex, sourceLen - lastIndex)); 422 436 423 437 return JSValue::encode(jsSpliceSubstringsWithSeparators(exec, sourceVal, source, sourceRanges.data(), sourceRanges.size(), replacements.data(), replacements.size()));
Note: See TracChangeset
for help on using the changeset viewer.