Skip to content

Commit 89ab2c9

Browse files
committed
Improve comments
1 parent f8cc68d commit 89ab2c9

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

Objects/stringlib/find_max_char.h

+5-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ STRINGLIB(find_max_char)(const STRINGLIB_CHAR *begin, const STRINGLIB_CHAR *end)
2525
const unsigned char *size_t_end = _end - SIZEOF_SIZE_T;
2626
const unsigned char *unrolled_end = _end - (4 * SIZEOF_SIZE_T - 1);
2727
while (p < unrolled_end) {
28-
/* Test chunks of 32 as more granularity limits compiler optimization */
28+
/* Chunks of 4 size_t values allow for compiler optimizations using vectors */
2929
const size_t *restrict _p = (const size_t *)p;
3030
size_t value0;
3131
size_t value1;
@@ -50,8 +50,11 @@ STRINGLIB(find_max_char)(const STRINGLIB_CHAR *begin, const STRINGLIB_CHAR *end)
5050
accumulator |= value;
5151
p += SIZEOF_SIZE_T;
5252
}
53+
/* In the end there will be up to SIZEOF_SIZE_T leftover characters. It is
54+
faster to do an unaligned load of a size_t integer at an offset from
55+
the end rather than breaking it up into single bytes. However, if the
56+
string is smaller than SIZEOF_SIZE_T this strategy is illegal. */
5357
if (size_t_end >= (const unsigned char*)begin) {
54-
/* Do unaligned size_t load rather than loading bytes individually. */
5558
size_t value;
5659
memcpy(&value, size_t_end, SIZEOF_SIZE_T);
5760
accumulator |= value;

0 commit comments

Comments
 (0)