mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 19:28:12 +00:00
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.
This commit is contained in:
parent
31515a9147
commit
f912a48315
23 changed files with 111 additions and 82 deletions
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue