Skip to content

Commit

Permalink
chore: remove redundant code and unused includes (#130)
Browse files Browse the repository at this point in the history
- Remove unused includes
- Remove redundant code:
  - zero/null initialization
  - instances of `typename` keyword
  - qualifiers
  - `static_cast`s
  - template arguments
  - instances of `else` keyword
  • Loading branch information
ThirdEyeSqueegee authored Oct 2, 2023
1 parent 7231bd7 commit 22b9968
Show file tree
Hide file tree
Showing 29 changed files with 372 additions and 397 deletions.
2 changes: 1 addition & 1 deletion CommonLibSF/include/RE/B/BSFixedString.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ namespace RE
static constexpr const value_type EMPTY[]{ 0 };

// members
BSStringPool::Entry* _data{ nullptr }; // 0
BSStringPool::Entry* _data{}; // 0
};

extern template class BSFixedString<char, false>;
Expand Down
2 changes: 1 addition & 1 deletion CommonLibSF/include/RE/B/BSIntrusiveRefCounted.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace RE
public:
SF_RTTI(BSIntrusiveRefCounted);

volatile mutable std::uint32_t refCount{ 0 }; // 00
volatile mutable std::uint32_t refCount{}; // 00
std::uint32_t unk04; // 04
};
static_assert(sizeof(BSIntrusiveRefCounted) == 0x08);
Expand Down
6 changes: 3 additions & 3 deletions CommonLibSF/include/RE/B/BSStringT.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ namespace RE
a_rhs._capacity = 0;
}

pointer _data{ nullptr }; // ??
size_type _size{ 0 }; // ??
size_type _capacity{ 0 }; // ??
pointer _data{}; // ??
size_type _size{}; // ??
size_type _capacity{}; // ??
};
}
6 changes: 3 additions & 3 deletions CommonLibSF/include/RE/F/FormTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ namespace std
{
[[nodiscard]] inline std::string to_string(RE::FormType a_formType)
{
return RE::FormTypeToString(a_formType);
return FormTypeToString(a_formType);
}
}

Expand All @@ -250,7 +250,7 @@ namespace fmt
template <class FormatContext>
auto format(const RE::FormType& a_formType, FormatContext& a_ctx)
{
return fmt::format_to(a_ctx.out(), "{}", RE::FormTypeToString(a_formType));
return fmt::format_to(a_ctx.out(), "{}", FormTypeToString(a_formType));
}
};
}
Expand All @@ -265,7 +265,7 @@ namespace std
template <class FormatContext>
auto format(RE::FormType a_formType, FormatContext& a_ctx)
{
return formatter<std::string_view, CharT>::format(RE::FormTypeToString(a_formType), a_ctx);
return formatter<std::string_view, CharT>::format(FormTypeToString(a_formType), a_ctx);
}
};
}
Expand Down
6 changes: 3 additions & 3 deletions CommonLibSF/include/RE/N/NativeFunctionBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,10 @@ namespace RE
std::uint64_t _retType; // 28 TypeInfo
ParameterInfo _params; // 30
bool _isStatic; // 40
bool _isCallableFromTasklet{ false }; // 41
bool _isLatent{ false }; // 42
bool _isCallableFromTasklet{}; // 41
bool _isLatent{}; // 42
std::uint8_t _pad43; // 43
std::uint32_t _userFlags{ 0 }; // 44
std::uint32_t _userFlags{}; // 44
BSFixedString _docString; // 48
};
static_assert(sizeof(NativeFunctionBase) == 0x50);
Expand Down
6 changes: 3 additions & 3 deletions CommonLibSF/include/RE/N/NiPoint3.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ namespace RE
float Unitize();

// members
float x{ 0.0F }; // 0x0
float y{ 0.0F }; // 0x4
float z{ 0.0F }; // 0x8
float x{}; // 0x0
float y{}; // 0x4
float z{}; // 0x8
};
static_assert(sizeof(NiPoint3) == 0xC);

Expand Down
2 changes: 1 addition & 1 deletion CommonLibSF/include/RE/N/NiSmartPointer.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ namespace RE
}

