Define AtomString(ASCIILiteral) and use ASCIILiteral more to avoid memory allocation
https://bugs.webkit.org/show_bug.cgi?id=224125
Reviewed by Saam Barati.
Source/WebCore:
We apply "..."_s more. This avoids allocating of string storage when creating StringImpl.
* accessibility/AccessibilityObject.cpp:
(WebCore::initializeRoleMap):
* dom/ScriptElement.cpp:
(WebCore::isLegacySupportedJavaScriptLanguage):
* editing/EditorCommand.cpp:
(WebCore::createCommandMap):
* html/Autofill.cpp:
(WebCore::fieldNameMap):
* platform/LegacySchemeRegistry.cpp:
(WebCore::builtinLocalURLSchemes):
(WebCore::builtinSecureSchemes):
(WebCore::builtinSchemesWithUniqueOrigins):
(WebCore::builtinEmptyDocumentSchemes):
(WebCore::builtinCanDisplayOnlyIfCanRequestSchemes):
(WebCore::builtinCORSEnabledSchemes):
* platform/MIMETypeRegistry.cpp:
(WebCore::MIMETypeRegistry::systemPreviewMIMETypes):
* platform/graphics/FontCascade.cpp:
(WebCore::FontCascade::hasValidAverageCharWidth const):
* platform/graphics/HEVCUtilities.cpp:
(WebCore::codecStringForDoViCodecType):
(WebCore::profileIDForAlphabeticDoViProfile):
* platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.cpp:
(WebCore::MediaPlayerPrivateAVFoundation::staticMIMETypeList):
* platform/graphics/avfoundation/objc/AVAssetMIMETypeCache.mm:
(WebCore::AVAssetMIMETypeCache::staticContainerTypeList):
* platform/graphics/cg/ImageSourceCGWin.cpp:
(WebCore::preferredExtensionForImageType):
* svg/SVGTests.cpp:
(WebCore::supportedSVGFeatures):
Source/WTF:
Add AtomString(ASCIILiteral). ASCIILiteral ensures that storage is constant non-heap string by its type.
So we can just use it as a literal (not allocating a string storage).
* wtf/text/AtomString.h:
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@275457 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/WebCore/platform/LegacySchemeRegistry.cpp b/Source/WebCore/platform/LegacySchemeRegistry.cpp
index b73d06a..c3f7560 100644
--- a/Source/WebCore/platform/LegacySchemeRegistry.cpp
+++ b/Source/WebCore/platform/LegacySchemeRegistry.cpp
@@ -113,9 +113,9 @@
{
ASSERT(schemeRegistryLock.isHeld());
static const auto schemes = makeNeverDestroyed(URLSchemesMap {
- "file",
+ "file"_s,
#if PLATFORM(COCOA)
- "applewebdata",
+ "applewebdata"_s,
#endif
});
return schemes;
@@ -139,12 +139,12 @@
{
ASSERT(schemeRegistryLock.isHeld());
static const auto schemes = makeNeverDestroyed(Vector<String> {
- "https",
- "about",
- "data",
- "wss",
+ "https"_s,
+ "about"_s,
+ "data"_s,
+ "wss"_s,
#if PLATFORM(GTK) || PLATFORM(WPE)
- "resource",
+ "resource"_s,
#endif
});
return schemes;
@@ -161,11 +161,11 @@
{
ASSERT(schemeRegistryLock.isHeld());
static const auto schemes = makeNeverDestroyed(Vector<String> {
- "about",
- "javascript",
+ "about"_s,
+ "javascript"_s,
// This is an intentional difference from the behavior the HTML specification calls for.
// See https://bugs.webkit.org/show_bug.cgi?id=11885
- "data",
+ "data"_s,
});
return schemes;
}
@@ -180,7 +180,7 @@
const Vector<String>& builtinEmptyDocumentSchemes()
{
ASSERT(isMainThread());
- static const auto schemes = makeNeverDestroyed(Vector<String> { "about" });
+ static const auto schemes = makeNeverDestroyed(Vector<String> { "about"_s });
return schemes;
}
@@ -201,7 +201,7 @@
const Vector<String>& builtinCanDisplayOnlyIfCanRequestSchemes()
{
ASSERT(schemeRegistryLock.isHeld());
- static const auto schemes = makeNeverDestroyed(Vector<String> { "blob" });
+ static const auto schemes = makeNeverDestroyed(Vector<String> { "blob"_s });
return schemes;
}
@@ -267,7 +267,7 @@
const Vector<String>& builtinCORSEnabledSchemes()
{
ASSERT(isMainThread());
- static const auto schemes = makeNeverDestroyed(Vector<String> { "http", "https" });
+ static const auto schemes = makeNeverDestroyed(Vector<String> { "http"_s, "https"_s });
return schemes;
}
diff --git a/Source/WebCore/platform/MIMETypeRegistry.cpp b/Source/WebCore/platform/MIMETypeRegistry.cpp
index 68f1d29..2b0d8ab 100644
--- a/Source/WebCore/platform/MIMETypeRegistry.cpp
+++ b/Source/WebCore/platform/MIMETypeRegistry.cpp
@@ -685,12 +685,12 @@
{
static NeverDestroyed<HashSet<String, ASCIICaseInsensitiveHash>> systemPreviewMIMETypes = std::initializer_list<String> {
// The official type: https://www.iana.org/assignments/media-types/model/vnd.usdz+zip
- "model/vnd.usdz+zip",
+ "model/vnd.usdz+zip"_s,
// Unofficial, but supported because we documented them.
- "model/usd",
- "model/vnd.pixar.usd",
+ "model/usd"_s,
+ "model/vnd.pixar.usd"_s,
// Reality files.
- "model/vnd.reality"
+ "model/vnd.reality"_s,
};
return systemPreviewMIMETypes;
}
diff --git a/Source/WebCore/platform/graphics/FontCascade.cpp b/Source/WebCore/platform/graphics/FontCascade.cpp
index a6a8a06..2cc3b3b 100644
--- a/Source/WebCore/platform/graphics/FontCascade.cpp
+++ b/Source/WebCore/platform/graphics/FontCascade.cpp
@@ -384,40 +384,40 @@
#endif
static const auto map = makeNeverDestroyed(MemoryCompactLookupOnlyRobinHoodHashSet<AtomString> {
- "American Typewriter",
- "Arial Hebrew",
- "Chalkboard",
- "Cochin",
- "Corsiva Hebrew",
- "Courier",
- "Euphemia UCAS",
- "Geneva",
- "Gill Sans",
- "Hei",
- "Helvetica",
- "Hoefler Text",
- "InaiMathi",
- "Kai",
- "Lucida Grande",
- "Marker Felt",
- "Monaco",
- "Mshtakan",
- "New Peninim MT",
- "Osaka",
- "Raanana",
- "STHeiti",
- "Symbol",
- "Times",
- "Apple Braille",
- "Apple LiGothic",
- "Apple LiSung",
- "Apple Symbols",
- "AppleGothic",
- "AppleMyungjo",
- "#GungSeo",
- "#HeadLineA",
- "#PCMyungjo",
- "#PilGi",
+ "American Typewriter"_s,
+ "Arial Hebrew"_s,
+ "Chalkboard"_s,
+ "Cochin"_s,
+ "Corsiva Hebrew"_s,
+ "Courier"_s,
+ "Euphemia UCAS"_s,
+ "Geneva"_s,
+ "Gill Sans"_s,
+ "Hei"_s,
+ "Helvetica"_s,
+ "Hoefler Text"_s,
+ "InaiMathi"_s,
+ "Kai"_s,
+ "Lucida Grande"_s,
+ "Marker Felt"_s,
+ "Monaco"_s,
+ "Mshtakan"_s,
+ "New Peninim MT"_s,
+ "Osaka"_s,
+ "Raanana"_s,
+ "STHeiti"_s,
+ "Symbol"_s,
+ "Times"_s,
+ "Apple Braille"_s,
+ "Apple LiGothic"_s,
+ "Apple LiSung"_s,
+ "Apple Symbols"_s,
+ "AppleGothic"_s,
+ "AppleMyungjo"_s,
+ "#GungSeo"_s,
+ "#HeadLineA"_s,
+ "#PCMyungjo"_s,
+ "#PilGi"_s,
});
return !map.get().contains(family);
}
diff --git a/Source/WebCore/platform/graphics/HEVCUtilities.cpp b/Source/WebCore/platform/graphics/HEVCUtilities.cpp
index 3995249..3382b31 100644
--- a/Source/WebCore/platform/graphics/HEVCUtilities.cpp
+++ b/Source/WebCore/platform/graphics/HEVCUtilities.cpp
@@ -26,9 +26,9 @@
#include "config.h"
#include "HEVCUtilities.h"
-#include <wtf/HashMap.h>
-#include <wtf/HashSet.h>
#include <wtf/NeverDestroyed.h>
+#include <wtf/RobinHoodHashMap.h>
+#include <wtf/RobinHoodHashSet.h>
#include <wtf/text/StringHash.h>
#include <wtf/text/StringToIntegerConversion.h>
@@ -116,12 +116,12 @@
static String codecStringForDoViCodecType(const String& codec)
{
- using MapType = HashMap<String, String>;
+ using MapType = MemoryCompactLookupOnlyRobinHoodHashMap<String, String>;
static NeverDestroyed<MapType> types = std::initializer_list<MapType::KeyValuePairType>({
- { "dvhe", "hev1" },
- { "dvh1", "hvc1" },
- { "dvav", "avc3" },
- { "dva1", "avc1" }
+ { "dvhe"_s, "hev1"_s },
+ { "dvh1"_s, "hvc1"_s },
+ { "dvav"_s, "avc3"_s },
+ { "dva1"_s, "avc1"_s }
});
auto findResults = types.get().find(codec);
@@ -133,13 +133,13 @@
static Optional<unsigned short> profileIDForAlphabeticDoViProfile(const String& profile)
{
// See Table 7 of "Dolby Vision Profiles and Levels Version 1.3.2"
- using MapType = HashMap<String, unsigned short>;
+ using MapType = MemoryCompactLookupOnlyRobinHoodHashMap<String, unsigned short>;
static NeverDestroyed<MapType> map = std::initializer_list<MapType::KeyValuePairType>({
- { "dvhe.dtr", 4 },
- { "dvhe.stn", 5 },
- { "dvhe.dtb", 7 },
- { "dvhe.st", 8 },
- { "dvav.se", 9 }
+ { "dvhe.dtr"_s, 4 },
+ { "dvhe.stn"_s, 5 },
+ { "dvhe.dtb"_s, 7 },
+ { "dvhe.st"_s, 8 },
+ { "dvav.se"_s, 9 }
});
auto findResults = map.get().find(profile);
diff --git a/Source/WebCore/platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.cpp b/Source/WebCore/platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.cpp
index b884509..ef5300b 100644
--- a/Source/WebCore/platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.cpp
+++ b/Source/WebCore/platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.cpp
@@ -1065,37 +1065,37 @@
const HashSet<String, ASCIICaseInsensitiveHash>& MediaPlayerPrivateAVFoundation::staticMIMETypeList()
{
static const auto cache = makeNeverDestroyed(HashSet<String, ASCIICaseInsensitiveHash> {
- "application/vnd.apple.mpegurl",
- "application/x-mpegurl",
- "audio/3gpp",
- "audio/aac",
- "audio/aacp",
- "audio/aiff",
- "audio/basic",
- "audio/mp3",
- "audio/mp4",
- "audio/mpeg",
- "audio/mpeg3",
- "audio/mpegurl",
- "audio/mpg",
- "audio/vnd.wave",
- "audio/wav",
- "audio/wave",
- "audio/x-aac",
- "audio/x-aiff",
- "audio/x-m4a",
- "audio/x-mpegurl",
- "audio/x-wav",
- "video/3gpp",
- "video/3gpp2",
- "video/mp4",
- "video/mpeg",
- "video/mpeg2",
- "video/mpg",
- "video/quicktime",
- "video/x-m4v",
- "video/x-mpeg",
- "video/x-mpg",
+ "application/vnd.apple.mpegurl"_s,
+ "application/x-mpegurl"_s,
+ "audio/3gpp"_s,
+ "audio/aac"_s,
+ "audio/aacp"_s,
+ "audio/aiff"_s,
+ "audio/basic"_s,
+ "audio/mp3"_s,
+ "audio/mp4"_s,
+ "audio/mpeg"_s,
+ "audio/mpeg3"_s,
+ "audio/mpegurl"_s,
+ "audio/mpg"_s,
+ "audio/vnd.wave"_s,
+ "audio/wav"_s,
+ "audio/wave"_s,
+ "audio/x-aac"_s,
+ "audio/x-aiff"_s,
+ "audio/x-m4a"_s,
+ "audio/x-mpegurl"_s,
+ "audio/x-wav"_s,
+ "video/3gpp"_s,
+ "video/3gpp2"_s,
+ "video/mp4"_s,
+ "video/mpeg"_s,
+ "video/mpeg2"_s,
+ "video/mpg"_s,
+ "video/quicktime"_s,
+ "video/x-m4v"_s,
+ "video/x-mpeg"_s,
+ "video/x-mpg"_s,
});
return cache;
}
diff --git a/Source/WebCore/platform/graphics/avfoundation/objc/AVAssetMIMETypeCache.mm b/Source/WebCore/platform/graphics/avfoundation/objc/AVAssetMIMETypeCache.mm
index 6ee5a98..22237ee 100644
--- a/Source/WebCore/platform/graphics/avfoundation/objc/AVAssetMIMETypeCache.mm
+++ b/Source/WebCore/platform/graphics/avfoundation/objc/AVAssetMIMETypeCache.mm
@@ -95,37 +95,37 @@
const HashSet<String, ASCIICaseInsensitiveHash>& AVAssetMIMETypeCache::staticContainerTypeList()
{
static const auto cache = makeNeverDestroyed(HashSet<String, ASCIICaseInsensitiveHash> {
- "application/vnd.apple.mpegurl",
- "application/x-mpegurl",
- "audio/3gpp",
- "audio/aac",
- "audio/aacp",
- "audio/aiff",
- "audio/basic",
- "audio/mp3",
- "audio/mp4",
- "audio/mpeg",
- "audio/mpeg3",
- "audio/mpegurl",
- "audio/mpg",
- "audio/vnd.wave",
- "audio/wav",
- "audio/wave",
- "audio/x-aac",
- "audio/x-aiff",
- "audio/x-m4a",
- "audio/x-mpegurl",
- "audio/x-wav",
- "video/3gpp",
- "video/3gpp2",
- "video/mp4",
- "video/mpeg",
- "video/mpeg2",
- "video/mpg",
- "video/quicktime",
- "video/x-m4v",
- "video/x-mpeg",
- "video/x-mpg",
+ "application/vnd.apple.mpegurl"_s,
+ "application/x-mpegurl"_s,
+ "audio/3gpp"_s,
+ "audio/aac"_s,
+ "audio/aacp"_s,
+ "audio/aiff"_s,
+ "audio/basic"_s,
+ "audio/mp3"_s,
+ "audio/mp4"_s,
+ "audio/mpeg"_s,
+ "audio/mpeg3"_s,
+ "audio/mpegurl"_s,
+ "audio/mpg"_s,
+ "audio/vnd.wave"_s,
+ "audio/wav"_s,
+ "audio/wave"_s,
+ "audio/x-aac"_s,
+ "audio/x-aiff"_s,
+ "audio/x-m4a"_s,
+ "audio/x-mpegurl"_s,
+ "audio/x-wav"_s,
+ "video/3gpp"_s,
+ "video/3gpp2"_s,
+ "video/mp4"_s,
+ "video/mpeg"_s,
+ "video/mpeg2"_s,
+ "video/mpg"_s,
+ "video/quicktime"_s,
+ "video/x-m4v"_s,
+ "video/x-mpeg"_s,
+ "video/x-mpg"_s,
});
return cache;
}
diff --git a/Source/WebCore/platform/graphics/cg/ImageSourceCGWin.cpp b/Source/WebCore/platform/graphics/cg/ImageSourceCGWin.cpp
index 5fe8252..2fc1879 100644
--- a/Source/WebCore/platform/graphics/cg/ImageSourceCGWin.cpp
+++ b/Source/WebCore/platform/graphics/cg/ImageSourceCGWin.cpp
@@ -52,31 +52,31 @@
return String();
static const auto map = makeNeverDestroyed(HashMap<String, String, ASCIICaseInsensitiveHash> {
- { "public.html", "html" },
- { "public.jpeg", "jpeg" },
- { "public.jpeg-2000", "jp2" },
- { "public.plain-text", "txt" },
- { "public.png", "png" },
- { "public.tiff", "tiff" },
- { "public.xbitmap-image", "xbm" },
- { "public.xml", "xml" },
- { "com.adobe.illustrator.ai-image", "ai" },
- { "com.adobe.pdf", "pdf" },
- { "com.adobe.photoshop-image", "psd" },
- { "com.adobe.postscript", "ps" },
- { "com.apple.icns", "icns" },
- { "com.apple.macpaint-image", "pntg" },
- { "com.apple.pict", "pict" },
- { "com.apple.quicktime-image", "qtif" },
- { "com.apple.webarchive", "webarchive" },
- { "com.compuserve.gif", "gif" },
- { "com.ilm.openexr-image", "exr" },
- { "com.kodak.flashpix-image", "fpx" },
- { "com.microsoft.bmp", "bmp" },
- { "com.microsoft.ico", "ico" },
- { "com.netscape.javascript-source", "js" },
- { "com.sgi.sgi-image", "sgi" },
- { "com.truevision.tga-image", "tga" },
+ { "public.html"_s, "html"_s },
+ { "public.jpeg"_s, "jpeg"_s },
+ { "public.jpeg-2000"_s, "jp2"_s },
+ { "public.plain-text"_s, "txt"_s },
+ { "public.png"_s, "png"_s },
+ { "public.tiff"_s, "tiff"_s },
+ { "public.xbitmap-image"_s, "xbm"_s },
+ { "public.xml"_s, "xml"_s },
+ { "com.adobe.illustrator.ai-image"_s, "ai"_s },
+ { "com.adobe.pdf"_s, "pdf"_s },
+ { "com.adobe.photoshop-image"_s, "psd"_s },
+ { "com.adobe.postscript"_s, "ps"_s },
+ { "com.apple.icns"_s, "icns"_s },
+ { "com.apple.macpaint-image"_s, "pntg"_s },
+ { "com.apple.pict"_s, "pict"_s },
+ { "com.apple.quicktime-image"_s, "qtif"_s },
+ { "com.apple.webarchive"_s, "webarchive"_s },
+ { "com.compuserve.gif"_s, "gif"_s },
+ { "com.ilm.openexr-image"_s, "exr"_s },
+ { "com.kodak.flashpix-image"_s, "fpx"_s },
+ { "com.microsoft.bmp"_s, "bmp"_s },
+ { "com.microsoft.ico"_s, "ico"_s },
+ { "com.netscape.javascript-source"_s, "js"_s },
+ { "com.sgi.sgi-image"_s, "sgi"_s },
+ { "com.truevision.tga-image"_s, "tga"_s },
});
return map.get().get(type);
}