Changeset 199780 in webkit


Ignore:
Timestamp:
Apr 20, 2016 12:10:43 PM (8 years ago)
Author:
mark.lam@apple.com
Message:

Unindent an unnecessary block in stringProtoFuncSplitFast().
https://bugs.webkit.org/show_bug.cgi?id=156802

Reviewed by Filip Pizlo.

In webkit.org/b/156013, I refactored stringProtoFuncSplit into
stringProtoFuncSplitFast. In that patch, I left an unnecessary block of code in
its original block (with FIXMEs) to keep the diff for that patch minimal. Now
that the patch for webkit.org/b/156013 has landed, I will unindent that block and
remove the FIXMEs.

  • runtime/StringPrototype.cpp:

(JSC::stringProtoFuncSplitFast):

Location:
trunk/Source/JavaScriptCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r199779 r199780  
     12016-04-20  Mark Lam  <mark.lam@apple.com>
     2
     3        Unindent an unnecessary block in stringProtoFuncSplitFast().
     4        https://bugs.webkit.org/show_bug.cgi?id=156802
     5
     6        Reviewed by Filip Pizlo.
     7
     8        In webkit.org/b/156013, I refactored stringProtoFuncSplit into
     9        stringProtoFuncSplitFast.  In that patch, I left an unnecessary block of code in
     10        its original block (with FIXMEs) to keep the diff for that patch minimal.  Now
     11        that the patch for webkit.org/b/156013 has landed, I will unindent that block and
     12        remove the FIXMEs.
     13
     14        * runtime/StringPrototype.cpp:
     15        (JSC::stringProtoFuncSplitFast):
     16
    1172016-04-20  Brady Eidson  <beidson@apple.com>
    218
  • trunk/Source/JavaScriptCore/runtime/StringPrototype.cpp

    r199731 r199780  
    11891189    //    otherwise let R = ToString(separator).
    11901190    JSValue separatorValue = exec->uncheckedArgument(0);
    1191     { // FIXME: Keeping this indentation here to minimize the diff. Will unindent and remove this later.
    1192         String separator = separatorValue.toString(exec)->value(exec);
    1193         if (exec->hadException())
    1194             return JSValue::encode(jsUndefined());
    1195 
    1196         // 10. If lim == 0, return A.
    1197         if (!limit)
    1198             return JSValue::encode(result);
    1199 
    1200         // 11. If separator is undefined, then
    1201         if (separatorValue.isUndefined()) {
    1202             // a.  Call the [[DefineOwnProperty]] internal method of A with arguments "0",
     1191    String separator = separatorValue.toString(exec)->value(exec);
     1192    if (exec->hadException())
     1193        return JSValue::encode(jsUndefined());
     1194
     1195    // 10. If lim == 0, return A.
     1196    if (!limit)
     1197        return JSValue::encode(result);
     1198
     1199    // 11. If separator is undefined, then
     1200    if (separatorValue.isUndefined()) {
     1201        // a. Call the [[DefineOwnProperty]] internal method of A with arguments "0",
     1202        result->putDirectIndex(exec, 0, jsStringWithReuse(exec, thisValue, input));
     1203        // b. Return A.
     1204        return JSValue::encode(result);
     1205    }
     1206
     1207    // 12. If s == 0, then
     1208    if (input.isEmpty()) {
     1209        // a. Let z be SplitMatch(S, 0, R) where S is input, R is separator.
     1210        // b. If z is not false, return A.
     1211        // c. Call CreateDataProperty(A, "0", S).
     1212        // d. Return A.
     1213        if (!separator.isEmpty())
    12031214            result->putDirectIndex(exec, 0, jsStringWithReuse(exec, thisValue, input));
    1204             // b.  Return A.
    1205             return JSValue::encode(result);
     1215        return JSValue::encode(result);
     1216    }
     1217
     1218    // Optimized case for splitting on the empty string.
     1219    if (separator.isEmpty()) {
     1220        limit = std::min(limit, input.length());
     1221        // Zero limt/input length handled in steps 9/11 respectively, above.
     1222        ASSERT(limit);
     1223
     1224        do {
     1225            result->putDirectIndex(exec, position, jsSingleCharacterString(exec, input[position]));
     1226        } while (++position < limit);
     1227
     1228        return JSValue::encode(result);
     1229    }
     1230
     1231    // 3 cases:
     1232    // -separator length == 1, 8 bits
     1233    // -separator length == 1, 16 bits
     1234    // -separator length > 1
     1235    StringImpl* stringImpl = input.impl();
     1236    StringImpl* separatorImpl = separator.impl();
     1237    size_t separatorLength = separatorImpl->length();
     1238
     1239    if (separatorLength == 1) {
     1240        UChar separatorCharacter;
     1241        if (separatorImpl->is8Bit())
     1242            separatorCharacter = separatorImpl->characters8()[0];
     1243        else
     1244            separatorCharacter = separatorImpl->characters16()[0];
     1245
     1246        if (stringImpl->is8Bit()) {
     1247            if (splitStringByOneCharacterImpl<LChar>(exec, result, thisValue, input, stringImpl, separatorCharacter, position, resultLength, limit))
     1248                return JSValue::encode(result);
     1249        } else {
     1250            if (splitStringByOneCharacterImpl<UChar>(exec, result, thisValue, input, stringImpl, separatorCharacter, position, resultLength, limit))
     1251                return JSValue::encode(result);
    12061252        }
    1207 
    1208         // 12. If s == 0, then
    1209         if (input.isEmpty()) {
    1210             // a. Let z be SplitMatch(S, 0, R) where S is input, R is separator.
    1211             // b. If z is not false, return A.
    1212             // c. Call CreateDataProperty(A, "0", S).
    1213             // d. Return A.
    1214             if (!separator.isEmpty())
    1215                 result->putDirectIndex(exec, 0, jsStringWithReuse(exec, thisValue, input));
    1216             return JSValue::encode(result);
     1253    } else {
     1254        // 13. Let q = p.
     1255        size_t matchPosition;
     1256        // 14. Repeat, while q != s
     1257        //   a. let e be SplitMatch(S, q, R).
     1258        //   b. If e is failure, then let q = q+1.
     1259        //   c. Else, e is an integer index <= s.
     1260        while ((matchPosition = stringImpl->find(separatorImpl, position)) != notFound) {
     1261            // 1. Let T be a String value equal to the substring of S consisting of the characters at positions p (inclusive)
     1262            //    through q (exclusive).
     1263            // 2. Call CreateDataProperty(A, ToString(lengthA), T).
     1264            result->putDirectIndex(exec, resultLength, jsSubstring(exec, thisValue, input, position, matchPosition - position));
     1265            // 3. Increment lengthA by 1.
     1266            // 4. If lengthA == lim, return A.
     1267            if (++resultLength == limit)
     1268                return JSValue::encode(result);
     1269
     1270            // 5. Let p = e.
     1271            // 6. Let q = p.
     1272            position = matchPosition + separator.length();
    12171273        }
    1218 
    1219         // Optimized case for splitting on the empty string.
    1220         if (separator.isEmpty()) {
    1221             limit = std::min(limit, input.length());
    1222             // Zero limt/input length handled in steps 9/11 respectively, above.
    1223             ASSERT(limit);
    1224 
    1225             do {
    1226                 result->putDirectIndex(exec, position, jsSingleCharacterString(exec, input[position]));
    1227             } while (++position < limit);
    1228 
    1229             return JSValue::encode(result);
    1230         }
    1231 
    1232         // 3 cases:
    1233         // -separator length == 1, 8 bits
    1234         // -separator length == 1, 16 bits
    1235         // -separator length > 1
    1236         StringImpl* stringImpl = input.impl();
    1237         StringImpl* separatorImpl = separator.impl();
    1238         size_t separatorLength = separatorImpl->length();
    1239 
    1240         if (separatorLength == 1) {
    1241             UChar separatorCharacter;
    1242             if (separatorImpl->is8Bit())
    1243                 separatorCharacter = separatorImpl->characters8()[0];
    1244             else
    1245                 separatorCharacter = separatorImpl->characters16()[0];
    1246 
    1247             if (stringImpl->is8Bit()) {
    1248                 if (splitStringByOneCharacterImpl<LChar>(exec, result, thisValue, input, stringImpl, separatorCharacter, position, resultLength, limit))
    1249                     return JSValue::encode(result);
    1250             } else {
    1251                 if (splitStringByOneCharacterImpl<UChar>(exec, result, thisValue, input, stringImpl, separatorCharacter, position, resultLength, limit))
    1252                     return JSValue::encode(result);
    1253             }
    1254         } else {
    1255             // 13. Let q = p.
    1256             size_t matchPosition;
    1257             // 14. Repeat, while q != s
    1258             //   a. let e be SplitMatch(S, q, R).
    1259             //   b. If e is failure, then let q = q+1.
    1260             //   c. Else, e is an integer index <= s.
    1261             while ((matchPosition = stringImpl->find(separatorImpl, position)) != notFound) {
    1262                 // 1. Let T be a String value equal to the substring of S consisting of the characters at positions p (inclusive)
    1263                 //    through q (exclusive).
    1264                 // 2. Call CreateDataProperty(A, ToString(lengthA), T).
    1265                 result->putDirectIndex(exec, resultLength, jsSubstring(exec, thisValue, input, position, matchPosition - position));
    1266                 // 3. Increment lengthA by 1.
    1267                 // 4. If lengthA == lim, return A.
    1268                 if (++resultLength == limit)
    1269                     return JSValue::encode(result);
    1270 
    1271                 // 5. Let p = e.
    1272                 // 6. Let q = p.
    1273                 position = matchPosition + separator.length();
    1274             }
    1275         }
    1276     } // FIXME: Keeping this indentation here to minimize the diff. Will unindent and remove this later.
     1274    }
    12771275
    12781276    // 15. Let T be a String value equal to the substring of S consisting of the characters at positions p (inclusive)
Note: See TracChangeset for help on using the changeset viewer.