// members
element_type* _ptr{ nullptr }; // 0
element_type* _ptr{}; // 0
};
static_assert(sizeof(NiPointer<void*>) == 0x8);

Expand Down
2 changes: 1 addition & 1 deletion CommonLibSF/include/RE/RTTI.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ namespace RE
[[nodiscard]] constexpr bool is_good() const noexcept { return _rva != 0; }

// members
std::uint32_t _rva{ 0 }; // 00
std::uint32_t _rva{}; // 00
};

static_assert(sizeof(RVA<void*>) == 0x4);
Expand Down
2 changes: 1 addition & 1 deletion CommonLibSF/include/RE/S/ScaleformPtr.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ namespace RE::Scaleform
}

// members
element_type* _ptr{ nullptr }; // 00
element_type* _ptr{}; // 00
};
static_assert(sizeof(Ptr<void*>) == 0x8);

Expand Down
2 changes: 1 addition & 1 deletion CommonLibSF/include/RE/S/Script.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ namespace RE
// members
const char* paramName{ "" }; // 00
std::uint32_t paramType; // 08 enumeration
bool optional{ false }; // 0C
bool optional{}; // 0C
};
static_assert(sizeof(SCRIPT_PARAMETER) == 0x10);

Expand Down
22 changes: 11 additions & 11 deletions CommonLibSF/include/REL/ID.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,18 @@ namespace REL
void close();

private:
void* _mapping{ nullptr };
void* _view{ nullptr };
void* _mapping{};
void* _view{};
};

class Offset2ID
{
public:
using value_type = mapping_t;
using container_type = std::vector<value_type>;
using size_type = typename container_type::size_type;
using const_iterator = typename container_type::const_iterator;
using const_reverse_iterator = typename container_type::const_reverse_iterator;
using size_type = container_type::size_type;
using const_iterator = container_type::const_iterator;
using const_reverse_iterator = container_type::const_reverse_iterator;

template <class ExecutionPolicy>
explicit Offset2ID(ExecutionPolicy&& a_policy)
Expand Down Expand Up @@ -151,12 +151,12 @@ namespace REL

[[nodiscard]] std::size_t address_count() const noexcept
{
return static_cast<std::size_t>(_addressCount);
return _addressCount;
}

[[nodiscard]] std::uint64_t pointer_size() const noexcept
{
return static_cast<std::uint64_t>(_pointerSize);
return _pointerSize;
}

[[nodiscard]] std::string_view name() const noexcept
Expand All @@ -172,8 +172,8 @@ namespace REL
private:
char _name[20]{};
Version _version;
std::uint32_t _pointerSize{ 0 };
std::uint32_t _addressCount{ 0 };
std::uint32_t _pointerSize{};
std::uint32_t _addressCount{};
};
}

Expand Down Expand Up @@ -232,7 +232,7 @@ namespace REL
}

static IDDatabase _instance;
inline static std::atomic_bool _initialized{ false };
inline static std::atomic_bool _initialized{};
inline static std::mutex _initLock;
database::memory_map _mmap;
std::span<database::mapping_t> _id2offset;
Expand Down Expand Up @@ -275,7 +275,7 @@ namespace REL
return Module::get().base();
}

std::uint64_t _id{ 0 };
std::uint64_t _id{};
};

template <class ExecutionPolicy>
Expand Down
8 changes: 4 additions & 4 deletions CommonLibSF/include/REL/Module.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ namespace REL
private:
friend class Module;

std::uintptr_t _proxyBase{ 0 };
std::uintptr_t _address{ 0 };
std::size_t _size{ 0 };
std::uintptr_t _proxyBase{};
std::uintptr_t _address{};
std::size_t _size{};
};

class Module
Expand All @@ -59,7 +59,7 @@ namespace REL
[[nodiscard]] constexpr auto base() const noexcept { return _base; }

template <typename T = void>
[[nodiscard]] constexpr auto* pointer() const noexcept
[[nodiscard]] constexpr auto pointer() const noexcept
{
return std::bit_cast<T*>(base());
}
Expand Down
2 changes: 1 addition & 1 deletion CommonLibSF/include/REL/Offset.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ namespace REL
}

