Skip to content

Commit

Permalink
remove <optional> include, use 'auto' for type deduction, and clarify…
Browse files Browse the repository at this point in the history
… null-termination checks
  • Loading branch information
farukeryilmaz committed Jan 3, 2024
1 parent e5dc014 commit 372e59d
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions include/bytepack/bytepack.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#include <cstdint>
#include <algorithm>
#include <concepts>
#include <optional>
#include <vector>
#include <array>

Expand Down Expand Up @@ -264,7 +263,7 @@ class binary_stream final
return false;
}

const SizeType size_custom = static_cast<SizeType>(vector.size());
const auto size_custom = static_cast<SizeType>(vector.size());
if ((std::is_signed_v<SizeType> && size_custom < 0) || static_cast<std::size_t>(size_custom) != vector.size()) {
// Overflow or incorrect size type
return false;
Expand Down Expand Up @@ -320,7 +319,7 @@ class binary_stream final
template<IntegralType SizeType = std::uint32_t, NetworkSerializableString StringType>
bool write(const StringType& value) noexcept
{
const SizeType str_length = static_cast<SizeType>(value.length());
const auto str_length = static_cast<SizeType>(value.length());
if ((std::is_signed_v<SizeType> && str_length < 0) || static_cast<std::size_t>(str_length) != value.length()) {
// Overflow or incorrect size type
return false;
Expand Down Expand Up @@ -485,7 +484,7 @@ class binary_stream final
if (read(size_custom) == false || size_custom < 1) {
return false;
}
const std::size_t size = static_cast<std::size_t>(size_custom);
const auto size = static_cast<std::size_t>(size_custom);

if (buffer_.size() < (read_index_ + size * sizeof(T))) {
return false;
Expand Down Expand Up @@ -588,7 +587,7 @@ class binary_stream final
// search-like method is more efficient for such strings, as it exponentially narrows the search space, quickly
// finding the initial null character, thus enhancing performance for longer lengths.
const std::size_t null_pos = value.find('\0');
if (null_pos != value.npos) {
if (null_pos != std::string::npos) {
// If the string in the buffer is null-terminated, resize the string to the actual length
value.resize(null_pos);
}
Expand Down

0 comments on commit 372e59d

Please sign in to comment.