From 957bd03b987fbef49f0448d862078f27295a3120 Mon Sep 17 00:00:00 2001 From: Gleb Mazovetskiy Date: Sun, 12 Mar 2023 16:31:56 +0000 Subject: [PATCH] Remove `FMT_COMPILE` in "cold" places Removes most `FMT_COMPILE` calls. `FMT_COMPILE` results in better performance but larger code size. Removes `FMT_COMPILE` calls for places that are called infrequently, i.e. not on every frame. RG-99 binary size reduced by ~4 KiB. --- Source/engine/palette.cpp | 6 +++--- Source/engine/render/text_render.cpp | 4 ++-- Source/items.cpp | 4 ++-- Source/loadsave.cpp | 4 ++-- Source/monster.cpp | 2 +- Source/pfile.cpp | 4 ++-- Source/player.cpp | 4 ++-- Source/utils/format_int.cpp | 3 --- 8 files changed, 14 insertions(+), 17 deletions(-) diff --git a/Source/engine/palette.cpp b/Source/engine/palette.cpp index f41f03d3f..9fd8c50c1 100644 --- a/Source/engine/palette.cpp +++ b/Source/engine/palette.cpp @@ -5,7 +5,7 @@ */ #include "engine/palette.h" -#include +#include #include "engine/backbuffer_state.hpp" #include "engine/demomode.h" @@ -265,9 +265,9 @@ void LoadRndLvlPal(dungeon_type l) if (!*sgOptions.Graphics.alternateNestArt) { rv++; } - *fmt::format_to(szFileName, FMT_COMPILE(R"(nlevels\l{0}data\l{0}base{1}.pal)"), 6, rv) = '\0'; + *fmt::format_to(szFileName, R"(nlevels\l{0}data\l{0}base{1}.pal)", 6, rv) = '\0'; } else { - *fmt::format_to(szFileName, FMT_COMPILE(R"(levels\l{0}data\l{0}_{1}.pal)"), l, rv) = '\0'; + *fmt::format_to(szFileName, R"(levels\l{0}data\l{0}_{1}.pal)", static_cast(l), rv) = '\0'; } LoadPalette(szFileName); } diff --git a/Source/engine/render/text_render.cpp b/Source/engine/render/text_render.cpp index 329b9c187..b42773e30 100644 --- a/Source/engine/render/text_render.cpp +++ b/Source/engine/render/text_render.cpp @@ -10,7 +10,7 @@ #include #include -#include +#include #include "DiabloUI/diabloui.h" #include "DiabloUI/ui_item.h" @@ -143,7 +143,7 @@ bool IsSmallFontTallRow(uint16_t row) void GetFontPath(GameFontTables size, uint16_t row, string_view ext, char *out) { - *fmt::format_to(out, FMT_COMPILE(R"(fonts\{}-{:02x}.{})"), FontSizes[size], row, ext) = '\0'; + *fmt::format_to(out, R"(fonts\{}-{:02x}.{})", FontSizes[size], row, ext) = '\0'; } uint32_t GetFontId(GameFontTables size, uint16_t row) diff --git a/Source/items.cpp b/Source/items.cpp index c32224166..fdd9a8256 100644 --- a/Source/items.cpp +++ b/Source/items.cpp @@ -13,7 +13,7 @@ #include #include -#include +#include #include #include "DiabloUI/ui_flags.hpp" @@ -3169,7 +3169,7 @@ void CornerstoneSave() PackItem(id, CornerStone.item, (CornerStone.item.dwBuff & CF_HELLFIRE) != 0); const auto *buffer = reinterpret_cast(&id); for (size_t i = 0; i < sizeof(ItemPack); i++) { - fmt::format_to(&sgOptions.Hellfire.szItem[i * 2], FMT_COMPILE("{:02X}"), buffer[i]); + fmt::format_to(&sgOptions.Hellfire.szItem[i * 2], "{:02X}", buffer[i]); } sgOptions.Hellfire.szItem[sizeof(sgOptions.Hellfire.szItem) - 1] = '\0'; } else { diff --git a/Source/loadsave.cpp b/Source/loadsave.cpp index 62b9f76e4..9d26b74fa 100644 --- a/Source/loadsave.cpp +++ b/Source/loadsave.cpp @@ -11,7 +11,7 @@ #include #include -#include +#include #include "automap.h" #include "codec.h" @@ -901,7 +901,7 @@ void GetLevelNames(string_view prefix, char *out) suf = 'l'; num = currlevel; } - *fmt::format_to(out, FMT_COMPILE("{}{}{:02d}"), prefix, suf, num) = '\0'; + *fmt::format_to(out, "{}{}{:02d}", prefix, suf, num) = '\0'; } void GetTempLevelNames(char *szTemp) diff --git a/Source/monster.cpp b/Source/monster.cpp index 5502afa82..01bdbf2b9 100644 --- a/Source/monster.cpp +++ b/Source/monster.cpp @@ -10,7 +10,7 @@ #include #include -#include +#include #include #include "control.h" diff --git a/Source/pfile.cpp b/Source/pfile.cpp index ee2a3a644..1feb07c6d 100644 --- a/Source/pfile.cpp +++ b/Source/pfile.cpp @@ -8,7 +8,7 @@ #include #include -#include +#include #include "codec.h" #include "engine.h" @@ -89,7 +89,7 @@ bool GetSaveNames(uint8_t index, string_view prefix, char *out) return false; } - *fmt::format_to(out, FMT_COMPILE("{}{}{:02d}"), prefix, suf, index) = '\0'; + *fmt::format_to(out, "{}{}{:02d}", prefix, suf, index) = '\0'; return true; } diff --git a/Source/player.cpp b/Source/player.cpp index 97f76f1e8..1b2b7b17f 100644 --- a/Source/player.cpp +++ b/Source/player.cpp @@ -6,7 +6,7 @@ #include #include -#include +#include #include "control.h" #include "controls/plrctrls.h" @@ -2157,7 +2157,7 @@ void LoadPlrGFX(Player &player, player_graphic graphic) char prefix[3] = { CharChar[static_cast(cls)], ArmourChar[player._pgfxnum >> 4], WepChar[static_cast(animWeaponId)] }; char pszName[256]; - *fmt::format_to(pszName, FMT_COMPILE(R"(plrgfx\{0}\{1}\{1}{2})"), path, string_view(prefix, 3), szCel) = 0; + *fmt::format_to(pszName, R"(plrgfx\{0}\{1}\{1}{2})", path, string_view(prefix, 3), szCel) = 0; const uint16_t animationWidth = GetPlayerSpriteWidth(cls, graphic, animWeaponId); animationData.sprites = LoadCl2Sheet(pszName, animationWidth); std::optional> trn = GetClassTRN(player); diff --git a/Source/utils/format_int.cpp b/Source/utils/format_int.cpp index 1b6acba17..8bcfa61cf 100644 --- a/Source/utils/format_int.cpp +++ b/Source/utils/format_int.cpp @@ -1,8 +1,5 @@ #include "utils/format_int.hpp" -#include -#include - #include "utils/language.h" #include "utils/stdcompat/string_view.hpp" #include "utils/str_cat.hpp"