Skip to content
Permalink
Browse files
Many call sites use makeNeverDestroyed, but could instead take advant…
…age of the NeverDestroyed deduction guide

https://bugs.webkit.org/show_bug.cgi?id=234350

Reviewed by Sam Weinig.

Source/WebCore:

* Modules/encryptedmedia/legacy/LegacyCDM.cpp:
(WebCore::installedCDMFactories): Use NeverDestroyed directly instead of via makeNeverDestroyed.

* Modules/mediasession/MediaSession.cpp:
(WebCore::platformCommandForMediaSessionAction): Use SortedArrayMap, obviating the need for
any use of NeverDestroyed.

* accessibility/AccessibilityRenderObject.cpp:
(WebCore::AccessibilityRenderObject::inheritsPresentationalRole const): Use Span instead of
Vector, allowing us to use constexpr arrays rather than allocating memory for a Vector.

* accessibility/mac/WebAccessibilityObjectWrapperMac.mm:
(-[WebAccessibilityObjectWrapper accessibilityAttributeNames]): Use deduction.
* dom/make_names.pl:
(printFactoryCppFile): Ditto.
(printWrapperFactoryCppFile): Ditto.

* editing/EditingStyle.cpp:
(WebCore::htmlElementEquivalents): Return a Span instead of a Vector&,
allowing us to use const arrays rather than allocating memory for a Vector.
(WebCore::htmlAttributeEquivalents): Ditto.

* editing/FormatBlockCommand.cpp:
(WebCore::isElementForFormatBlock): Use deduction.
* editing/RemoveFormatCommand.cpp:
(WebCore::isElementForRemoveFormatCommand): Ditto.

* editing/ReplaceSelectionCommand.cpp:
(WebCore::isProhibitedParagraphChild): Use deduction, also change the tags array
to be a constexpr array so we don't have to use read/write memory for it.

* editing/cocoa/HTMLConverter.mm:
(WebDefaultFont): Use deduction.
(defaultParagraphStyle): Ditto.
* html/Autofill.cpp:
(WebCore::fieldNameMap): Ditto.

* html/HTMLDocument.cpp:
(WebCore::HTMLDocument::isCaseSensitiveAttribute): Use deduction, also change
the names array to be a constexpr array so we don't have to use read/write memory for it.

* html/HTMLElement.cpp:
(WebCore::HTMLElement::eventNameForEventHandlerAttribute): Use std::array deduction
so we don't have to write out the LazyNeverDestroyed type here.

* html/HTMLObjectElement.cpp:
(WebCore::preventsParentObjectFromExposure): Use deduction.
* html/InputType.cpp:
(WebCore::InputType::create): Ditto.
* loader/ContentFilter.cpp:
(WebCore::blockedPageURL): Ditto.
* page/DebugPageOverlays.cpp:
(WebCore::touchEventRegionColors): Ditto.
* page/PerformanceUserTiming.cpp:
(WebCore::restrictedMarkNamesToNavigationTimingFunctionMap): Ditto.

* platform/LegacySchemeRegistry.cpp:
(WebCore::add): Use Span instead of Vector, allowing us to use constexpr arrays
rather thna allocating memory for a Vector.
(WebCore::makeNeverDestroyedSchemeSet): Ditto.
(WebCore::allBuiltinSchemes): Ditto. Also use deduction.
(WebCore::builtinLocalURLSchemes): Ditto.
(WebCore::builtinSecureSchemes): Ditto.
(WebCore::builtinSchemesWithUniqueOrigins): Ditto.
(WebCore::builtinEmptyDocumentSchemes): Ditto.
(WebCore::builtinCanDisplayOnlyIfCanRequestSchemes): Ditto.
(WebCore::builtinCORSEnabledSchemes): Ditto.

* platform/MIMETypeRegistry.cpp:
(WebCore::MIMETypeRegistry::supportedNonImageMIMETypes): Use deduction.
(WebCore::MIMETypeRegistry::supportedMediaMIMETypes): Ditto.

