From f912a48315c425ff49fb9421f58ea5bb834a96d6 Mon Sep 17 00:00:00 2001 From: Lenny Maiorani Date: Sun, 13 Mar 2022 16:09:41 -0600 Subject: Userland: Change static const variables to static constexpr `static const` variables can be computed and initialized at run-time during initialization or the first time a function is called. Change them to `static constexpr` to ensure they are computed at compile-time. This allows some removal of `strlen` because the length of the `StringView` can be used which is pre-computed at compile-time. --- Userland/Libraries/LibGfx/PNGLoader.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'Userland/Libraries/LibGfx/PNGLoader.cpp') diff --git a/Userland/Libraries/LibGfx/PNGLoader.cpp b/Userland/Libraries/LibGfx/PNGLoader.cpp index e95f8edc02..12237b5793 100644 --- a/Userland/Libraries/LibGfx/PNGLoader.cpp +++ b/Userland/Libraries/LibGfx/PNGLoader.cpp @@ -1,9 +1,11 @@ /* * Copyright (c) 2018-2020, Andreas Kling + * Copyright (c) 2022, the SerenityOS developers. * * SPDX-License-Identifier: BSD-2-Clause */ +#include #include #include #include @@ -17,7 +19,7 @@ namespace Gfx { -static const u8 png_header[8] = { 0x89, 'P', 'N', 'G', 13, 10, 26, 10 }; +static constexpr Array png_header = { 0x89, 'P', 'N', 'G', 13, 10, 26, 10 }; struct PNG_IHDR { NetworkOrdered width; @@ -516,7 +518,7 @@ static bool decode_png_header(PNGLoadingContext& context) return false; } - if (memcmp(context.data, png_header, sizeof(png_header)) != 0) { + if (memcmp(context.data, png_header.span().data(), sizeof(png_header)) != 0) { dbgln_if(PNG_DEBUG, "Invalid PNG header"); context.state = PNGLoadingContext::State::Error; return false; -- cgit v1.2.3