Skip to content

Commit b87d70d

Browse files
committed
approach 3
1 parent 0180d0f commit b87d70d

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

include/boost/json/detail/digest.hpp

+14-6
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,23 @@ digest(
3232
#endif
3333
hash += salt;
3434

35-
char const* const end = s + n;
36-
for(;s < end;)
35+
constexpr std::size_t step = sizeof(std::size_t);
36+
auto const m = n - (n % step);
37+
n -= m;
38+
39+
char const* const end = s + m;
40+
for(; s < end; s += step)
3741
{
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;
42+
std::size_t batch;
4143
std::memcpy(&batch, s, step);
4244
hash = (batch ^ hash) * prime;
43-
s += step;
45+
}
46+
47+
if(n)
48+
{
49+
std::size_t batch = 0;
50+
std::memcpy(&batch, s, n);
51+
hash = (batch ^ hash) * prime;
4452
}
4553

4654
return hash;

0 commit comments

Comments
 (0)