Commit b3c7d25
authored
[ADT] Use a C++17 fold expression in hash_combine (NFC) (#159901)
combine() combines hash values with recursion on variadic parameters.
This patch replaces the recursion with a C++17 fold expression:
(combine_data(length, buffer_ptr, buffer_end, get_hashable_data(args)),
...);
which expands to:
combine_data(length, buffer_ptr, buffer_end, get_hashable_data(a));
combine_data(length, buffer_ptr, buffer_end, get_hashable_data(b));
combine_data(length, buffer_ptr, buffer_end, get_hashable_data(c));
:
A key benefit of this change is the unification of the recursive step
and the base case. The argument processing and finalization logic now
exist as straight-line code within a single function.
combine_data now takes buffer_ptr by reference. This is necessary
because the previous assignment pattern:
buffer_ptr = combine_data(...)
is syntactically incompatible with a fold expression. The new pattern:
(combine_data(...), ...)
discards return values, so combine_data must update buffer_ptr
directly.
For readability, this patch does the bare minimum to use a fold
expression, leaving further cleanups to subsequent patches. For
example, buffer_ptr and buffer_end could become member variables, and
several comments that mention recursion still need updating.1 parent 507f394 commit b3c7d25
1 file changed
+9
-14
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
503 | 503 | | |
504 | 504 | | |
505 | 505 | | |
506 | | - | |
| 506 | + | |
| 507 | + | |
507 | 508 | | |
508 | 509 | | |
509 | 510 | | |
| |||
541 | 542 | | |
542 | 543 | | |
543 | 544 | | |
544 | | - | |
| 545 | + | |
545 | 546 | | |
546 | | - | |
547 | | - | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
548 | 551 | | |
549 | | - | |
550 | | - | |
551 | | - | |
552 | | - | |
553 | | - | |
554 | | - | |
555 | | - | |
556 | | - | |
557 | | - | |
558 | | - | |
| 552 | + | |
| 553 | + | |
559 | 554 | | |
560 | 555 | | |
561 | 556 | | |
| |||
0 commit comments