From 5b325ac2bc28a1b5f6fe620c76092a07d85e477e Mon Sep 17 00:00:00 2001 From: Vyacheslav Ivanov Date: Fri, 2 Aug 2024 02:49:07 +0300 Subject: [PATCH] fix: optimization: PVS-Studio warning V815 The 'empty()' method is more efficient for checking if a string is empty compared to comparing it with an empty string literal. The default constructor 'std::wstring()' is more efficient for creating an empty string compared to using a string literal. The 'clear()' method is more efficient for clearing a std::wstring compared to assigning it an empty string literal. Reported by: PVS-Studio Signed-off-by: Vyacheslav Ivanov --- src/graphics/ui/elements/InventoryView.cpp | 2 +- src/logic/scripting/scripting_functional.cpp | 2 +- src/world/World.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/graphics/ui/elements/InventoryView.cpp b/src/graphics/ui/elements/InventoryView.cpp index de121327..14b7a59b 100644 --- a/src/graphics/ui/elements/InventoryView.cpp +++ b/src/graphics/ui/elements/InventoryView.cpp @@ -126,7 +126,7 @@ void SlotView::draw(const DrawContext* pctx, Assets* assets) { langs::get(util::str2wstr_utf8(def->caption)) ); } else { - tooltip = L""; + tooltip.clear(); } } prevItem = itemid; diff --git a/src/logic/scripting/scripting_functional.cpp b/src/logic/scripting/scripting_functional.cpp index b3ad82af..557ece1d 100644 --- a/src/logic/scripting/scripting_functional.cpp +++ b/src/logic/scripting/scripting_functional.cpp @@ -66,7 +66,7 @@ wstringsupplier scripting::create_wstring_supplier( auto str = lua::require_wstring(L, -1); lua::pop(L); return str; } - return std::wstring(L""); + return std::wstring(); }; } diff --git a/src/world/World.cpp b/src/world/World.cpp index 37379852..c8ad542a 100644 --- a/src/world/World.cpp +++ b/src/world/World.cpp @@ -201,7 +201,7 @@ void World::deserialize(dynamic::Map* root) { generator = root->get("generator", generator); seed = root->get("seed", seed); - if (generator == "") { + if (generator.empty()) { generator = WorldGenerators::getDefaultGeneratorID(); } if (auto verobj = root->map("version")) {