private:
std::ptrdiff_t _offset{ 0 };
std::ptrdiff_t _offset{};
};
}
15 changes: 7 additions & 8 deletions CommonLibSF/include/REL/Relocation.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include "REL/ID.h"
#include "REL/Module.h"
#include "REL/Offset.h"
#include "REL/Version.h"

#define REL_MAKE_MEMBER_FUNCTION_POD_TYPE_HELPER_IMPL(a_nopropQual, a_propQual, ...) \
template <class R, class Cls, class... Args> \
Expand Down Expand Up @@ -153,14 +152,14 @@ namespace REL

inline void safe_write(const std::uintptr_t a_dst, const void* a_src, const std::size_t a_count)
{
std::uint32_t old{ 0 };
std::uint32_t old{};
auto success = WinAPI::VirtualProtect(reinterpret_cast<void*>(a_dst), a_count, WinAPI::PAGE_EXECUTE_READWRITE, std::addressof(old));
if (success != 0) {
if (success) {
std::memcpy(reinterpret_cast<void*>(a_dst), a_src, a_count);
success = WinAPI::VirtualProtect(reinterpret_cast<void*>(a_dst), a_count, old, std::addressof(old));
}

assert(success != 0);
assert(success);
}

template <std::integral T>
Expand All @@ -177,14 +176,14 @@ namespace REL

inline void safe_fill(const std::uintptr_t a_dst, const std::uint8_t a_value, const std::size_t a_count)
{
std::uint32_t old{ 0 };
std::uint32_t old{};
auto success = WinAPI::VirtualProtect(reinterpret_cast<void*>(a_dst), a_count, WinAPI::PAGE_EXECUTE_READWRITE, std::addressof(old));
if (success != 0) {
if (success) {
std::fill_n(reinterpret_cast<std::uint8_t*>(a_dst), a_count, a_value);
success = WinAPI::VirtualProtect(reinterpret_cast<void*>(a_dst), a_count, old, std::addressof(old));
}

assert(success != 0);
assert(success);
};

template <typename T = std::uintptr_t>
Expand Down Expand Up @@ -270,7 +269,7 @@ namespace REL
private:
[[nodiscard]] static std::uintptr_t base() { return Module::get().base(); }

std::uintptr_t _address{ 0 };
std::uintptr_t _address{};
};
}

Expand Down
14 changes: 7 additions & 7 deletions CommonLibSF/include/REL/Version.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ namespace REL

