From 66bd7cdb28d54669c2c1bfed188e8d263827d00a Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Fri, 21 Apr 2023 08:32:02 -0400 Subject: [PATCH] LibGfx: Move two globals into the only functions that use them No real behavior change. (The two globals are now both initialized at first use instead of before main(), but that should have no observable effect. The motivation is readability.) --- .../LibGfx/ImageFormats/ImageDecoder.cpp | 58 +++++++++---------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/Userland/Libraries/LibGfx/ImageFormats/ImageDecoder.cpp b/Userland/Libraries/LibGfx/ImageFormats/ImageDecoder.cpp index b8a8ff4207..3494840b31 100644 --- a/Userland/Libraries/LibGfx/ImageFormats/ImageDecoder.cpp +++ b/Userland/Libraries/LibGfx/ImageFormats/ImageDecoder.cpp @@ -21,37 +21,27 @@ namespace Gfx { -struct ImagePluginInitializer { - bool (*sniff)(ReadonlyBytes) = nullptr; - ErrorOr> (*create)(ReadonlyBytes) = nullptr; -}; - -static constexpr ImagePluginInitializer s_initializers[] = { - { PNGImageDecoderPlugin::sniff, PNGImageDecoderPlugin::create }, - { GIFImageDecoderPlugin::sniff, GIFImageDecoderPlugin::create }, - { BMPImageDecoderPlugin::sniff, BMPImageDecoderPlugin::create }, - { PBMImageDecoderPlugin::sniff, PBMImageDecoderPlugin::create }, - { PGMImageDecoderPlugin::sniff, PGMImageDecoderPlugin::create }, - { PPMImageDecoderPlugin::sniff, PPMImageDecoderPlugin::create }, - { ICOImageDecoderPlugin::sniff, ICOImageDecoderPlugin::create }, - { JPEGImageDecoderPlugin::sniff, JPEGImageDecoderPlugin::create }, - { DDSImageDecoderPlugin::sniff, DDSImageDecoderPlugin::create }, - { QOIImageDecoderPlugin::sniff, QOIImageDecoderPlugin::create }, - { WebPImageDecoderPlugin::sniff, WebPImageDecoderPlugin::create }, -}; - -struct ImagePluginWithMIMETypeInitializer { - ErrorOr (*validate_before_create)(ReadonlyBytes) = nullptr; - ErrorOr> (*create)(ReadonlyBytes) = nullptr; - StringView mime_type; -}; - -static constexpr ImagePluginWithMIMETypeInitializer s_initializers_with_mime_type[] = { - { TGAImageDecoderPlugin::validate_before_create, TGAImageDecoderPlugin::create, "image/x-targa"sv }, -}; - static OwnPtr probe_and_sniff_for_appropriate_plugin(ReadonlyBytes bytes) { + struct ImagePluginInitializer { + bool (*sniff)(ReadonlyBytes) = nullptr; + ErrorOr> (*create)(ReadonlyBytes) = nullptr; + }; + + static constexpr ImagePluginInitializer s_initializers[] = { + { PNGImageDecoderPlugin::sniff, PNGImageDecoderPlugin::create }, + { GIFImageDecoderPlugin::sniff, GIFImageDecoderPlugin::create }, + { BMPImageDecoderPlugin::sniff, BMPImageDecoderPlugin::create }, + { PBMImageDecoderPlugin::sniff, PBMImageDecoderPlugin::create }, + { PGMImageDecoderPlugin::sniff, PGMImageDecoderPlugin::create }, + { PPMImageDecoderPlugin::sniff, PPMImageDecoderPlugin::create }, + { ICOImageDecoderPlugin::sniff, ICOImageDecoderPlugin::create }, + { JPEGImageDecoderPlugin::sniff, JPEGImageDecoderPlugin::create }, + { DDSImageDecoderPlugin::sniff, DDSImageDecoderPlugin::create }, + { QOIImageDecoderPlugin::sniff, QOIImageDecoderPlugin::create }, + { WebPImageDecoderPlugin::sniff, WebPImageDecoderPlugin::create }, + }; + for (auto& plugin : s_initializers) { auto sniff_result = plugin.sniff(bytes); if (!sniff_result) @@ -65,6 +55,16 @@ static OwnPtr probe_and_sniff_for_appropriate_plugin(Readonl static OwnPtr probe_and_sniff_for_appropriate_plugin_with_known_mime_type(StringView mime_type, ReadonlyBytes bytes) { + struct ImagePluginWithMIMETypeInitializer { + ErrorOr (*validate_before_create)(ReadonlyBytes) = nullptr; + ErrorOr> (*create)(ReadonlyBytes) = nullptr; + StringView mime_type; + }; + + static constexpr ImagePluginWithMIMETypeInitializer s_initializers_with_mime_type[] = { + { TGAImageDecoderPlugin::validate_before_create, TGAImageDecoderPlugin::create, "image/x-targa"sv }, + }; + for (auto& plugin : s_initializers_with_mime_type) { if (plugin.mime_type != mime_type) continue;