Changeset 69590 in webkit


Ignore:
Timestamp:
Oct 12, 2010 11:34:18 AM (13 years ago)
Author:
msaboff@apple.com
Message:

2010-10-12 Michael Saboff <msaboff@apple.com>

Reviewed by Oliver Hunt.

Cleaned up the processing of replacements after regular expression
processing, especially the case where there wasn't a match.
Changed to use empty strings instead of computing a zero length sub
string.
https://bugs.webkit.org/show_bug.cgi?id=47506

  • runtime/StringPrototype.cpp: (JSC::jsSpliceSubstringsWithSeparators): (JSC::stringProtoFuncReplace):
Location:
trunk/JavaScriptCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/ChangeLog

    r69535 r69590  
     12010-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
    1152010-10-11  Patrick Gansterer  <paroga@webkit.org>
    216
  • trunk/JavaScriptCore/runtime/StringPrototype.cpp

    r69422 r69590  
    277277    for (int i = 0; i < maxCount; i++) {
    278278        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            }
    281283        }
    282284        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            }
    285289        }
    286290    }
     
    304308    if (pattern.inherits(&RegExpObject::info)) {
    305309        const UString& source = sourceVal->value(exec);
     310        unsigned sourceLen = source.length();
    306311        if (exec->hadException())
    307312            return JSValue::encode(JSValue());
     
    332337                if (matchIndex < 0)
    333338                    break;
    334                
     339
    335340                sourceRanges.append(StringRange(lastIndex, matchIndex - lastIndex));
    336341
     
    349354                cachedCall.setArgument(i++, jsNumber(exec, completeMatchStart));
    350355                cachedCall.setArgument(i++, sourceVal);
    351                
     356
    352357                cachedCall.setThis(exec->globalThisValue());
    353358                JSValue result = cachedCall.call();
     
    365370                if (matchLen == 0) {
    366371                    startPosition++;
    367                     if (startPosition > source.length())
     372                    if (startPosition > sourceLen)
    368373                        break;
    369374                }
    370             }           
     375            }
    371376        } else {
    372377            do {
     
    378383                    break;
    379384
    380                 sourceRanges.append(StringRange(lastIndex, matchIndex - lastIndex));
    381 
    382385                if (callType != CallTypeNone) {
     386                    sourceRanges.append(StringRange(lastIndex, matchIndex - lastIndex));
     387
    383388                    int completeMatchStart = ovector[0];
    384389                    MarkedArgumentBuffer args;
     
    387392                        int matchStart = ovector[i * 2];
    388393                        int matchLen = ovector[i * 2 + 1] - matchStart;
    389 
     394 
    390395                        if (matchStart < 0)
    391396                            args.append(jsUndefined());
     
    400405                    if (exec->hadException())
    401406                        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                }
    404418
    405419                lastIndex = matchIndex + matchLen;
     
    409423                if (matchLen == 0) {
    410424                    startPosition++;
    411                     if (startPosition > source.length())
     425                    if (startPosition > sourceLen)
    412426                        break;
    413427                }
     
    418432            return JSValue::encode(sourceVal);
    419433
    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));
    422436
    423437        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.