mirror of
https://git.savannah.gnu.org/git/gperf.git
synced 2025-12-02 13:09:22 +00:00
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.
This commit is contained in:
10
ChangeLog
10
ChangeLog
@@ -1,3 +1,13 @@
|
||||
2025-04-19 Bruno Haible <bruno@clisp.org>
|
||||
|
||||
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 <bruno@clisp.org>
|
||||
|
||||
tests: Add unit test with many keywords.
|
||||
|
||||
@@ -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<unsigned int *>(_storage_array);
|
||||
delete[] const_cast<unsigned char *>(_storage_array);
|
||||
}
|
||||
|
||||
#ifndef __OPTIMIZE__
|
||||
|
||||
@@ -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 <schmidt@ics.uci.edu>
|
||||
and Bruno Haible <bruno@clisp.org>.
|
||||
|
||||
@@ -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! */
|
||||
|
||||
@@ -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 <schmidt@ics.uci.edu>
|
||||
and Bruno Haible <bruno@clisp.org>.
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user