[[nodiscard]] static constexpr Version unpack(const std::uint32_t a_packedVersion) noexcept
{
return REL::Version{
return Version{
static_cast<value_type>((a_packedVersion >> 24) & 0x0FF),
static_cast<value_type>((a_packedVersion >> 16) & 0x0FF),
static_cast<value_type>((a_packedVersion >> 4) & 0xFFF),
Expand All @@ -106,7 +106,7 @@ namespace REL
namespace detail
{
template <std::size_t Index, char C>
constexpr uint8_t read_version(std::array<typename REL::Version::value_type, 4>& result)
constexpr uint8_t read_version(std::array<Version::value_type, 4>& result)
{
static_assert(C >= '0' && C <= '9', "Invalid character in semantic version literal.");
static_assert(Index < 4, "Too many components in semantic version literal.");
Expand All @@ -116,7 +116,7 @@ namespace REL

template <std::size_t Index, char C, char... Rest>
requires(sizeof...(Rest) > 0)
constexpr uint8_t read_version(std::array<typename REL::Version::value_type, 4>& result)
constexpr uint8_t read_version(std::array<Version::value_type, 4>& result)
{
static_assert(C == '.' || (C >= '0' && C <= '9'), "Invalid character in semantic version literal.");
static_assert(Index < 4, "Too many components in semantic version literal.");
Expand All @@ -132,14 +132,14 @@ namespace REL
}

template <char... C>
[[nodiscard]] constexpr REL::Version operator""_v() noexcept
[[nodiscard]] constexpr Version operator""_v() noexcept
{
std::array<typename REL::Version::value_type, 4> result{ 0, 0, 0, 0 };
std::array<Version::value_type, 4> result{ 0, 0, 0, 0 };
detail::read_version<0, C...>(result);
return REL::Version(result);
return Version(result);
}

[[nodiscard]] constexpr REL::Version operator""_v(const char* str, const std::size_t len)
[[nodiscard]] constexpr Version operator""_v(const char* str, const std::size_t len)
{
return Version(std::string_view(str, len));
}
Expand Down
1 change: 0 additions & 1 deletion CommonLibSF/include/SFSE/API.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include "SFSE/Impl/Stubs.h"
#include "SFSE/Interfaces.h"
#include "SFSE/Trampoline.h"
#include "SFSE/Version.h"

#define SFSEAPI __cdecl

Expand Down
6 changes: 3 additions & 3 deletions CommonLibSF/include/SFSE/IAT.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@ namespace SFSE
[[nodiscard]] void* GetIATPtr(std::string_view a_dll, std::string_view a_function);

template <class T>
[[nodiscard]] inline T* GetIATPtr(std::string_view a_dll, std::string_view a_function)
[[nodiscard]] T* GetIATPtr(std::string_view a_dll, std::string_view a_function)
{
return static_cast<T*>(GetIATPtr(std::move(a_dll), std::move(a_function)));
}

[[nodiscard]] void* GetIATPtr(void* a_module, std::string_view a_dll, std::string_view a_function);

template <class T>
[[nodiscard]] inline T* GetIATPtr(void* a_module, std::string_view a_dll, std::string_view a_function)
[[nodiscard]] T* GetIATPtr(void* a_module, std::string_view a_dll, std::string_view a_function)
{
return static_cast<T*>(GetIATPtr(a_module, std::move(a_dll), std::move(a_function)));
}

std::uintptr_t PatchIAT(std::uintptr_t a_newFunc, std::string_view a_dll, std::string_view a_function);

template <class F>
inline std::uintptr_t PatchIAT(F a_newFunc, const std::string_view a_dll, const std::string_view a_function)
std::uintptr_t PatchIAT(F a_newFunc, const std::string_view a_dll, const std::string_view a_function)
{
return PatchIAT(stl::unrestricted_cast<std::uintptr_t>(a_newFunc), a_dll, a_function);
}
Expand Down
11 changes: 5 additions & 6 deletions CommonLibSF/include/SFSE/Impl/PCH.h
Original file line number Diff line number Diff line change
Expand Up @@ -389,11 +389,11 @@ namespace SFSE
}

private:
underlying_type _impl{ 0 };
underlying_type _impl{};
};

template <class... Args>
enumeration(Args...) -> enumeration<std::common_type_t<Args...>, std::underlying_type_t<std::common_type_t<Args...>>>;
enumeration(Args...) -> enumeration<std::common_type_t<Args...>>;
}
}

Expand Down Expand Up @@ -583,12 +583,12 @@ namespace SFSE
void memzero(volatile T* a_ptr, const std::size_t a_size = sizeof(T))
{
const auto begin = reinterpret_cast<volatile char*>(a_ptr);
constexpr char val{ 0 };
constexpr char val{};
std::fill_n(begin, a_size, val);
}

template <class... Args>
[[nodiscard]] inline auto pun_bits(Args... a_args)
[[nodiscard]] auto pun_bits(Args... a_args)
requires(std::same_as<std::remove_cv_t<Args>, bool> && ...)
{
constexpr auto ARGC = sizeof...(Args);
Expand Down Expand Up @@ -675,9 +675,8 @@ namespace SFSE
if (result && result != buf.size()) {
std::filesystem::path p(buf.begin(), buf.begin() + result);
return p.filename().native();
} else {
return L""s;
}
return L""s;
}();

spdlog::log(spdlog::source_loc{ a_loc.file_name(), static_cast<int>(a_loc.line()), a_loc.function_name() }, spdlog::level::critical, a_msg);
Expand Down
1 change: 0 additions & 1 deletion CommonLibSF/include/SFSE/Interfaces.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#pragma once

#include "SFSE/Impl/Stubs.h"
#include "SFSE/Version.h"

namespace RE
{
Expand Down
Loading

0 comments on commit 22b9968

Please sign in to comment.