1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 14:48:14 +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:
Lenny Maiorani 2022-03-13 16:09:41 -06:00 committed by Andreas Kling
parent 31515a9147
commit f912a48315
23 changed files with 111 additions and 82 deletions

View file

@ -1,6 +1,7 @@
/*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2021, Mițca Dumitru <dumitru0mitca@gmail.com>
* Copyright (c) 2022, the SerenityOS developers.
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -63,11 +64,11 @@ union FloatExtractor;
// This assumes long double is 80 bits, which is true with GCC on Intel platforms
template<>
union FloatExtractor<long double> {
static const int mantissa_bits = 64;
static const unsigned long long mantissa_max = ~0u;
static const int exponent_bias = 16383;
static const int exponent_bits = 15;
static const unsigned exponent_max = 32767;
static constexpr int mantissa_bits = 64;
static constexpr unsigned long long mantissa_max = ~0u;
static constexpr int exponent_bias = 16383;
static constexpr int exponent_bits = 15;
static constexpr unsigned exponent_max = 32767;
struct {
unsigned long long mantissa;
unsigned exponent : 15;
@ -79,11 +80,11 @@ union FloatExtractor<long double> {
template<>
union FloatExtractor<double> {
static const int mantissa_bits = 52;
static const unsigned long long mantissa_max = (1ull << 52) - 1;
static const int exponent_bias = 1023;
static const int exponent_bits = 11;
static const unsigned exponent_max = 2047;
static constexpr int mantissa_bits = 52;
static constexpr unsigned long long mantissa_max = (1ull << 52) - 1;
static constexpr int exponent_bias = 1023;
static constexpr int exponent_bits = 11;
static constexpr unsigned exponent_max = 2047;
struct {
unsigned long long mantissa : 52;
unsigned exponent : 11;
@ -94,11 +95,11 @@ union FloatExtractor<double> {
template<>
union FloatExtractor<float> {
static const int mantissa_bits = 23;
static const unsigned mantissa_max = (1 << 23) - 1;
static const int exponent_bias = 127;
static const int exponent_bits = 8;
static const unsigned exponent_max = 255;
static constexpr int mantissa_bits = 23;
static constexpr unsigned mantissa_max = (1 << 23) - 1;
static constexpr int exponent_bias = 127;
static constexpr int exponent_bits = 8;
static constexpr unsigned exponent_max = 255;
struct {
unsigned long long mantissa : 23;
unsigned exponent : 8;