Changeset 244694 in webkit


Ignore:
Timestamp:
Apr 26, 2019 9:51:48 AM (5 years ago)
Author:
don.olmstead@sony.com
Message:

Add WTF::findIgnoringASCIICaseWithoutLength to replace strcasestr
https://bugs.webkit.org/show_bug.cgi?id=197291

Reviewed by Konstantin Tokarev.

Source/JavaScriptCore:

Replace uses of strcasestr with WTF::findIgnoringASCIICaseWithoutLength.

  • API/tests/testapi.cpp:
  • assembler/testmasm.cpp:
  • b3/air/testair.cpp:
  • b3/testb3.cpp:
  • dfg/testdfg.cpp:
  • dynbench.cpp:

Source/WTF:

Adds an implementation of strcasestr within WTF.

  • wtf/text/StringCommon.h:

(WTF::findIgnoringASCIICaseWithoutLength):

Location:
trunk/Source
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/API/tests/testapi.cpp

    r236805 r244694  
    3737#include <wtf/NumberOfCores.h>
    3838#include <wtf/Vector.h>
     39#include <wtf/text/StringCommon.h>
    3940
    4041extern "C" int testCAPIViaCpp(const char* filter);
     
    485486    Deque<RefPtr<SharedTask<void(TestAPI&)>>> tasks;
    486487
    487 #if OS(DARWIN)
    488488    auto shouldRun = [&] (const char* testName) -> bool {
    489         return !filter || !!strcasestr(testName, filter);
     489        return !filter || WTF::findIgnoringASCIICaseWithoutLength(testName, filter) != WTF::notFound;
    490490    };
    491 #else
    492     auto shouldRun = [] (const char*) -> bool { return true; };
    493 #endif
    494491
    495492    RUN(basicSymbol());
  • trunk/Source/JavaScriptCore/ChangeLog

    r244676 r244694  
     12019-04-26  Don Olmstead  <don.olmstead@sony.com>
     2
     3        Add WTF::findIgnoringASCIICaseWithoutLength to replace strcasestr
     4        https://bugs.webkit.org/show_bug.cgi?id=197291
     5
     6        Reviewed by Konstantin Tokarev.
     7
     8        Replace uses of strcasestr with WTF::findIgnoringASCIICaseWithoutLength.
     9
     10        * API/tests/testapi.cpp:
     11        * assembler/testmasm.cpp:
     12        * b3/air/testair.cpp:
     13        * b3/testb3.cpp:
     14        * dfg/testdfg.cpp:
     15        * dynbench.cpp:
     16
    1172019-04-25  Fujii Hironori  <Hironori.Fujii@sony.com>
    218
  • trunk/Source/JavaScriptCore/assembler/testmasm.cpp

    r242109 r244694  
    4141#include <wtf/NumberOfCores.h>
    4242#include <wtf/Threading.h>
     43#include <wtf/text/StringCommon.h>
    4344
    4445// We don't have a NO_RETURN_DUE_TO_EXIT, nor should we. That's ridiculous.
     
    956957
    957958    auto shouldRun = [&] (const char* testName) -> bool {
    958 #if OS(UNIX)
    959         return !filter || !!strcasestr(testName, filter);
    960 #else
    961         return !filter || !!strstr(testName, filter);
    962 #endif
     959        return !filter || WTF::findIgnoringASCIICaseWithoutLength(testName, filter) != WTF::notFound;
    963960    };
    964961
  • trunk/Source/JavaScriptCore/b3/air/testair.cpp

    r242068 r244694  
    4646#include <wtf/StdMap.h>
    4747#include <wtf/Threading.h>
     48#include <wtf/text/StringCommon.h>
    4849
    4950// We don't have a NO_RETURN_DUE_TO_EXIT, nor should we. That's ridiculous.
     
    20822083
    20832084    auto shouldRun = [&] (const char* testName) -> bool {
    2084         return !filter || !!strcasestr(testName, filter);
     2085        return !filter || WTF::findIgnoringASCIICaseWithoutLength(testName, filter) != WTF::notFound;
    20852086    };
    20862087
  • trunk/Source/JavaScriptCore/b3/testb3.cpp

    r244309 r244694  
    7979#include <wtf/StdList.h>
    8080#include <wtf/Threading.h>
     81#include <wtf/text/StringCommon.h>
    8182
    8283// We don't have a NO_RETURN_DUE_TO_EXIT, nor should we. That's ridiculous.
     
    1715717158
    1715817159    auto shouldRun = [&] (const char* testName) -> bool {
    17159         return !filter || !!strcasestr(testName, filter);
     17160        return !filter || WTF::findIgnoringASCIICaseWithoutLength(testName, filter) != WTF::notFound;
    1716017161    };
    1716117162
  • trunk/Source/JavaScriptCore/dfg/testdfg.cpp

    r243278 r244694  
    3232#include "InitializeThreading.h"
    3333#include <wtf/DataLog.h>
     34#include <wtf/text/StringCommon.h>
    3435
    3536// We don't have a NO_RETURN_DUE_TO_EXIT, nor should we. That's ridiculous.
     
    8182{
    8283    auto shouldRun = [&] (const char* testName) -> bool {
    83         return !filter || !!strcasestr(testName, filter);
     84        return !filter || WTF::findIgnoringASCIICaseWithoutLength(testName, filter) != WTF::notFound;
    8485    };
    8586
  • trunk/Source/JavaScriptCore/dynbench.cpp

    r230303 r244694  
    3535#include "VM.h"
    3636#include <wtf/MainThread.h>
     37#include <wtf/text/StringCommon.h>
    3738
    3839using namespace JSC;
     
    5556NEVER_INLINE void benchmarkImpl(const char* name, unsigned iterationCount, const Callback& callback)
    5657{
    57     if (nameFilter && !strcasestr(name, nameFilter))
     58    if (nameFilter && WTF::findIgnoringASCIICaseWithoutLength(name, nameFilter) == WTF::notFound)
    5859        return;
    5960
  • trunk/Source/WTF/ChangeLog

    r244687 r244694  
     12019-04-26  Don Olmstead  <don.olmstead@sony.com>
     2
     3        Add WTF::findIgnoringASCIICaseWithoutLength to replace strcasestr
     4        https://bugs.webkit.org/show_bug.cgi?id=197291
     5
     6        Reviewed by Konstantin Tokarev.
     7
     8        Adds an implementation of strcasestr within WTF.
     9
     10        * wtf/text/StringCommon.h:
     11        (WTF::findIgnoringASCIICaseWithoutLength):
     12
    1132019-04-26  Sihui Liu  <sihui_liu@apple.com>
    214
  • trunk/Source/WTF/wtf/text/StringCommon.h

    r237266 r244694  
    467467}
    468468
     469inline size_t findIgnoringASCIICaseWithoutLength(const char* source, const char* matchCharacters)
     470{
     471    unsigned searchLength = strlen(source);
     472    unsigned matchLength = strlen(matchCharacters);
     473
     474    return matchLength < searchLength ? findIgnoringASCIICase(source, matchCharacters, 0, searchLength, matchLength) : notFound;
     475}
     476
    469477template<typename StringClassA, typename StringClassB>
    470478size_t findIgnoringASCIICase(const StringClassA& source, const StringClassB& stringToFind, unsigned startOffset)
Note: See TracChangeset for help on using the changeset viewer.