diff --git a/ChangeLog b/ChangeLog index a23252c..78cb180 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2025-04-19 Bruno Haible + + Optimize: Minimize object references in find_asso_values. + This reduces the execution time of gperf on large inputs by ca. 4%. + * src/search.cc (Search::find_asso_values): Cache some values in local + variables. + 2025-04-19 Bruno Haible Optimize: Use a hash table in compute_partition. diff --git a/src/search.cc b/src/search.cc index aa45a42..f6e83db 100644 --- a/src/search.cc +++ b/src/search.cc @@ -1334,6 +1334,11 @@ Search::find_asso_values () for (;;) { + /* Cache some values in local variables, for speed. */ + bool hash_includes_len = _hash_includes_len; + bool *undetermined = step->_undetermined; + int *asso_values = _asso_values; + /* Test whether these asso_values[] lead to collisions among the equivalence classes that should be collision-free. */ bool has_collision = false; @@ -1350,12 +1355,12 @@ Search::find_asso_values () the yet undetermined asso_values[]. */ int hashcode; { - int sum = _hash_includes_len ? keyword->_allchars_length : 0; + int sum = hash_includes_len ? keyword->_allchars_length : 0; const unsigned int *p = keyword->_selchars; int i = keyword->_selchars_length; for (; i > 0; p++, i--) - if (!step->_undetermined[*p]) - sum += _asso_values[*p]; + if (!undetermined[*p]) + sum += asso_values[*p]; hashcode = sum; }