From ebb0a161c33a5f5f11d510f52233935a77893bc3 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 5 Apr 2020 09:03:36 -0400 Subject: [PATCH 01/10] HMDL_RT: Remove unnecessary pointer cast The MemoryReader class already accepts const qualified data, so there's no need to cast away const. --- hecl/lib/Runtime/HMDL_RT.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hecl/lib/Runtime/HMDL_RT.cpp b/hecl/lib/Runtime/HMDL_RT.cpp index 5695a03d1..c9d4cd1b8 100644 --- a/hecl/lib/Runtime/HMDL_RT.cpp +++ b/hecl/lib/Runtime/HMDL_RT.cpp @@ -11,7 +11,7 @@ static logvisor::Module HMDL_Log("HMDL"); HMDLData::HMDLData(boo::IGraphicsDataFactory::Context& ctx, const void* metaData, const void* vbo, const void* ibo) { HMDLMeta meta; { - athena::io::MemoryReader r((atUint8*)metaData, HECL_HMDL_META_SZ); + athena::io::MemoryReader r(metaData, HECL_HMDL_META_SZ); meta.read(r); } if (meta.magic != 'TACO') From 45556184b4250339360ac153ca38b436e6c8576b Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 5 Apr 2020 09:05:34 -0400 Subject: [PATCH 02/10] HMDL_RT: Make use of std::make_unique More straightforward than using raw new within a reset() call. --- hecl/lib/Runtime/HMDL_RT.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hecl/lib/Runtime/HMDL_RT.cpp b/hecl/lib/Runtime/HMDL_RT.cpp index c9d4cd1b8..d70c72135 100644 --- a/hecl/lib/Runtime/HMDL_RT.cpp +++ b/hecl/lib/Runtime/HMDL_RT.cpp @@ -20,8 +20,8 @@ HMDLData::HMDLData(boo::IGraphicsDataFactory::Context& ctx, const void* metaData m_vbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, vbo, meta.vertStride, meta.vertCount); m_ibo = ctx.newStaticBuffer(boo::BufferUse::Index, ibo, 4, meta.indexCount); - size_t elemCount = 2 + meta.colorCount + meta.uvCount + meta.weightCount; - m_vtxFmtData.reset(new boo::VertexElementDescriptor[elemCount]); + const size_t elemCount = 2 + meta.colorCount + meta.uvCount + meta.weightCount; + m_vtxFmtData = std::make_unique(elemCount); m_vtxFmtData[0].semantic = boo::VertexSemantic::Position3; m_vtxFmtData[1].semantic = boo::VertexSemantic::Normal3; From ede801b344867d3155cf81bcf2dedfded5bdecae Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 5 Apr 2020 09:12:25 -0400 Subject: [PATCH 03/10] Project: Use emplace_back where applicable in lockAndRead() Same behavior, but allows for in-place construction. --- hecl/lib/Project.cpp | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/hecl/lib/Project.cpp b/hecl/lib/Project.cpp index 796fb1499..f84ddce66 100644 --- a/hecl/lib/Project.cpp +++ b/hecl/lib/Project.cpp @@ -60,24 +60,27 @@ std::vector& Project::ConfigFile::lockAndRead() { mainString += std::string(readBuf, readSz); } - std::string::const_iterator begin = mainString.begin(); - std::string::const_iterator end = mainString.begin(); + auto begin = mainString.cbegin(); + auto end = mainString.cbegin(); m_lines.clear(); while (end != mainString.end()) { - std::string::const_iterator origEnd = end; - if (*end == '\0') + auto origEnd = end; + if (*end == '\0') { break; - else if (CheckNewLineAdvance(end)) { - if (begin != origEnd) - m_lines.push_back(std::string(begin, origEnd)); + } + if (CheckNewLineAdvance(end)) { + if (begin != origEnd) { + m_lines.emplace_back(begin, origEnd); + } begin = end; continue; } ++end; } - if (begin != end) - m_lines.push_back(std::string(begin, end)); + if (begin != end) { + m_lines.emplace_back(begin, end); + } return m_lines; } From 613b503cd6c51c470c3b6262b8aabad57bf8d822 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 5 Apr 2020 09:13:26 -0400 Subject: [PATCH 04/10] FourCC: Remove constexpr from IStreamReader constructor IStreamReader isn't constexpr, so this will result in a compilation error if used. --- hecl/include/hecl/FourCC.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hecl/include/hecl/FourCC.hpp b/hecl/include/hecl/FourCC.hpp index 24a0f6799..5056a8e87 100644 --- a/hecl/include/hecl/FourCC.hpp +++ b/hecl/include/hecl/FourCC.hpp @@ -63,7 +63,7 @@ public: constexpr DNAFourCC(const FourCC& other) noexcept : FourCC(other) {} constexpr DNAFourCC(const char* name) noexcept : FourCC(name) {} constexpr DNAFourCC(uint32_t n) noexcept : FourCC(n) {} - constexpr DNAFourCC(athena::io::IStreamReader& r) { read(r); } + DNAFourCC(athena::io::IStreamReader& r) { read(r); } AT_DECL_EXPLICIT_DNA_YAML }; template <> From 393e824838885955c73caa68caaba79e222af13d Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 5 Apr 2020 09:16:29 -0400 Subject: [PATCH 05/10] Project: Make checkForLine() a const member function This only ever queries the existence of a line, so it can be made const. --- hecl/lib/Project.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/hecl/lib/Project.cpp b/hecl/lib/Project.cpp index f84ddce66..0fd76e060 100644 --- a/hecl/lib/Project.cpp +++ b/hecl/lib/Project.cpp @@ -1,4 +1,6 @@ #include + +#include #include #include #include @@ -105,16 +107,13 @@ void Project::ConfigFile::removeLine(std::string_view refLine) { } } -bool Project::ConfigFile::checkForLine(std::string_view refLine) { +bool Project::ConfigFile::checkForLine(std::string_view refLine) const { if (!m_lockedFile) { LogModule.reportSource(logvisor::Fatal, __FILE__, __LINE__, fmt("Project::ConfigFile::lockAndRead not yet called")); return false; } - for (const std::string& line : m_lines) - if (line == refLine) - return true; - return false; + return std::any_of(m_lines.cbegin(), m_lines.cend(), [&refLine](const auto& line) { return line == refLine; }); } void Project::ConfigFile::unlockAndDiscard() { From c48303c2c2635c672ab3488b5de9028491de4beb Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 5 Apr 2020 09:21:58 -0400 Subject: [PATCH 06/10] Database: Add missing const qualifier --- hecl/include/hecl/Database.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hecl/include/hecl/Database.hpp b/hecl/include/hecl/Database.hpp index 89563b075..e61d33377 100644 --- a/hecl/include/hecl/Database.hpp +++ b/hecl/include/hecl/Database.hpp @@ -260,7 +260,7 @@ public: std::vector& lockAndRead(); void addLine(std::string_view line); void removeLine(std::string_view refLine); - bool checkForLine(std::string_view refLine); + bool checkForLine(std::string_view refLine) const; void unlockAndDiscard(); bool unlockAndCommit(); }; From 1a031f54c48487f0b1269dc5abb0c7ca5dc2cfc2 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 5 Apr 2020 09:22:25 -0400 Subject: [PATCH 07/10] ProjectPath: Remove unused file-scope std::regex instance Same behavior, minus an unnecessary heap allocation on program start. --- hecl/lib/ProjectPath.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/hecl/lib/ProjectPath.cpp b/hecl/lib/ProjectPath.cpp index dfaf2f9de..b17334cf4 100644 --- a/hecl/lib/ProjectPath.cpp +++ b/hecl/lib/ProjectPath.cpp @@ -7,7 +7,6 @@ namespace hecl { static const SystemRegex regPATHCOMP(_SYS_STR("[/\\\\]*([^/\\\\]+)"), SystemRegex::ECMAScript | SystemRegex::optimize); -static const SystemRegex regDRIVELETTER(_SYS_STR("^([^/]*)/"), SystemRegex::ECMAScript | SystemRegex::optimize); static SystemString CanonRelPath(SystemStringView path) { /* Tokenize Path */ From caca49b3bd8319a510e571bf13a74dbe7bff8ee4 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 5 Apr 2020 09:26:27 -0400 Subject: [PATCH 08/10] UniformBufferPool: Make Token move constructor and move assignment noexcept Allows the type to be used with containers and facilities that make use of std::move_if_noexcept, etc. --- hecl/include/hecl/UniformBufferPool.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hecl/include/hecl/UniformBufferPool.hpp b/hecl/include/hecl/UniformBufferPool.hpp index b2a2f117e..925ec073d 100644 --- a/hecl/include/hecl/UniformBufferPool.hpp +++ b/hecl/include/hecl/UniformBufferPool.hpp @@ -129,14 +129,14 @@ public: Token() = default; Token(const Token& other) = delete; Token& operator=(const Token& other) = delete; - Token& operator=(Token&& other) { + Token& operator=(Token&& other) noexcept { m_pool = other.m_pool; m_index = other.m_index; m_div = other.m_div; other.m_index = -1; return *this; } - Token(Token&& other) : m_pool(other.m_pool), m_index(other.m_index), m_div(other.m_div) { other.m_index = -1; } + Token(Token&& other) noexcept : m_pool(other.m_pool), m_index(other.m_index), m_div(other.m_div) { other.m_index = -1; } ~Token() { if (m_index != -1) { From b5a26d5136349365c2d1ae713e8ba1c38fe167c4 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 5 Apr 2020 09:28:03 -0400 Subject: [PATCH 09/10] VertexBufferPool: Make Token move constructor and move assignment noexcept Same behavior, but allows the type to be used nicely with containers and move facilities that rely on std::move_if_noexcept. --- hecl/include/hecl/VertexBufferPool.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hecl/include/hecl/VertexBufferPool.hpp b/hecl/include/hecl/VertexBufferPool.hpp index fa71fc3ba..8489245ed 100644 --- a/hecl/include/hecl/VertexBufferPool.hpp +++ b/hecl/include/hecl/VertexBufferPool.hpp @@ -132,7 +132,7 @@ public: Token() = default; Token(const Token& other) = delete; Token& operator=(const Token& other) = delete; - Token& operator=(Token&& other) { + Token& operator=(Token&& other) noexcept { m_pool = other.m_pool; m_index = other.m_index; m_count = other.m_count; @@ -140,7 +140,7 @@ public: other.m_index = -1; return *this; } - Token(Token&& other) : m_pool(other.m_pool), m_index(other.m_index), m_count(other.m_count), m_div(other.m_div) { + Token(Token&& other) noexcept : m_pool(other.m_pool), m_index(other.m_index), m_count(other.m_count), m_div(other.m_div) { other.m_index = -1; } From 57fa706311e838f3a9efca468160fe67f30487a1 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 5 Apr 2020 09:34:22 -0400 Subject: [PATCH 10/10] hecl: Allow Time instances to be constexpr Some constructors accept primitive values. These can be made constexpr. --- hecl/include/hecl/hecl.hpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/hecl/include/hecl/hecl.hpp b/hecl/include/hecl/hecl.hpp index 37e43ca2e..44fd9598c 100644 --- a/hecl/include/hecl/hecl.hpp +++ b/hecl/include/hecl/hecl.hpp @@ -485,20 +485,20 @@ class Time final { time_t ts; public: - Time() : ts(time(NULL)) {} - Time(time_t ti) : ts(ti) {} - Time(const Time& other) { ts = other.ts; } - time_t getTs() const { return ts; } - Time& operator=(const Time& other) { + Time() : ts(std::time(nullptr)) {} + constexpr Time(time_t ti) noexcept : ts{ti} {} + constexpr Time(const Time& other) noexcept : ts{other.ts} {} + [[nodiscard]] constexpr time_t getTs() const { return ts; } + constexpr Time& operator=(const Time& other) noexcept { ts = other.ts; return *this; } - bool operator==(const Time& other) const { return ts == other.ts; } - bool operator!=(const Time& other) const { return ts != other.ts; } - bool operator<(const Time& other) const { return ts < other.ts; } - bool operator>(const Time& other) const { return ts > other.ts; } - bool operator<=(const Time& other) const { return ts <= other.ts; } - bool operator>=(const Time& other) const { return ts >= other.ts; } + [[nodiscard]] constexpr bool operator==(const Time& other) const noexcept { return ts == other.ts; } + [[nodiscard]] constexpr bool operator!=(const Time& other) const noexcept { return ts != other.ts; } + [[nodiscard]] constexpr bool operator<(const Time& other) const noexcept { return ts < other.ts; } + [[nodiscard]] constexpr bool operator>(const Time& other) const noexcept { return ts > other.ts; } + [[nodiscard]] constexpr bool operator<=(const Time& other) const noexcept { return ts <= other.ts; } + [[nodiscard]] constexpr bool operator>=(const Time& other) const noexcept { return ts >= other.ts; } }; /**