8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-23 02:03:04 +01:00

Named constant instead of magic numbers to please Adriano

This commit is contained in:
Dimitry Sibiryakov 2016-03-31 14:45:25 +02:00
parent c3858e1e65
commit 09c986cb56

View File

@ -851,7 +851,9 @@ int CLIB_ROUTINE main( int argc, char *argv[])
SLONG hash_max_count = 0; SLONG hash_max_count = 0;
SLONG hash_min_count = 10000000; SLONG hash_min_count = 10000000;
USHORT i = 0; USHORT i = 0;
unsigned int distribution[21] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; static const int MAX_MAX_COUNT_STATS = 21;
static const int LAST_MAX_COUNT_INDEX = MAX_MAX_COUNT_STATS - 1;
unsigned int distribution[MAX_MAX_COUNT_STATS] = {0}; // C++11 default brace initialization to zero
for (const srq* slot = LOCK_header->lhb_hash; i < LOCK_header->lhb_hash_slots; slot++, i++) for (const srq* slot = LOCK_header->lhb_hash; i < LOCK_header->lhb_hash_slots; slot++, i++)
{ {
SLONG hash_lock_count = 0; SLONG hash_lock_count = 0;
@ -865,8 +867,8 @@ int CLIB_ROUTINE main( int argc, char *argv[])
hash_min_count = hash_lock_count; hash_min_count = hash_lock_count;
if (hash_lock_count > hash_max_count) if (hash_lock_count > hash_max_count)
hash_max_count = hash_lock_count; hash_max_count = hash_lock_count;
if (hash_lock_count > 20) if (hash_lock_count > LAST_MAX_COUNT_INDEX)
hash_lock_count = 20; hash_lock_count = LAST_MAX_COUNT_INDEX;
++distribution[hash_lock_count]; ++distribution[hash_lock_count];
} }
@ -876,15 +878,16 @@ int CLIB_ROUTINE main( int argc, char *argv[])
hash_min_count, (hash_total_count / LOCK_header->lhb_hash_slots), hash_min_count, (hash_total_count / LOCK_header->lhb_hash_slots),
hash_max_count); hash_max_count);
// Hash distribution testing output. To be removed unless is considered useful for end users.
FPRINTF(outfile, "\tHash lengths distribution:\n"); FPRINTF(outfile, "\tHash lengths distribution:\n");
if (hash_max_count >= 20) if (hash_max_count >= LAST_MAX_COUNT_INDEX)
hash_max_count = 19; hash_max_count = LAST_MAX_COUNT_INDEX - 1;
for (int i = hash_min_count; i<=hash_max_count; ++i) for (int i = hash_min_count; i<=hash_max_count; ++i)
{ {
FPRINTF(outfile, "\t\t%-2d : %8u\t(%d%%)\n", i, distribution[i], distribution[i]*100/LOCK_header->lhb_hash_slots); FPRINTF(outfile, "\t\t%-2d : %8u\t(%d%%)\n", i, distribution[i], distribution[i] * 100 / LOCK_header->lhb_hash_slots);
} }
if (hash_max_count == 19) if (hash_max_count == LAST_MAX_COUNT_INDEX - 1)
FPRINTF(outfile, "\t\t> : %8u\t(%d%%)\n", distribution[20], distribution[20]*100/LOCK_header->lhb_hash_slots); FPRINTF(outfile, "\t\t> : %8u\t(%d%%)\n", distribution[LAST_MAX_COUNT_INDEX], distribution[LAST_MAX_COUNT_INDEX] * 100 / LOCK_header->lhb_hash_slots);
const shb* a_shb = (shb*) SRQ_ABS_PTR(LOCK_header->lhb_secondary); const shb* a_shb = (shb*) SRQ_ABS_PTR(LOCK_header->lhb_secondary);
FPRINTF(outfile, FPRINTF(outfile,