From 251b48274c979d2d72ba54d514549d83afadc593 Mon Sep 17 00:00:00 2001 From: Parapets Date: Sun, 10 Nov 2024 00:13:31 +0000 Subject: [PATCH] Further build optimization --- include/RE/B/BGSDefaultObjectManager.h | 1 - include/RE/B/BGSEntryPointPerkEntry.h | 1 - include/RE/B/BSFixedString.h | 119 ++++-------------------- include/RE/F/FormTraits.h | 21 ++++- include/RE/T/TESForm.h | 32 +++---- src/RE/B/BSFixedString.cpp | 121 +++++++++++++++++++++++++ src/RE/T/TutorialMenu.cpp | 1 + 7 files changed, 169 insertions(+), 127 deletions(-) diff --git a/include/RE/B/BGSDefaultObjectManager.h b/include/RE/B/BGSDefaultObjectManager.h index 18d61df64..6ec339f28 100644 --- a/include/RE/B/BGSDefaultObjectManager.h +++ b/include/RE/B/BGSDefaultObjectManager.h @@ -1,7 +1,6 @@ #pragma once #include "RE/B/BSTSingleton.h" -#include "RE/F/FormTraits.h" #include "RE/F/FormTypes.h" #include "RE/T/TESForm.h" diff --git a/include/RE/B/BGSEntryPointPerkEntry.h b/include/RE/B/BGSEntryPointPerkEntry.h index a5420754a..6af7c968f 100644 --- a/include/RE/B/BGSEntryPointPerkEntry.h +++ b/include/RE/B/BGSEntryPointPerkEntry.h @@ -1,7 +1,6 @@ #pragma once #include "RE/B/BGSPerkEntry.h" -#include "RE/F/FormTypes.h" #include "RE/M/MemoryManager.h" namespace RE diff --git a/include/RE/B/BSFixedString.h b/include/RE/B/BSFixedString.h index a563392d0..ce86c687c 100644 --- a/include/RE/B/BSFixedString.h +++ b/include/RE/B/BSFixedString.h @@ -20,88 +20,26 @@ namespace RE constexpr BSFixedString() noexcept = default; - inline BSFixedString(const BSFixedString& a_rhs) : - _data(a_rhs._data) - { - try_acquire(); - } + BSFixedString(const BSFixedString& a_rhs); + BSFixedString(BSFixedString&& a_rhs) noexcept; + BSFixedString(const_pointer a_string); + BSFixedString(std::basic_string_view a_view); - inline BSFixedString(BSFixedString&& a_rhs) : - _data(a_rhs._data) + inline BSFixedString(std::convertible_to> auto&& a_string) : + BSFixedString(static_cast>(a_string)) { - a_rhs._data = nullptr; } - inline BSFixedString(const_pointer a_string) - { - if (a_string) { - ctor(a_string); - } - } - - template < - class T, - std::enable_if_t< - std::conjunction_v< - std::is_convertible>, - std::negation< - std::is_convertible>>, - int> = 0> - inline BSFixedString(const T& a_string) - { - const auto view = static_cast>(a_string); - if (!view.empty()) { - ctor(view.data()); - } - } + ~BSFixedString(); - inline ~BSFixedString() { try_release(); } + BSFixedString& operator=(const BSFixedString& a_rhs); + BSFixedString& operator=(BSFixedString&& a_rhs) noexcept; + BSFixedString& operator=(const_pointer a_string); + BSFixedString& operator=(std::basic_string_view a_view); - inline BSFixedString& operator=(const BSFixedString& a_rhs) + inline BSFixedString& operator=(std::convertible_to> auto&& a_string) { - if (this != std::addressof(a_rhs)) { - try_release(); - _data = a_rhs._data; - try_acquire(); - } - return *this; - } - - inline BSFixedString& operator=(BSFixedString&& a_rhs) - { - if (this != std::addressof(a_rhs)) { - try_release(); - _data = a_rhs._data; - a_rhs._data = nullptr; - } - return *this; - } - - inline BSFixedString& operator=(const_pointer a_string) - { - try_release(); - if (a_string) { - ctor(a_string); - } - return *this; - } - - template < - class T, - std::enable_if_t< - std::conjunction_v< - std::is_convertible>, - std::negation< - std::is_convertible>>, - int> = 0> - inline BSFixedString& operator=(const T& a_string) - { - const auto view = static_cast>(a_string); - try_release(); - if (!view.empty()) { - ctor(view.data()); - } - return *this; + return *this = static_cast>(a_string); } [[nodiscard]] inline const_reference operator[](size_type a_pos) const noexcept @@ -172,22 +110,10 @@ namespace RE return _wcsnicmp(a_lhs, a_rhs, a_length); } - inline BSFixedString* ctor(const char* a_data) { return ctor8(a_data); } - inline BSFixedString* ctor(const wchar_t* a_data) { return ctor16(a_data); } - - inline BSFixedString* ctor8(const char* a_data) - { - using func_t = decltype(&BSFixedString::ctor8); - REL::Relocation func{ STATIC_OFFSET(BSFixedString::Ctor8) }; - return func(this, a_data); - } - - inline BSFixedString* ctor16(const wchar_t* a_data) - { - using func_t = decltype(&BSFixedString::ctor16); - REL::Relocation func{ STATIC_OFFSET(BSFixedString::Ctor16) }; - return func(this, a_data); - } + BSFixedString* ctor(const char* a_data); + BSFixedString* ctor(const wchar_t* a_data); + BSFixedString* ctor8(const char* a_data); + BSFixedString* ctor16(const wchar_t* a_data); [[nodiscard]] inline BSStringPool::Entry* get_proxy() noexcept { @@ -203,15 +129,8 @@ namespace RE nullptr; } - inline void try_acquire() - { - const auto proxy = get_proxy(); - if (proxy) { - proxy->acquire(); - } - } - - inline void try_release() { BSStringPool::Entry::release(_data); } + void try_acquire(); + void try_release(); static constexpr const value_type EMPTY[]{ 0 }; diff --git a/include/RE/F/FormTraits.h b/include/RE/F/FormTraits.h index 4e1c1e459..78303c78f 100644 --- a/include/RE/F/FormTraits.h +++ b/include/RE/F/FormTraits.h @@ -142,15 +142,28 @@ namespace RE { - template - T* TESForm::As() noexcept + template + requires(std::is_class_v) + T* TESForm::As() noexcept { return const_cast( static_cast(this)->As()); } - template - const T* TESForm::As() const noexcept + template + requires(requires { T::FORMTYPE; }) + const T* TESForm::As() const noexcept + { + if (GetFormType() == T::FORMTYPE) { + return static_cast(this); + } else { + return nullptr; + } + } + + template T> + requires(!requires { T::FORMTYPE; }) + const T* TESForm::As() const noexcept { switch (GetFormType()) { SKSE_FORMTRAITS(TESForm); diff --git a/include/RE/T/TESForm.h b/include/RE/T/TESForm.h index ee320b84e..97199b30b 100644 --- a/include/RE/T/TESForm.h +++ b/include/RE/T/TESForm.h @@ -206,27 +206,17 @@ namespace RE return form ? form->As() : nullptr; } - template < - class T, - class = std::enable_if_t< - std::negation_v< - std::disjunction< - std::is_pointer, - std::is_reference, - std::is_const, - std::is_volatile>>>> - [[nodiscard]] T* As() noexcept; - - template < - class T, - class = std::enable_if_t< - std::negation_v< - std::disjunction< - std::is_pointer, - std::is_reference, - std::is_const, - std::is_volatile>>>> - [[nodiscard]] const T* As() const noexcept; + template + requires(std::is_class_v) + [[nodiscard]] T* As() noexcept; + + template + requires(requires { T::FORMTYPE; }) + [[nodiscard]] const T* As() const noexcept; + + template T> + requires(!requires { T::FORMTYPE; }) + [[nodiscard]] const T* As() const noexcept; [[nodiscard]] TESObjectREFR* AsReference() { return AsReference1(); } [[nodiscard]] const TESObjectREFR* AsReference() const { return AsReference2(); } diff --git a/src/RE/B/BSFixedString.cpp b/src/RE/B/BSFixedString.cpp index b021ef859..ff28a86e0 100644 --- a/src/RE/B/BSFixedString.cpp +++ b/src/RE/B/BSFixedString.cpp @@ -4,6 +4,127 @@ namespace RE { namespace detail { + template + BSFixedString::BSFixedString(const BSFixedString& a_rhs) : + _data(a_rhs._data) + { + try_acquire(); + } + + template + BSFixedString::BSFixedString(BSFixedString&& a_rhs) noexcept : + _data(a_rhs._data) + { + a_rhs._data = nullptr; + } + + template + BSFixedString::BSFixedString(const_pointer a_string) + { + if (a_string) { + ctor(a_string); + } + } + + template + BSFixedString::BSFixedString(std::basic_string_view a_view) + { + if (!a_view.empty()) { + ctor(a_view.data()); + } + } + + template + BSFixedString::~BSFixedString() + { + try_release(); + } + + template + BSFixedString& BSFixedString::operator=(const BSFixedString& a_rhs) + { + if (this != std::addressof(a_rhs)) { + try_release(); + _data = a_rhs._data; + try_acquire(); + } + return *this; + } + + template + BSFixedString& BSFixedString::operator=(BSFixedString&& a_rhs) noexcept + { + if (this != std::addressof(a_rhs)) { + try_release(); + _data = a_rhs._data; + a_rhs._data = nullptr; + } + return *this; + } + + template + BSFixedString& BSFixedString::operator=(const_pointer a_string) + { + try_release(); + if (a_string) { + ctor(a_string); + } + return *this; + } + + template + BSFixedString& BSFixedString::operator=(std::basic_string_view a_view) + { + try_release(); + if (!a_view.empty()) { + ctor(a_view.data()); + } + return *this; + } + + template + BSFixedString* BSFixedString::ctor(const char* a_data) + { + return ctor8(a_data); + } + + template + BSFixedString* BSFixedString::ctor(const wchar_t* a_data) + { + return ctor16(a_data); + } + + template + BSFixedString* BSFixedString::ctor8(const char* a_data) + { + using func_t = decltype(&BSFixedString::ctor8); + REL::Relocation func{ STATIC_OFFSET(BSFixedString::Ctor8) }; + return func(this, a_data); + } + + template + BSFixedString* BSFixedString::ctor16(const wchar_t* a_data) + { + using func_t = decltype(&BSFixedString::ctor16); + REL::Relocation func{ STATIC_OFFSET(BSFixedString::Ctor16) }; + return func(this, a_data); + } + + template + void BSFixedString::try_acquire() + { + const auto proxy = get_proxy(); + if (proxy) { + proxy->acquire(); + } + } + + template + void BSFixedString::try_release() + { + BSStringPool::Entry::release(_data); + } + template class BSFixedString; static_assert(sizeof(BSFixedString) == 0x8); diff --git a/src/RE/T/TutorialMenu.cpp b/src/RE/T/TutorialMenu.cpp index 8cc685da4..14f66ad51 100644 --- a/src/RE/T/TutorialMenu.cpp +++ b/src/RE/T/TutorialMenu.cpp @@ -3,6 +3,7 @@ #include "RE/B/BGSMessage.h" #include "RE/B/BSTArray.h" #include "RE/C/CRC.h" +#include "RE/F/FormTraits.h" #include "RE/I/INISettingCollection.h" #include "RE/T/TESFile.h" #include "RE/T/TESFormUIData.h"