1
0
mirror of https://git.savannah.gnu.org/git/gperf.git synced 2025-12-02 13:09:22 +00:00

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.
This commit is contained in:
Bruno Haible
2025-04-19 15:05:22 +02:00
parent 772a63e46d
commit a69b7c1c81
2 changed files with 15 additions and 3 deletions

View File

@@ -1,3 +1,10 @@
2025-04-19 Bruno Haible <bruno@clisp.org>
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 <bruno@clisp.org> 2025-04-19 Bruno Haible <bruno@clisp.org>
Optimize: Use a hash table in compute_partition. Optimize: Use a hash table in compute_partition.

View File

@@ -1334,6 +1334,11 @@ Search::find_asso_values ()
for (;;) 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 /* Test whether these asso_values[] lead to collisions among
the equivalence classes that should be collision-free. */ the equivalence classes that should be collision-free. */
bool has_collision = false; bool has_collision = false;
@@ -1350,12 +1355,12 @@ Search::find_asso_values ()
the yet undetermined asso_values[]. */ the yet undetermined asso_values[]. */
int hashcode; 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; const unsigned int *p = keyword->_selchars;
int i = keyword->_selchars_length; int i = keyword->_selchars_length;
for (; i > 0; p++, i--) for (; i > 0; p++, i--)
if (!step->_undetermined[*p]) if (!undetermined[*p])
sum += _asso_values[*p]; sum += asso_values[*p];
hashcode = sum; hashcode = sum;
} }