mirror of https://github.com/OpenTTD/OpenTTD
Codechange: Add 'const' to static variables, which are only initialised once.
parent
1900125c98
commit
61cec33be2
|
@ -2036,7 +2036,7 @@ static bool ConSayClient(std::span<std::string_view> argv)
|
|||
}
|
||||
|
||||
/** All the known authorized keys with their name. */
|
||||
static std::vector<std::pair<std::string_view, NetworkAuthorizedKeys *>> _console_cmd_authorized_keys{
|
||||
static const std::initializer_list<std::pair<std::string_view, NetworkAuthorizedKeys *>> _console_cmd_authorized_keys{
|
||||
{ "admin", &_settings_client.network.admin_authorized_keys },
|
||||
{ "rcon", &_settings_client.network.rcon_authorized_keys },
|
||||
{ "server", &_settings_client.network.server_authorized_keys },
|
||||
|
|
|
@ -540,7 +540,7 @@ struct EffectProcs {
|
|||
};
|
||||
|
||||
/** Per-EffectVehicleType handling. */
|
||||
static std::array<EffectProcs, EV_END> _effect_procs = {{
|
||||
static const std::array<EffectProcs, EV_END> _effect_procs = {{
|
||||
{ ChimneySmokeInit, ChimneySmokeTick, TO_INDUSTRIES }, // EV_CHIMNEY_SMOKE
|
||||
{ SteamSmokeInit, SteamSmokeTick, TO_INVALID }, // EV_STEAM_SMOKE
|
||||
{ DieselSmokeInit, DieselSmokeTick, TO_INVALID }, // EV_DIESEL_SMOKE
|
||||
|
|
|
@ -716,7 +716,7 @@ FiosNumberedSaveName::FiosNumberedSaveName(const std::string &prefix) : prefix(p
|
|||
static std::string _prefix; ///< Static as the lambda needs access to it.
|
||||
|
||||
/* Callback for FiosFileScanner. */
|
||||
static FiosGetTypeAndNameProc *proc = [](SaveLoadOperation, std::string_view file, std::string_view ext) {
|
||||
static FiosGetTypeAndNameProc *const proc = [](SaveLoadOperation, std::string_view file, std::string_view ext) {
|
||||
if (StrEqualsIgnoreCase(ext, ".sav") && file.starts_with(_prefix)) return std::tuple(FIOS_TYPE_FILE, std::string{});
|
||||
return std::tuple(FIOS_TYPE_INVALID, std::string{});
|
||||
};
|
||||
|
|
|
@ -48,7 +48,7 @@ struct IniGroup {
|
|||
|
||||
/** Ini file that only supports loading. */
|
||||
struct IniLoadFile {
|
||||
using IniGroupNameList = std::initializer_list<std::string_view>;
|
||||
using IniGroupNameList = std::initializer_list<const std::string_view>;
|
||||
|
||||
std::list<IniGroup> groups; ///< all groups in the ini
|
||||
std::string comment; ///< last comment in file
|
||||
|
|
|
@ -178,7 +178,7 @@ struct DumpTarget {
|
|||
/** Dump nested object (or only its name if this instance is already known). */
|
||||
template <typename S> void WriteStructT(std::string_view name, const S *s)
|
||||
{
|
||||
static size_t type_id = ++LastTypeId();
|
||||
static const size_t type_id = ++LastTypeId();
|
||||
|
||||
if (s == nullptr) {
|
||||
/* No need to dump nullptr struct. */
|
||||
|
@ -201,7 +201,7 @@ struct DumpTarget {
|
|||
/** Dump nested object (or only its name if this instance is already known). */
|
||||
template <typename S> void WriteStructT(std::string_view name, const std::deque<S> *s)
|
||||
{
|
||||
static size_t type_id = ++LastTypeId();
|
||||
static const size_t type_id = ++LastTypeId();
|
||||
|
||||
if (s == nullptr) {
|
||||
/* No need to dump nullptr struct. */
|
||||
|
|
|
@ -29,19 +29,19 @@
|
|||
|
||||
#if defined(UNIX)
|
||||
/** List of certificate bundles, depending on OS. Taken from: https://go.dev/src/crypto/x509/root_linux.go. */
|
||||
static auto _certificate_files = {
|
||||
"/etc/ssl/certs/ca-certificates.crt", // Debian/Ubuntu/Gentoo etc.
|
||||
"/etc/pki/tls/certs/ca-bundle.crt", // Fedora/RHEL 6
|
||||
"/etc/ssl/ca-bundle.pem", // OpenSUSE
|
||||
"/etc/pki/tls/cacert.pem", // OpenELEC
|
||||
"/etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem", // CentOS/RHEL 7
|
||||
"/etc/ssl/cert.pem", // Alpine Linux
|
||||
static constexpr std::initializer_list<std::string_view> _certificate_files = {
|
||||
"/etc/ssl/certs/ca-certificates.crt"sv, // Debian/Ubuntu/Gentoo etc.
|
||||
"/etc/pki/tls/certs/ca-bundle.crt"sv, // Fedora/RHEL 6
|
||||
"/etc/ssl/ca-bundle.pem"sv, // OpenSUSE
|
||||
"/etc/pki/tls/cacert.pem"sv, // OpenELEC
|
||||
"/etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem"sv, // CentOS/RHEL 7
|
||||
"/etc/ssl/cert.pem"sv, // Alpine Linux
|
||||
};
|
||||
/** List of certificate directories, depending on OS. Taken from: https://go.dev/src/crypto/x509/root_linux.go. */
|
||||
static auto _certificate_directories = {
|
||||
"/etc/ssl/certs", // SLES10/SLES11, https://golang.org/issue/12139
|
||||
"/etc/pki/tls/certs", // Fedora/RHEL
|
||||
"/system/etc/security/cacerts", // Android
|
||||
static constexpr std::initializer_list<std::string_view> _certificate_directories = {
|
||||
"/etc/ssl/certs"sv, // SLES10/SLES11, https://golang.org/issue/12139
|
||||
"/etc/pki/tls/certs"sv, // Fedora/RHEL
|
||||
"/system/etc/security/cacerts"sv, // Android
|
||||
};
|
||||
#endif /* UNIX */
|
||||
|
||||
|
|
|
@ -110,7 +110,7 @@ inline auto MakeCallbackTable(std::index_sequence<i...>) noexcept
|
|||
}
|
||||
|
||||
/** Type-erased table of callbacks. */
|
||||
static auto _callback_table = MakeCallbackTable(std::make_index_sequence<_callback_tuple_size>{});
|
||||
static const auto _callback_table = MakeCallbackTable(std::make_index_sequence<_callback_tuple_size>{});
|
||||
|
||||
template <typename T> struct CallbackArgsHelper;
|
||||
template <typename... Targs>
|
||||
|
|
|
@ -317,7 +317,7 @@ static WindowDesc &GetNewsWindowLayout(NewsStyle style)
|
|||
/**
|
||||
* Per-NewsType data
|
||||
*/
|
||||
static NewsTypeData _news_type_data[] = {
|
||||
static const NewsTypeData _news_type_data[] = {
|
||||
/* name, age, sound, */
|
||||
NewsTypeData("news_display.arrival_player", 60, SND_1D_APPLAUSE ), ///< NewsType::ArrivalCompany
|
||||
NewsTypeData("news_display.arrival_other", 60, SND_1D_APPLAUSE ), ///< NewsType::ArrivalOther
|
||||
|
|
|
@ -145,7 +145,7 @@ static CGFloat SpriteFontGetWidth(void *ref_con)
|
|||
return GetGlyphWidth(fs, c);
|
||||
}
|
||||
|
||||
static CTRunDelegateCallbacks _sprite_font_callback = {
|
||||
static const CTRunDelegateCallbacks _sprite_font_callback = {
|
||||
kCTRunDelegateCurrentVersion, nullptr, nullptr, nullptr,
|
||||
&SpriteFontGetWidth
|
||||
};
|
||||
|
@ -330,7 +330,7 @@ void MacOSSetCurrentLocaleName(std::string_view iso_code)
|
|||
*/
|
||||
int MacOSStringCompare(std::string_view s1, std::string_view s2)
|
||||
{
|
||||
static bool supported = MacOSVersionIsAtLeast(10, 5, 0);
|
||||
static const bool supported = MacOSVersionIsAtLeast(10, 5, 0);
|
||||
if (!supported) return 0;
|
||||
|
||||
CFStringCompareFlags flags = kCFCompareCaseInsensitive | kCFCompareNumerically | kCFCompareLocalized | kCFCompareWidthInsensitive | kCFCompareForcedOrdering;
|
||||
|
@ -354,7 +354,7 @@ int MacOSStringCompare(std::string_view s1, std::string_view s2)
|
|||
*/
|
||||
int MacOSStringContains(std::string_view str, std::string_view value, bool case_insensitive)
|
||||
{
|
||||
static bool supported = MacOSVersionIsAtLeast(10, 5, 0);
|
||||
static const bool supported = MacOSVersionIsAtLeast(10, 5, 0);
|
||||
if (!supported) return -1;
|
||||
|
||||
CFStringCompareFlags flags = kCFCompareLocalized | kCFCompareWidthInsensitive;
|
||||
|
|
|
@ -66,7 +66,7 @@ static constexpr EndSegmentReasons ESRF_ABORT_PF_MASK = {
|
|||
|
||||
inline std::string ValueStr(EndSegmentReasons flags)
|
||||
{
|
||||
static const std::initializer_list<std::string_view> end_segment_reason_names = {
|
||||
static const std::initializer_list<const std::string_view> end_segment_reason_names = {
|
||||
"DEAD_END", "RAIL_TYPE", "INFINITE_LOOP", "SEGMENT_TOO_LONG", "CHOICE_FOLLOWS",
|
||||
"DEPOT", "WAYPOINT", "STATION", "SAFE_TILE",
|
||||
"PATH_TOO_LONG", "FIRST_TWO_WAY_RED", "LOOK_AHEAD_END", "TARGET_REACHED"
|
||||
|
|
|
@ -1916,7 +1916,7 @@ struct FenceOffset {
|
|||
};
|
||||
|
||||
/** Offsets for drawing fences */
|
||||
static FenceOffset _fence_offsets[] = {
|
||||
static const FenceOffset _fence_offsets[] = {
|
||||
{ CORNER_INVALID, 0, 1, 16, 1 }, // RFO_FLAT_X_NW
|
||||
{ CORNER_INVALID, 1, 0, 1, 16 }, // RFO_FLAT_Y_NE
|
||||
{ CORNER_W, 8, 8, 1, 1 }, // RFO_FLAT_LEFT
|
||||
|
|
|
@ -153,4 +153,4 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
static ScreenshotProvider_Pcx s_screenshot_provider_pcx;
|
||||
static const ScreenshotProvider_Pcx s_screenshot_provider_pcx;
|
||||
|
|
|
@ -1425,7 +1425,7 @@ void LoadFromConfig(bool startup)
|
|||
}
|
||||
|
||||
if (generic_version < IFV_AUTOSAVE_RENAME && IsConversionNeeded(generic_ini, "gui", "autosave", "autosave_interval", &old_item)) {
|
||||
static std::vector<std::string_view> _old_autosave_interval{"off", "monthly", "quarterly", "half year", "yearly"};
|
||||
static constexpr std::initializer_list<std::string_view> _old_autosave_interval{"off"sv, "monthly"sv, "quarterly"sv, "half year"sv, "yearly"sv};
|
||||
auto old_value = OneOfManySettingDesc::ParseSingleValue(*old_item->value, _old_autosave_interval).value_or(-1);
|
||||
|
||||
switch (old_value) {
|
||||
|
|
|
@ -448,7 +448,7 @@ static bool CheckRoadSide(int32_t &)
|
|||
static std::optional<uint32_t> ConvertLandscape(std::string_view value)
|
||||
{
|
||||
/* try with the old values */
|
||||
static std::vector<std::string_view> _old_landscape_values{"normal", "hilly", "desert", "candy"};
|
||||
static constexpr std::initializer_list<std::string_view> _old_landscape_values{"normal"sv, "hilly"sv, "desert"sv, "candy"sv};
|
||||
return OneOfManySettingDesc::ParseSingleValue(value, _old_landscape_values);
|
||||
}
|
||||
|
||||
|
|
|
@ -55,7 +55,7 @@ struct LegendAndColour {
|
|||
};
|
||||
|
||||
/** Link stat colours shown in legenda. */
|
||||
static uint8_t _linkstat_colours_in_legenda[] = {0, 1, 3, 5, 7, 9, 11};
|
||||
static const uint8_t _linkstat_colours_in_legenda[] = {0, 1, 3, 5, 7, 9, 11};
|
||||
|
||||
static const int NUM_NO_COMPANY_ENTRIES = 4; ///< Number of entries in the owner legend that are not companies.
|
||||
|
||||
|
|
|
@ -864,7 +864,7 @@ std::optional<std::string> GetTextfile(TextfileType type, Subdirectory dir, std:
|
|||
|
||||
std::string_view base_path = filename.substr(0, slash + 1);
|
||||
|
||||
static const std::initializer_list<std::string_view> extensions{
|
||||
static const std::initializer_list<const std::string_view> extensions{
|
||||
"txt",
|
||||
"md",
|
||||
#if defined(WITH_ZLIB)
|
||||
|
|
|
@ -961,7 +961,7 @@ static void MakeCatalanTownName(StringBuilder &builder, uint32_t seed)
|
|||
typedef void TownNameGenerator(StringBuilder &builder, uint32_t seed);
|
||||
|
||||
/** Town name generators */
|
||||
static TownNameGenerator *_town_name_generators[] = {
|
||||
static TownNameGenerator *const _town_name_generators[] = {
|
||||
MakeEnglishOriginalTownName, // replaces first 4 characters of name
|
||||
MakeFrenchTownName,
|
||||
MakeGermanTownName,
|
||||
|
|
|
@ -2391,13 +2391,13 @@ extern void DrawRoadVehDetails(const Vehicle *v, const Rect &r);
|
|||
extern void DrawShipDetails(const Vehicle *v, const Rect &r);
|
||||
extern void DrawAircraftDetails(const Aircraft *v, const Rect &r);
|
||||
|
||||
static StringID _service_interval_dropdown_calendar[] = {
|
||||
static const StringID _service_interval_dropdown_calendar[] = {
|
||||
STR_VEHICLE_DETAILS_DEFAULT,
|
||||
STR_VEHICLE_DETAILS_DAYS,
|
||||
STR_VEHICLE_DETAILS_PERCENT,
|
||||
};
|
||||
|
||||
static StringID _service_interval_dropdown_wallclock[] = {
|
||||
static const StringID _service_interval_dropdown_wallclock[] = {
|
||||
STR_VEHICLE_DETAILS_DEFAULT,
|
||||
STR_VEHICLE_DETAILS_MINUTES,
|
||||
STR_VEHICLE_DETAILS_PERCENT,
|
||||
|
|
|
@ -442,7 +442,7 @@ static void SetDarkModeForWindow(HWND hWnd, bool dark_mode)
|
|||
* reason, the code uses dynamic loading and ignores any errors for a best-effort result. */
|
||||
static LibraryLoader _dwmapi("dwmapi.dll");
|
||||
typedef HRESULT(WINAPI *PFNDWMSETWINDOWATTRIBUTE)(HWND, DWORD, LPCVOID, DWORD);
|
||||
static PFNDWMSETWINDOWATTRIBUTE DwmSetWindowAttribute = _dwmapi.GetFunction("DwmSetWindowAttribute");
|
||||
static const PFNDWMSETWINDOWATTRIBUTE DwmSetWindowAttribute = _dwmapi.GetFunction("DwmSetWindowAttribute");
|
||||
|
||||
if (DwmSetWindowAttribute != nullptr) {
|
||||
/* Contrary to the published documentation, DWMWA_USE_IMMERSIVE_DARK_MODE does not change the
|
||||
|
|
|
@ -3559,7 +3559,7 @@ struct ViewportSSCSS {
|
|||
};
|
||||
|
||||
/** List of sorters ordered from best to worst. */
|
||||
static ViewportSSCSS _vp_sprite_sorters[] = {
|
||||
static const ViewportSSCSS _vp_sprite_sorters[] = {
|
||||
#ifdef WITH_SSE
|
||||
{ &ViewportSortParentSpritesSSE41Checker, &ViewportSortParentSpritesSSE41 },
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue