diff --git a/ChangeLog b/ChangeLog index e5fc85e..f232c55 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2025-04-19 Bruno Haible + + Optimize: Make Bool_Array take less memory. + Less memory means: less cache misses. + This reduces the execution time of gperf on large inputs by ca. 2.5%. + * src/bool-array.h (Bool_Array): For the _storage_array and + _iteration_number fields, use 'unsigned char' instead of 'unsigned int'. + * src/bool-array.icc (Bool_Array::Bool_Array, Bool_Array::clear: Update. + * src/bool-array.cc (Bool_Array::~Bool_Array): Update. + 2025-04-19 Bruno Haible tests: Add unit test with many keywords. diff --git a/src/bool-array.cc b/src/bool-array.cc index c181a7a..5998575 100644 --- a/src/bool-array.cc +++ b/src/bool-array.cc @@ -35,7 +35,7 @@ Bool_Array::~Bool_Array () fprintf (stderr, "\ndumping boolean array information\n" "size = %d\niteration number = %d\nend of array dump\n", _size, _iteration_number); - delete[] const_cast(_storage_array); + delete[] const_cast(_storage_array); } #ifndef __OPTIMIZE__ diff --git a/src/bool-array.h b/src/bool-array.h index 6167d38..c62fefa 100644 --- a/src/bool-array.h +++ b/src/bool-array.h @@ -2,7 +2,7 @@ /* Simple lookup table abstraction implemented as an Iteration Number Array. - Copyright (C) 1989-1998, 2002 Free Software Foundation, Inc. + Copyright (C) 1989-1998, 2002, 2025 Free Software Foundation, Inc. Written by Douglas C. Schmidt and Bruno Haible . @@ -56,11 +56,11 @@ private: /* Current iteration number. Always nonzero. Starts out as 1, and is incremented each time clear() is called. */ - unsigned int _iteration_number; + unsigned char _iteration_number; /* For each index, we store in storage_array[index] the iteration_number at the time set_bit(index) was last called. */ - unsigned int * const _storage_array; + unsigned char * const _storage_array; }; #ifdef __OPTIMIZE__ /* efficiency hack! */ diff --git a/src/bool-array.icc b/src/bool-array.icc index e913656..20f8489 100644 --- a/src/bool-array.icc +++ b/src/bool-array.icc @@ -1,6 +1,6 @@ /* Inline Functions for bool-array.{h,cc}. - Copyright (C) 1989-1998, 2002 Free Software Foundation, Inc. + Copyright (C) 1989-1998, 2002, 2025 Free Software Foundation, Inc. Written by Douglas C. Schmidt and Bruno Haible . @@ -30,7 +30,7 @@ INLINE Bool_Array::Bool_Array (unsigned int size) : _size (size), _iteration_number (1), - _storage_array (new unsigned int [size]) + _storage_array (new unsigned char [size]) { memset (_storage_array, 0, size * sizeof (_storage_array[0])); if (option[DEBUG]) @@ -60,8 +60,8 @@ INLINE void Bool_Array::clear () { /* If we wrap around it's time to zero things out again! However, this only - occurs once about every 2^32 iterations, so it will not happen more - frequently than once per second. */ + occurs once about every 2^8 iterations, so it does not take much time on + average. */ if (++_iteration_number == 0) {