* platform/cocoa/AGXCompilerService.cpp:
(WebCore::agxCompilerServices): Use Span instead of a Vector&, allowing us
to use a constexpr array rather than allocating memory for a vector.
(WebCore::agxCompilerClasses): Ditto.
* platform/cocoa/AGXCompilerService.h: Ditto.

* platform/cocoa/MIMETypeRegistryCocoa.mm:
(WebCore::extensionsForMIMETypeMap): Use deduction.

* platform/cocoa/RemoteCommandListenerCocoa.mm:
(WebCore::mediaRemoteCommandForPlatformCommand): Use SortedArrayMap, ovbviating the
need for any use of NeverDestroyed.

* platform/cocoa/VideoFullscreenModelVideoElement.h:
* platform/cocoa/VideoFullscreenModelVideoElement.mm:
(WebCore::VideoFullscreenModelVideoElement::observedEventNames): Return a Span
instead of a Vector&, allowing us to use an array rather than allocating
memory for a Vector.

* platform/encryptedmedia/CDMProxy.cpp:
(WebCore::CDMProxyFactory::registeredFactories): Use deduction.

* platform/graphics/FontCascade.cpp:
(WebCore::useBackslashAsYenSignForFamily): Use deduction.
(WebCore::FontCascade::hasValidAverageCharWidth const): Ditto.

* platform/graphics/ImageDecoder.cpp:
(WebCore::installedFactories): Use NeverDestroyed directly, not makeNeverDestroyed.

* platform/graphics/IntSize.h: Added constexpr so many operations can be done
at compile time as needed; mainly this was so we can make a constexpr array of
these sizes. This same enhancement can be applied to other types, but just did
it here for now. Also fixed return values for min/maxDimension that were accidentally
returning float, hurting performance because of the round trip int to float,
also not cleanly round tripping very large and small values.

* platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.cpp:
(WebCore::MediaPlayerPrivateAVFoundation::staticMIMETypeList): Use deduction.
* platform/graphics/avfoundation/cf/MediaPlayerPrivateAVFoundationCF.cpp:
(WebCore::AVFWrapper::checkPlayability): Ditto.
* platform/graphics/cg/ImageSourceCGWin.cpp:
(WebCore::preferredExtensionForImageType): Ditto.
* platform/graphics/cg/UTIRegistry.cpp:
(WebCore::defaultSupportedImageTypes): Ditto.
* platform/graphics/cocoa/FontDescriptionCocoa.cpp:
(WebCore::matchSystemFontUse): Ditto.
* platform/graphics/cocoa/SourceBufferParserWebM.cpp:
(WebCore::SourceBufferParserWebM::webmMIMETypes): Ditto.
(WebCore::SourceBufferParserWebM::supportedVideoCodecs): Ditto.
(WebCore::SourceBufferParserWebM::supportedAudioCodecs): Ditto.
* platform/ios/DragImageIOS.mm:
(WebCore::createDragImageForLink): Ditto.
* platform/mac/WebNSAttributedStringExtras.mm:
(WebCore::attributedStringByStrippingAttachmentCharacters): Ditto.
* platform/mediacapabilities/MediaEngineConfigurationFactory.cpp:
(WebCore::factories): Ditto.

* platform/mediastream/RealtimeVideoCaptureSource.cpp:
(WebCore::RealtimeVideoCaptureSource::standardVideoSizes): Return a Span
instead of a Vector& so we can use a constexpr array and don't need to
allocate memory or use read/write storage.
* platform/mediastream/RealtimeVideoCaptureSource.h: Ditto. Also make
this a static member function.

