summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibGfx
diff options
context:
space:
mode:
authorLenny Maiorani <lenny@serenityos.org>2022-03-13 16:09:41 -0600
committerAndreas Kling <kling@serenityos.org>2022-03-18 19:58:57 +0100
commitf912a48315c425ff49fb9421f58ea5bb834a96d6 (patch)
tree3a07abae47052211701d97e0246d62f162adb295 /Userland/Libraries/LibGfx
parent31515a9147459d29f871d8dedfdc9a4072a9900d (diff)
downloadserenity-f912a48315c425ff49fb9421f58ea5bb834a96d6.zip
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.
Diffstat (limited to 'Userland/Libraries/LibGfx')
-rw-r--r--Userland/Libraries/LibGfx/GIFLoader.cpp5
-rw-r--r--Userland/Libraries/LibGfx/PNGLoader.cpp6
2 files changed, 7 insertions, 4 deletions
diff --git a/Userland/Libraries/LibGfx/GIFLoader.cpp b/Userland/Libraries/LibGfx/GIFLoader.cpp
index 10708a04b8..9943eaf719 100644
--- a/Userland/Libraries/LibGfx/GIFLoader.cpp
+++ b/Userland/Libraries/LibGfx/GIFLoader.cpp
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
+ * Copyright (c) 2022, the SerenityOS developers.
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@@ -16,8 +17,8 @@
namespace Gfx {
// Row strides and offsets for each interlace pass.
-static const int INTERLACE_ROW_STRIDES[] = { 8, 8, 4, 2 };
-static const int INTERLACE_ROW_OFFSETS[] = { 0, 4, 2, 1 };
+static constexpr Array<int, 4> INTERLACE_ROW_STRIDES = { 8, 8, 4, 2 };
+static constexpr Array<int, 4> INTERLACE_ROW_OFFSETS = { 0, 4, 2, 1 };
struct GIFImageDescriptor {
u16 x { 0 };
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 <kling@serenityos.org>
+ * Copyright (c) 2022, the SerenityOS developers.
*
* SPDX-License-Identifier: BSD-2-Clause
*/
+#include <AK/Array.h>
#include <AK/Debug.h>
#include <AK/Endian.h>
#include <AK/Vector.h>
@@ -17,7 +19,7 @@
namespace Gfx {
-static const u8 png_header[8] = { 0x89, 'P', 'N', 'G', 13, 10, 26, 10 };
+static constexpr Array<u8, 8> png_header = { 0x89, 'P', 'N', 'G', 13, 10, 26, 10 };
struct PNG_IHDR {
NetworkOrdered<u32> 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;