Ignore:
Timestamp:
Feb 6, 2022, 11:17:26 AM (3 years ago)
Author:
[email protected]
Message:

[WTF] Make Bitmap constexpr friendly
https://bugs.webkit.org/show_bug.cgi?id=236180

Reviewed by Darin Adler.

Source/JavaScriptCore:

This patch makes Bitmap more constexpr friendly so that JSGlobalObjectFunctions's
functions can compile Bitmap as constexpr, which avoids possible race condition.

  • runtime/JSGlobalObjectFunctions.cpp:

(JSC::makeCharacterBitmap):
(JSC::JSC_DEFINE_HOST_FUNCTION):

Source/WTF:

Attach constexpr to constructor and methods if it is possible.

  • wtf/Bitmap.h:

(WTF::WordType>::set):
(WTF::WordType>::testAndSet):
(WTF::WordType>::testAndClear):
(WTF::WordType>::clear):
(WTF::WordType>::invert):
(WTF::WordType>::nextPossiblyUnset const):
(WTF::WordType>::isEmpty const):
(WTF::WordType>::isFull const):
(WTF::WordType>::merge):
(WTF::WordType>::filter):
(WTF::WordType>::exclude):
(WTF::WordType>::subsumes const):
(WTF::WordType>::mergeAndClear):
(WTF::WordType>::setAndClear):
(WTF::= const):
(WTF::=):
(WTF::WordType>::Bitmap): Deleted.

Tools:

  • TestWebKitAPI/Tests/WTF/Bitmap.cpp:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/runtime/JSGlobalObjectFunctions.cpp

    r288473 r289172  
    5353
    5454template<unsigned charactersCount>
    55 static Bitmap<256> makeCharacterBitmap(const char (&characters)[charactersCount])
     55static constexpr Bitmap<256> makeCharacterBitmap(const char (&characters)[charactersCount])
    5656{
    5757    static_assert(charactersCount > 0, "Since string literal is null terminated, characterCount is always larger than 0");
     
    545545JSC_DEFINE_HOST_FUNCTION(globalFuncDecodeURI, (JSGlobalObject* globalObject, CallFrame* callFrame))
    546546{
    547     static const Bitmap<256> doNotUnescapeWhenDecodingURI = makeCharacterBitmap(
     547    static constexpr auto doNotUnescapeWhenDecodingURI = makeCharacterBitmap(
    548548        "#$&+,/:;=?@"
    549549    );
     
    554554JSC_DEFINE_HOST_FUNCTION(globalFuncDecodeURIComponent, (JSGlobalObject* globalObject, CallFrame* callFrame))
    555555{
    556     static const Bitmap<256> emptyBitmap;
     556    static constexpr auto emptyBitmap;
    557557    return JSValue::encode(decode(globalObject, callFrame->argument(0), emptyBitmap, true));
    558558}
     
    560560JSC_DEFINE_HOST_FUNCTION(globalFuncEncodeURI, (JSGlobalObject* globalObject, CallFrame* callFrame))
    561561{
    562     static const Bitmap<256> doNotEscapeWhenEncodingURI = makeCharacterBitmap(
     562    static constexpr auto doNotEscapeWhenEncodingURI = makeCharacterBitmap(
    563563        "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    564564        "abcdefghijklmnopqrstuvwxyz"
     
    571571JSC_DEFINE_HOST_FUNCTION(globalFuncEncodeURIComponent, (JSGlobalObject* globalObject, CallFrame* callFrame))
    572572{
    573     static const Bitmap<256> doNotEscapeWhenEncodingURIComponent = makeCharacterBitmap(
     573    static constexpr auto doNotEscapeWhenEncodingURIComponent = makeCharacterBitmap(
    574574        "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    575575        "abcdefghijklmnopqrstuvwxyz"
     
    583583{
    584584    return JSValue::encode(toStringView(globalObject, callFrame->argument(0), [&] (StringView view) -> JSString* {
    585         static const Bitmap<256> doNotEscape = makeCharacterBitmap(
     585        static constexpr auto doNotEscape = makeCharacterBitmap(
    586586            "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    587587            "abcdefghijklmnopqrstuvwxyz"
Note: See TracChangeset for help on using the changeset viewer.