* platform/mock/MockRealtimeMediaSourceCenter.cpp:
(WebCore::devices): Use deduction.
(WebCore::deviceMap): Ditto.
(WebCore::MockRealtimeMediaSourceCenter::microphoneDevices): Ditto.
(WebCore::MockRealtimeMediaSourceCenter::speakerDevices): Ditto.
(WebCore::MockRealtimeMediaSourceCenter::videoDevices): Ditto.
(WebCore::MockRealtimeMediaSourceCenter::displayDevices): Ditto.
* platform/mock/mediasource/MockMediaPlayerMediaSource.cpp:
(WebCore::mimeTypeCache): Ditto.
* platform/network/mac/ResourceHandleMac.mm:
(WebCore::operationQueueForAsyncClients): Ditto.
* platform/text/mac/TextBoundaries.mm:
(WebCore::tokenizerForString): Ditto.

* rendering/RenderTheme.cpp:
(WebCore::RenderTheme::cachedSystemFontDescription const): Use
NeverDestroyed directly instead of makeNeverDestroyed.
* rendering/RenderThemeCocoa.mm:
(WebCore::RenderThemeCocoa::cachedSystemFontDescription const): Ditto.

* svg/SVGAnimationElement.cpp:
(WebCore::SVGAnimationElement::isSupportedAttribute): Use deduction.

* svg/SVGElement.cpp:
(WebCore::createAttributeNameToCSSPropertyIDMap): Use a constexpr array
instead of a const one that has to be initialized at runtime.
(WebCore::SVGElement::animatableAttributeForName): Ditto, also use deduction.
(WebCore::SVGElement::cssPropertyIdForSVGAttributeName): Use deduction.

* svg/animation/SVGSMILElement.cpp:
(WebCore::SVGSMILElement::isSupportedAttribute): Use deduction.
* xml/XPathFunctions.cpp:
(WebCore::XPath::Function::create): Ditto.
* xml/XPathParser.cpp:
(WebCore::XPath::parseAxisName): Ditto.

Source/WebKit:

* NetworkProcess/Classifier/ResourceLoadStatisticsDatabaseStore.cpp:
(WebKit::ResourceLoadStatisticsDatabaseStore::expectedTableAndIndexQueries):
Use deduction.
* NetworkProcess/PrivateClickMeasurement/PrivateClickMeasurementDatabase.cpp:
(WebKit::PCM::Database::expectedTableAndIndexQueries): Ditto.
* Shared/Cocoa/DefaultWebBrowserChecks.mm:
(WebKit::getAppBoundDomainsTesting): Ditto.

* Shared/Cocoa/SandboxExtensionCocoa.mm:
(WebKit::createHandlesForResources): Make this more generic so it works with
other kinds of collections, not just Vector. Also right-size the Vector this
returns rather than letting it grow organically.
(WebKit::SandboxExtension::createReadOnlyHandlesForFiles): Ditto.
(WebKit::SandboxExtension::createHandleForReadWriteDirectory): Ditto.
(WebKit::SandboxExtension::createHandlesForMachLookup): Ditto. Also update this
function to take a Span or an initializer_list instead of a Vector.
(WebKit::SandboxExtension::createHandlesForIOKitClassExtensions): Ditto.
(WebKit::SandboxExtension::consumePermanently): Ditto.
* Shared/SandboxExtension.h: Updated for the above. Also corrected some unusual
use of #if to share a single declaration of some functions for both enabled
and disabled SANDBOX_EXTENSIONS.

* UIProcess/GPU/GPUProcessProxy.cpp:
(WebKit::nonBrowserServices): Use deduction.

* UIProcess/WebPageProxy.cpp: Remove unused MERGE_WHEEL_EVENTS.
(WebKit::attachmentElementServices): Return a Span, allowing us to use a
constexpr obviating the need for memory allocation or read/write memory,
(WebKit::gpuIOKitClasses): Ditto.
(WebKit::gpuMachServices): Ditto.
(WebKit::mediaRelatedMachServices): Ditto.
(WebKit::mediaRelatedIOKitClasses): Ditto.

