diff --git a/deps/ox/src/ox/std/CMakeLists.txt b/deps/ox/src/ox/std/CMakeLists.txt index 6163ec2e..9ece6e61 100644 --- a/deps/ox/src/ox/std/CMakeLists.txt +++ b/deps/ox/src/ox/std/CMakeLists.txt @@ -97,6 +97,7 @@ install( new.hpp optional.hpp random.hpp + ranges.hpp serialize.hpp std.hpp stddef.hpp diff --git a/deps/ox/src/ox/std/memops.cpp b/deps/ox/src/ox/std/memops.cpp index 0a817f8d..b888fe2d 100644 --- a/deps/ox/src/ox/std/memops.cpp +++ b/deps/ox/src/ox/std/memops.cpp @@ -27,13 +27,8 @@ void *ox_inhibit_loop_to_libcall memset(void *ptr, int val, std::size_t size) { return ox_memset(ptr, val, size); } -} -#undef ox_inhibit_loop_to_libcall - -#endif - -int ox_memcmp(const void *ptr1, const void *ptr2, std::size_t size) noexcept { +int ox_inhibit_loop_to_libcall memcmp(const void *ptr1, const void *ptr2, std::size_t size) noexcept { int retval = 0; auto block1 = reinterpret_cast(ptr1); auto block2 = reinterpret_cast(ptr2); @@ -48,3 +43,13 @@ int ox_memcmp(const void *ptr1, const void *ptr2, std::size_t size) noexcept { } return retval; } + +} + +#undef ox_inhibit_loop_to_libcall + +#endif + +int ox_memcmp(const void *ptr1, const void *ptr2, std::size_t size) noexcept { + return memcmp(ptr1, ptr2, size); +} diff --git a/deps/ox/src/ox/std/memops.hpp b/deps/ox/src/ox/std/memops.hpp index 77ea1e06..d8916df5 100644 --- a/deps/ox/src/ox/std/memops.hpp +++ b/deps/ox/src/ox/std/memops.hpp @@ -23,6 +23,8 @@ void *memmove(void *dest, const void *src, std::size_t size); void *memset(void *ptr, int val, std::size_t size); +int memcmp(const void *ptr1, const void *ptr2, std::size_t size) noexcept; + } #endif @@ -68,10 +70,22 @@ constexpr void *ox_memset(void *ptr, int val, std::size_t size) noexcept { namespace ox { +constexpr void *memmove(void *dest, const void *src, std::size_t size) { + return ox_memmove(dest, src, size); +} + +constexpr void *memset(void *ptr, int val, std::size_t size) noexcept { + return ox_memset(ptr, val, size); +} + constexpr void *memcpy(void *dest, const void *src, std::size_t size) noexcept { return ox_memcpy(dest, src, size); } +inline int memcmp(const void *ptr1, const void *ptr2, std::size_t size) noexcept { + return ox_memcmp(ptr1, ptr2, size); +} + template void *memsetElements(T *ptr, T val, std::size_t elements) noexcept { return memset(ptr, val, elements * sizeof(T)); diff --git a/deps/ox/src/ox/std/random.hpp b/deps/ox/src/ox/std/random.hpp index f07821bd..a43ba0c4 100644 --- a/deps/ox/src/ox/std/random.hpp +++ b/deps/ox/src/ox/std/random.hpp @@ -8,6 +8,7 @@ #pragma once +#include "bit.hpp" #include "stddef.hpp" #include "types.hpp" diff --git a/deps/ox/src/ox/std/ranges.hpp b/deps/ox/src/ox/std/ranges.hpp new file mode 100644 index 00000000..5b2f6bd9 --- /dev/null +++ b/deps/ox/src/ox/std/ranges.hpp @@ -0,0 +1,35 @@ +/* + * Copyright 2015 - 2023 gary@drinkingtea.net + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + */ + +#pragma once + +namespace ox { + +[[nodiscard]] +constexpr bool all_of(auto begin, auto end, auto pred) noexcept { + while (begin != end) { + if (!pred(*begin)) { + return false; + } + ++begin; + } + return true; +} + +[[nodiscard]] +constexpr bool any_of(auto begin, auto end, auto pred) noexcept { + while (begin != end) { + if (pred(*begin)) { + return true; + } + ++begin; + } + return false; +} + +} diff --git a/deps/ox/src/ox/std/stringview.hpp b/deps/ox/src/ox/std/stringview.hpp index 978ac32f..369a61d0 100644 --- a/deps/ox/src/ox/std/stringview.hpp +++ b/deps/ox/src/ox/std/stringview.hpp @@ -352,3 +352,19 @@ constexpr auto toStdStringView(CRStringView sv) noexcept { #endif } + +constexpr ox::Result ox_atoi(ox::CRStringView str) noexcept { + int total = 0; + int multiplier = 1; + for (auto i = static_cast(str.len()) - 1; i != -1; --i) { + auto s = static_cast(i); + if (str[s] >= '0' && str[s] <= '9') { + total += (str[s] - '0') * multiplier; + multiplier *= 10; + } else { + return OxError(1); + } + } + return total; +} + diff --git a/deps/ox/src/ox/std/strops.hpp b/deps/ox/src/ox/std/strops.hpp index c9148000..b3e8fbb9 100644 --- a/deps/ox/src/ox/std/strops.hpp +++ b/deps/ox/src/ox/std/strops.hpp @@ -125,20 +125,6 @@ constexpr int ox_lastIndexOf(const auto &str, int character, std::size_t maxLen return retval; } -constexpr ox::Result ox_atoi(const char *str) noexcept { - int total = 0; - int multiplier = 1; - for (auto i = static_cast(ox_strlen(str)) - 1; i != -1; i--) { - if (str[i] >= '0' && str[i] <= '9') { - total += (str[i] - '0') * multiplier; - multiplier *= 10; - } else { - return OxError(1); - } - } - return total; -} - template constexpr T ox_itoa(Integer v, T str) noexcept { if (v) { diff --git a/deps/ox/src/ox/std/uuid.cpp b/deps/ox/src/ox/std/uuid.cpp index a406309a..0978bcca 100644 --- a/deps/ox/src/ox/std/uuid.cpp +++ b/deps/ox/src/ox/std/uuid.cpp @@ -35,6 +35,6 @@ Result UUID::generate() noexcept { } static_assert(UUID{}.isNull()); -static_assert(!UUID::fromString("34AF4809-043D-4348-B720-2B454E5678C7").value.isNull()); +static_assert(!UUID::fromString("34af4809-043d-4348-b720-2b454e5678c7").value.isNull()); } diff --git a/deps/ox/src/ox/std/uuid.hpp b/deps/ox/src/ox/std/uuid.hpp index 833521aa..db743d6e 100644 --- a/deps/ox/src/ox/std/uuid.hpp +++ b/deps/ox/src/ox/std/uuid.hpp @@ -11,6 +11,7 @@ #include "array.hpp" #include "bstring.hpp" #include "random.hpp" +#include "ranges.hpp" #include "stringview.hpp" #include "strops.hpp" #include "trace.hpp" @@ -56,8 +57,8 @@ constexpr ox::Result fromHex(ox::CRStringView v) noexcept { return OxError(2); } uint8_t out = 0; - out += valMap[static_cast(v[0])] * 16u; - out += valMap[static_cast(v[1])]; + out += valMap[static_cast(v[0])] * 16u; + out += valMap[static_cast(v[1])]; return out; } @@ -95,7 +96,7 @@ class UUID { protected: static bool s_seeded; static Random s_rand; - ox::Array m_value; + ox::Array m_value{}; public: static void seedGenerator(const RandomSeed &seed) noexcept; @@ -110,12 +111,10 @@ class UUID { [[nodiscard]] constexpr auto isNull() const noexcept { if (std::is_constant_evaluated()) { - for (auto v : m_value) { - if (v) { - return false; - } + if (ox::all_of(m_value.begin(), m_value.end(), [](auto v) { return v == 0; })) { + return true; } - return true; + return false; } else { constexpr uint64_t zero = 0; return ox::memcmp(&zero, m_value.data() + 0, 8) == 0 @@ -125,7 +124,7 @@ class UUID { static constexpr ox::Result fromString(ox::CRStringView s) noexcept { if (s.len() < 36) { - return OxError(1, "Insufficient data contain complete UUID"); + return OxError(1, "Insufficient data to contain a complete UUID"); } UUID out; auto valueI = 0u;