Skip to content

Commit 0180d0f

Browse files
committed
approach 2
1 parent 6eeee0a commit 0180d0f

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

include/boost/json/detail/digest.hpp

+6-10
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,17 @@ digest(
3232
#endif
3333
hash += salt;
3434

35-
constexpr std::size_t step = sizeof(std::size_t);
36-
std::size_t const m = n - (n % step);
37-
n -= m;
38-
39-
char const* const end = s + m;
40-
for(; s < end; s += step)
35+
char const* const end = s + n;
36+
for(;s < end;)
4137
{
42-
std::size_t batch;
38+
std::size_t step = (std::min)(sizeof(std::size_t),
39+
static_cast<std::size_t>(end - s));
40+
std::size_t batch = 0;
4341
std::memcpy(&batch, s, step);
4442
hash = (batch ^ hash) * prime;
43+
s += step;
4544
}
4645

47-
for (; s < end + n; ++s)
48-
hash = (*s ^ hash) * prime;
49-
5046
return hash;
5147
}
5248

0 commit comments

Comments
 (0)