diff options
| author | Amlal El Mahrouss <amlal@nekernel.org> | 2025-11-18 14:13:02 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-11-18 14:13:02 +0100 |
| commit | c9fd682f3662e0eec09de49a36a4ea199656da34 (patch) | |
| tree | f6e0c4c52724cd2af4cc6f469506b5552db13c3d /dev | |
| parent | 4fd646501b75cb1d94a6e17d2387372d72ce797b (diff) | |
| parent | 54940e80e0a259f748d483291e0e7aef7dd98353 (diff) | |
Merge pull request #11 from amlel-el-mahrouss/develop
develop->stable: fixes and improvements.
Diffstat (limited to 'dev')
| -rw-r--r-- | dev/lib/core/chunk_string.hpp | 22 | ||||
| -rw-r--r-- | dev/lib/simd/simd.hpp | 3 | ||||
| -rw-r--r-- | dev/tests/chunk_string/chunk_test.cc | 9 |
3 files changed, 27 insertions, 7 deletions
diff --git a/dev/lib/core/chunk_string.hpp b/dev/lib/core/chunk_string.hpp index 4fe5cc2..7e5360c 100644 --- a/dev/lib/core/chunk_string.hpp +++ b/dev/lib/core/chunk_string.hpp @@ -9,6 +9,7 @@ #define OCL_UTILITY_CHUNK_STRING_HPP #include <lib/core/includes.hpp> +#include <lib/io/print.hpp> namespace ocl { @@ -45,6 +46,19 @@ namespace ocl basic_chunk_string(const basic_chunk_string&) = delete; public: + /// @brief Append a std::basic_string to the chunk string. + basic_chunk_string& operator+=(const char_type* in) + { + if (in == nullptr || bad_) + return *this; + + const auto& sz = std::strlen(in); + + this->operator+=(std::basic_string<char_type>(in, sz)); + + return *this; + } + basic_chunk_string& operator+=(const std::basic_string<char_type>& in) { if (in.empty() || bad_) @@ -75,14 +89,18 @@ namespace ocl return *this; } + /// @brief Convert to basic_string or return from cache. std::basic_string<char_type> str() const noexcept { static std::basic_string<char_type> ret; + const auto& sz = ret.size(); - if (ret.size() > 0) + if (chunk_total_ > sz) ret.clear(); + else + return ret; - ret += packed_chunks_; + ret = packed_chunks_; return ret; } diff --git a/dev/lib/simd/simd.hpp b/dev/lib/simd/simd.hpp index e571b23..22650bb 100644 --- a/dev/lib/simd/simd.hpp +++ b/dev/lib/simd/simd.hpp @@ -22,10 +22,11 @@ namespace ocl::snu::simd enum opcode { - bad, + bad = 0, add, mul, div, + invalid = 0xfff, }; public: diff --git a/dev/tests/chunk_string/chunk_test.cc b/dev/tests/chunk_string/chunk_test.cc index 973ce43..7d68ae2 100644 --- a/dev/tests/chunk_string/chunk_test.cc +++ b/dev/tests/chunk_string/chunk_test.cc @@ -11,12 +11,13 @@ TEST(ChunkTest, BasicChunkUsage) { - const std::string test_string = "HELLO, WORLD!"; - const unsigned iterations = 1024000; + const char* test_string = "HELLO, WORLD!\r\n"; + const auto iterations = 1024000; + const auto limit = 30; auto start = std::chrono::high_resolution_clock::now(); - ocl::basic_chunk_string<char, 1000000> optimized; + ocl::basic_chunk_string<char, iterations> optimized; for (unsigned i = 0; i < iterations; ++i) { @@ -26,5 +27,5 @@ TEST(ChunkTest, BasicChunkUsage) auto end = std::chrono::high_resolution_clock::now(); auto optimized_time = std::chrono::duration_cast<std::chrono::milliseconds>(end - start); - EXPECT_TRUE(optimized_time.count() < 30U); + EXPECT_TRUE(optimized_time.count() < limit); } |