* UIProcess/ios/TextCheckerIOS.mm:
(WebKit::mutableState): Use deduction.
* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView supportedPasteboardTypesForCurrentSelection]): Ditto.
* UIProcess/mac/TextCheckerMac.mm:
(WebKit::mutableState): Ditto.
* UIProcess/mac/WebPageProxyMac.mm:
(WebKit::temporaryPDFDirectoryPath): Ditto.

Source/WebKitLegacy/mac:

* Misc/WebNSPasteboardExtras.mm:
(writableTypesForImageWithoutArchive): Use deduction.
(writableTypesForImageWithArchive):
* Misc/WebNSURLExtras.mm:
(-[NSString _webkit_rangeOfURLScheme]): Ditto.
* WebView/WebDataSource.mm:
(+[WebDataSource _repTypesAllowImageTypeOmission:]): Ditto.
* WebView/WebFrameView.mm:
(+[WebFrameView _viewTypesAllowImageTypeOmission:]): Ditto.

Source/WTF:

* wtf/NeverDestroyed.h:
(WTF::makeNeverDestroyed): Deleted.

* wtf/text/cf/StringImplCF.cpp:
(WTF::StringWrapperCFAllocator::allocator): Use deduction guide.

Tools:

* DumpRenderTree/mac/DumpRenderTree.mm:
(fontAllowList): Use deduction.

* TestWebKitAPI/Tests/WTF/NeverDestroyed.cpp:
(TestWebKitAPI::TEST): Remove tests of makeNeverDestroyed.
(TestWebKitAPI::list): Use deduction.


Canonical link: https://commits.webkit.org/245322@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@287138 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
darinadler committed Dec 16, 2021
1 parent a09b909 commit bb166fdf5e2c4edeb03772dec231249cf6b14eca
Showing 76 changed files with 962 additions and 777 deletions.
@@ -1,3 +1,16 @@
2021-12-15 Darin Adler <darin@apple.com>

Many call sites use makeNeverDestroyed, but could instead take advantage of the NeverDestroyed deduction guide
https://bugs.webkit.org/show_bug.cgi?id=234350

Reviewed by Sam Weinig.

* wtf/NeverDestroyed.h:
(WTF::makeNeverDestroyed): Deleted.

* wtf/text/cf/StringImplCF.cpp:
(WTF::StringWrapperCFAllocator::allocator): Use deduction guide.

2021-12-15 Alex Christensen <achristensen@webkit.org>

Remove unreachable code in Plugin and PluginController
@@ -104,8 +104,6 @@ template<typename T, typename AccessTraits> class NeverDestroyed {
typename std::aligned_storage<sizeof(T), std::alignment_of<T>::value>::type m_storage;
};

template<typename T, typename AccessTraits = AnyThreadsAccessTraits> NeverDestroyed<T, AccessTraits> makeNeverDestroyed(T&&);

// FIXME: It's messy to have to repeat the whole class just to make this "lazy" version.
// Should revisit clients to see if we really need this, and perhaps use templates to
// share more of the code with the main NeverDestroyed above.
@@ -181,23 +179,14 @@ template<typename T, typename AccessTraits> class LazyNeverDestroyed {

template<typename T> NeverDestroyed(T) -> NeverDestroyed<T>;

// FIXME: Remove this function, relying instead on the deduction guide for NeverDestroyed above.
template<typename T, typename AccessTraits> inline NeverDestroyed<T, AccessTraits> makeNeverDestroyed(T&& argument)
{
return std::forward<T>(argument);
}

template<typename T>
using MainThreadNeverDestroyed = NeverDestroyed<T, MainThreadAccessTraits>;
template<typename T> using MainThreadNeverDestroyed = NeverDestroyed<T, MainThreadAccessTraits>;

template<typename T>
using MainThreadLazyNeverDestroyed = LazyNeverDestroyed<T, MainThreadAccessTraits>;
template<typename T> using MainThreadLazyNeverDestroyed = LazyNeverDestroyed<T, MainThreadAccessTraits>;

} // namespace WTF;

using WTF::LazyNeverDestroyed;
using WTF::NeverDestroyed;
using WTF::makeNeverDestroyed;
using WTF::MainThreadNeverDestroyed;
using WTF::MainThreadLazyNeverDestroyed;
using WTF::AnyThreadsAccessTraits;
@@ -106,10 +106,10 @@ namespace StringWrapperCFAllocator {

static CFAllocatorRef allocator()
{
static auto allocator = makeNeverDestroyed([] {
static NeverDestroyed allocator = [] {
CFAllocatorContext context = { 0, nullptr, retain, release, copyDescription, allocate, reallocate, deallocate, preferredSize };
return adoptCF(CFAllocatorCreate(nullptr, &context));
}());
}();
return allocator.get().get();
}

@@ -1,3 +1,182 @@
2021-12-15 Darin Adler <darin@apple.com>

Many call sites use makeNeverDestroyed, but could instead take advantage of the NeverDestroyed deduction guide
https://bugs.webkit.org/show_bug.cgi?id=234350

Reviewed by Sam Weinig.

* Modules/encryptedmedia/legacy/LegacyCDM.cpp:
(WebCore::installedCDMFactories): Use NeverDestroyed directly instead of via makeNeverDestroyed.

* Modules/mediasession/MediaSession.cpp:
(WebCore::platformCommandForMediaSessionAction): Use SortedArrayMap, obviating the need for
any use of NeverDestroyed.

* accessibility/AccessibilityRenderObject.cpp:
(WebCore::AccessibilityRenderObject::inheritsPresentationalRole const): Use Span instead of
Vector, allowing us to use constexpr arrays rather than allocating memory for a Vector.

* accessibility/mac/WebAccessibilityObjectWrapperMac.mm:
(-[WebAccessibilityObjectWrapper accessibilityAttributeNames]): Use deduction.
* dom/make_names.pl:
(printFactoryCppFile): Ditto.
(printWrapperFactoryCppFile): Ditto.

* editing/EditingStyle.cpp:
(WebCore::htmlElementEquivalents): Return a Span instead of a Vector&,
allowing us to use const arrays rather than allocating memory for a Vector.
(WebCore::htmlAttributeEquivalents): Ditto.

* editing/FormatBlockCommand.cpp:
(WebCore::isElementForFormatBlock): Use deduction.
* editing/RemoveFormatCommand.cpp:
(WebCore::isElementForRemoveFormatCommand): Ditto.

* editing/ReplaceSelectionCommand.cpp:
(WebCore::isProhibitedParagraphChild): Use deduction, also change the tags array
to be a constexpr array so we don't have to use read/write memory for it.

* editing/cocoa/HTMLConverter.mm:
(WebDefaultFont): Use deduction.
(defaultParagraphStyle): Ditto.
* html/Autofill.cpp:
(WebCore::fieldNameMap): Ditto.

* html/HTMLDocument.cpp:
(WebCore::HTMLDocument::isCaseSensitiveAttribute): Use deduction, also change
the names array to be a constexpr array so we don't have to use read/write memory for it.

* html/HTMLElement.cpp:
(WebCore::HTMLElement::eventNameForEventHandlerAttribute): Use std::array deduction
so we don't have to write out the LazyNeverDestroyed type here.

* html/HTMLObjectElement.cpp:
(WebCore::preventsParentObjectFromExposure): Use deduction.
* html/InputType.cpp:
(WebCore::InputType::create): Ditto.
* loader/ContentFilter.cpp:
(WebCore::blockedPageURL): Ditto.
* page/DebugPageOverlays.cpp:
(WebCore::touchEventRegionColors): Ditto.
* page/PerformanceUserTiming.cpp:
(WebCore::restrictedMarkNamesToNavigationTimingFunctionMap): Ditto.

* platform/LegacySchemeRegistry.cpp:
(WebCore::add): Use Span instead of Vector, allowing us to use constexpr arrays
rather thna allocating memory for a Vector.
(WebCore::makeNeverDestroyedSchemeSet): Ditto.
(WebCore::allBuiltinSchemes): Ditto. Also use deduction.
(WebCore::builtinLocalURLSchemes): Ditto.
(WebCore::builtinSecureSchemes): Ditto.
(WebCore::builtinSchemesWithUniqueOrigins): Ditto.
(WebCore::builtinEmptyDocumentSchemes): Ditto.
(WebCore::builtinCanDisplayOnlyIfCanRequestSchemes): Ditto.
(WebCore::builtinCORSEnabledSchemes): Ditto.

* platform/MIMETypeRegistry.cpp:
(WebCore::MIMETypeRegistry::supportedNonImageMIMETypes): Use deduction.
(WebCore::MIMETypeRegistry::supportedMediaMIMETypes): Ditto.

* platform/cocoa/AGXCompilerService.cpp:
(WebCore::agxCompilerServices): Use Span instead of a Vector&, allowing us
to use a constexpr array rather than allocating memory for a vector.
(WebCore::agxCompilerClasses): Ditto.
* platform/cocoa/AGXCompilerService.h: Ditto.

* platform/cocoa/MIMETypeRegistryCocoa.mm:
(WebCore::extensionsForMIMETypeMap): Use deduction.

* platform/cocoa/RemoteCommandListenerCocoa.mm:
(WebCore::mediaRemoteCommandForPlatformCommand): Use SortedArrayMap, ovbviating the
need for any use of NeverDestroyed.

* platform/cocoa/VideoFullscreenModelVideoElement.h:
* platform/cocoa/VideoFullscreenModelVideoElement.mm:
(WebCore::VideoFullscreenModelVideoElement::observedEventNames): Return a Span
instead of a Vector&, allowing us to use an array rather than allocating
memory for a Vector.

* platform/encryptedmedia/CDMProxy.cpp:
(WebCore::CDMProxyFactory::registeredFactories): Use deduction.

* platform/graphics/FontCascade.cpp:
(WebCore::useBackslashAsYenSignForFamily): Use deduction.
(WebCore::FontCascade::hasValidAverageCharWidth const): Ditto.

* platform/graphics/ImageDecoder.cpp:
(WebCore::installedFactories): Use NeverDestroyed directly, not makeNeverDestroyed.

* platform/graphics/IntSize.h: Added constexpr so many operations can be done
at compile time as needed; mainly this was so we can make a constexpr array of
these sizes. This same enhancement can be applied to other types, but just did
it here for now. Also fixed return values for min/maxDimension that were accidentally
returning float, hurting performance because of the round trip int to float,
also not cleanly round tripping very large and small values.

* platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.cpp:
(WebCore::MediaPlayerPrivateAVFoundation::staticMIMETypeList): Use deduction.
* platform/graphics/avfoundation/cf/MediaPlayerPrivateAVFoundationCF.cpp:
(WebCore::AVFWrapper::checkPlayability): Ditto.
* platform/graphics/cg/ImageSourceCGWin.cpp:
(WebCore::preferredExtensionForImageType): Ditto.
* platform/graphics/cg/UTIRegistry.cpp:
(WebCore::defaultSupportedImageTypes): Ditto.
* platform/graphics/cocoa/FontDescriptionCocoa.cpp:
(WebCore::matchSystemFontUse): Ditto.
* platform/graphics/cocoa/SourceBufferParserWebM.cpp:
(WebCore::SourceBufferParserWebM::webmMIMETypes): Ditto.
(WebCore::SourceBufferParserWebM::supportedVideoCodecs): Ditto.
(WebCore::SourceBufferParserWebM::supportedAudioCodecs): Ditto.
* platform/ios/DragImageIOS.mm:
(WebCore::createDragImageForLink): Ditto.
* platform/mac/WebNSAttributedStringExtras.mm:
(WebCore::attributedStringByStrippingAttachmentCharacters): Ditto.
* platform/mediacapabilities/MediaEngineConfigurationFactory.cpp:
(WebCore::factories): Ditto.

* platform/mediastream/RealtimeVideoCaptureSource.cpp:
(WebCore::RealtimeVideoCaptureSource::standardVideoSizes): Return a Span
instead of a Vector& so we can use a constexpr array and don't need to
allocate memory or use read/write storage.
* platform/mediastream/RealtimeVideoCaptureSource.h: Ditto. Also make
this a static member function.

* platform/mock/MockRealtimeMediaSourceCenter.cpp:
(WebCore::devices): Use deduction.
(WebCore::deviceMap): Ditto.
(WebCore::MockRealtimeMediaSourceCenter::microphoneDevices): Ditto.
(WebCore::MockRealtimeMediaSourceCenter::speakerDevices): Ditto.
(WebCore::MockRealtimeMediaSourceCenter::videoDevices): Ditto.
(WebCore::MockRealtimeMediaSourceCenter::displayDevices): Ditto.
* platform/mock/mediasource/MockMediaPlayerMediaSource.cpp:
(WebCore::mimeTypeCache): Ditto.
* platform/network/mac/ResourceHandleMac.mm:
(WebCore::operationQueueForAsyncClients): Ditto.
* platform/text/mac/TextBoundaries.mm:
(WebCore::tokenizerForString): Ditto.

* rendering/RenderTheme.cpp:
(WebCore::RenderTheme::cachedSystemFontDescription const): Use
NeverDestroyed directly instead of makeNeverDestroyed.
* rendering/RenderThemeCocoa.mm:
(WebCore::RenderThemeCocoa::cachedSystemFontDescription const): Ditto.

* svg/SVGAnimationElement.cpp:
(WebCore::SVGAnimationElement::isSupportedAttribute): Use deduction.

* svg/SVGElement.cpp:
(WebCore::createAttributeNameToCSSPropertyIDMap): Use a constexpr array
instead of a const one that has to be initialized at runtime.
(WebCore::SVGElement::animatableAttributeForName): Ditto, also use deduction.
(WebCore::SVGElement::cssPropertyIdForSVGAttributeName): Use deduction.

* svg/animation/SVGSMILElement.cpp:
(WebCore::SVGSMILElement::isSupportedAttribute): Use deduction.
* xml/XPathFunctions.cpp:
(WebCore::XPath::Function::create): Ditto.
* xml/XPathParser.cpp:
(WebCore::XPath::parseAxisName): Ditto.

2021-12-16 Michael Saboff <msaboff@apple.com>

https://bugs.webkit.org/show_bug.cgi?id=234173
@@ -61,7 +61,7 @@ static void platformRegisterFactories(Vector<LegacyCDMFactory>& factories)

static Vector<LegacyCDMFactory>& installedCDMFactories()
{
static auto cdms = makeNeverDestroyed<Vector<LegacyCDMFactory>>({ });
static NeverDestroyed<Vector<LegacyCDMFactory>> cdms;
static std::once_flag registerDefaults;
std::call_once(registerDefaults, [&] {
platformRegisterFactories(cdms);
@@ -42,6 +42,7 @@
#include "Page.h"
#include "PlatformMediaSessionManager.h"
#include <wtf/JSONValues.h>
#include <wtf/SortedArrayMap.h>

namespace WebCore {

@@ -65,27 +66,19 @@ static const char* logClassName()

static PlatformMediaSession::RemoteControlCommandType platformCommandForMediaSessionAction(MediaSessionAction action)
{
static const auto commandMap = makeNeverDestroyed([] {
using ActionToCommandMap = HashMap<MediaSessionAction, PlatformMediaSession::RemoteControlCommandType, IntHash<MediaSessionAction>, WTF::StrongEnumHashTraits<MediaSessionAction>>;

return ActionToCommandMap {
{ MediaSessionAction::Play, PlatformMediaSession::PlayCommand },
{ MediaSessionAction::Pause, PlatformMediaSession::PauseCommand },
{ MediaSessionAction::Seekforward, PlatformMediaSession::SkipForwardCommand },
{ MediaSessionAction::Seekbackward, PlatformMediaSession::SkipBackwardCommand },
{ MediaSessionAction::Previoustrack, PlatformMediaSession::PreviousTrackCommand },
{ MediaSessionAction::Nexttrack, PlatformMediaSession::NextTrackCommand },
{ MediaSessionAction::Stop, PlatformMediaSession::StopCommand },
{ MediaSessionAction::Seekto, PlatformMediaSession::SeekToPlaybackPositionCommand },
{ MediaSessionAction::Skipad, PlatformMediaSession::NextTrackCommand },
};
}());

auto it = commandMap.get().find(action);
if (it != commandMap.get().end())
return it->value;

return PlatformMediaSession::NoCommand;
static constexpr std::pair<MediaSessionAction, PlatformMediaSession::RemoteControlCommandType> mappings[] {
{ MediaSessionAction::Play, PlatformMediaSession::PlayCommand },
{ MediaSessionAction::Pause, PlatformMediaSession::PauseCommand },
{ MediaSessionAction::Seekbackward, PlatformMediaSession::SkipBackwardCommand },
{ MediaSessionAction::Seekforward, PlatformMediaSession::SkipForwardCommand },
{ MediaSessionAction::Previoustrack, PlatformMediaSession::PreviousTrackCommand },
{ MediaSessionAction::Nexttrack, PlatformMediaSession::NextTrackCommand },
{ MediaSessionAction::Skipad, PlatformMediaSession::NextTrackCommand },
{ MediaSessionAction::Stop, PlatformMediaSession::StopCommand },
{ MediaSessionAction::Seekto, PlatformMediaSession::SeekToPlaybackPositionCommand },
};
static constexpr SortedArrayMap map { mappings };
return map.get(action, PlatformMediaSession::NoCommand);
}

static std::optional<std::pair<PlatformMediaSession::RemoteControlCommandType, PlatformMediaSession::RemoteCommandArgument>> platformCommandForMediaSessionAction(const MediaSessionActionDetails& actionDetails)
@@ -3214,18 +3214,18 @@ bool AccessibilityRenderObject::inheritsPresentationalRole() const
// those child elements are also presentational. For example, <li> becomes presentational from <ul>.
// http://www.w3.org/WAI/PF/aria/complete#presentation

const Vector<const HTMLQualifiedName*>* parentTags;
Span<const LazyNeverDestroyed<const HTMLQualifiedName>* const> parentTags;
switch (roleValue()) {
case AccessibilityRole::ListItem:
case AccessibilityRole::ListMarker: {
static const auto listItemParents = makeNeverDestroyed(Vector<const HTMLQualifiedName*> { &dlTag.get(), &olTag.get(), &ulTag.get() });
parentTags = &listItemParents.get();
static constexpr std::array listItemParents { &dlTag, &olTag, &ulTag };
parentTags = listItemParents;
break;
}
case AccessibilityRole::GridCell:
case AccessibilityRole::Cell: {
static const auto tableCellParents = makeNeverDestroyed(Vector<const HTMLQualifiedName*> { &tableTag.get() });
parentTags = &tableCellParents.get();
static constexpr std::array tableCellParents { &tableTag };
parentTags = tableCellParents;
break;
}
default:
@@ -3244,7 +3244,7 @@ bool AccessibilityRenderObject::inheritsPresentationalRole() const
// If native tag of the parent element matches an acceptable name, then return
// based on its presentational status.
auto& name = downcast<Element>(*node).tagQName();
if (std::any_of(parentTags->begin(), parentTags->end(), [&name] (auto* possibleName) { return *possibleName == name; }))
if (std::any_of(parentTags.begin(), parentTags.end(), [&name] (auto* possibleName) { return possibleName->get() == name; }))
return parent->roleValue() == AccessibilityRole::Presentational;
}

0 comments on commit bb166fd

Please sign in to comment.