mirror of
https://github.com/postgres/postgres.git
synced 2025-11-24 00:23:06 +03:00
Suppress compiler warnings in new pgstats code.
Some clang versions whine about comparing an enum variable to a value outside the range of the enum, on the grounds that the result must be constant. In the cases we fix here, the loops will terminate only if the enum variable can in fact hold a value one beyond its declared range. While that's very likely to always be true for these enum types, it still seems like a poor coding practice to assume it; so use "int" loop variables instead to silence the warnings. (This matches what we've done in other places, for example loops over the range of ForkNumber.) While at it, let's drop the XXX_FIRST macros for these enums and just write zeroes for the loop start values. The apparent flexibility seems rather illusory given that iterating up to one-less-than- the-number-of-values is only correct for a zero-based range. Melanie Plageman Discussion: https://postgr.es/m/20520.1677435600@sss.pgh.pa.us
This commit is contained in:
@@ -36,18 +36,16 @@ pgstat_bktype_io_stats_valid(PgStat_BktypeIO *backend_io,
|
||||
{
|
||||
bool bktype_tracked = pgstat_tracks_io_bktype(bktype);
|
||||
|
||||
for (IOObject io_object = IOOBJECT_FIRST;
|
||||
io_object < IOOBJECT_NUM_TYPES; io_object++)
|
||||
for (int io_object = 0; io_object < IOOBJECT_NUM_TYPES; io_object++)
|
||||
{
|
||||
for (IOContext io_context = IOCONTEXT_FIRST;
|
||||
io_context < IOCONTEXT_NUM_TYPES; io_context++)
|
||||
for (int io_context = 0; io_context < IOCONTEXT_NUM_TYPES; io_context++)
|
||||
{
|
||||
/*
|
||||
* Don't bother trying to skip to the next loop iteration if
|
||||
* pgstat_tracks_io_object() would return false here. We still
|
||||
* need to validate that each counter is zero anyway.
|
||||
*/
|
||||
for (IOOp io_op = IOOP_FIRST; io_op < IOOP_NUM_TYPES; io_op++)
|
||||
for (int io_op = 0; io_op < IOOP_NUM_TYPES; io_op++)
|
||||
{
|
||||
/* No stats, so nothing to validate */
|
||||
if (backend_io->data[io_object][io_context][io_op] == 0)
|
||||
@@ -111,14 +109,11 @@ pgstat_flush_io(bool nowait)
|
||||
else if (!LWLockConditionalAcquire(bktype_lock, LW_EXCLUSIVE))
|
||||
return true;
|
||||
|
||||
for (IOObject io_object = IOOBJECT_FIRST;
|
||||
io_object < IOOBJECT_NUM_TYPES; io_object++)
|
||||
for (int io_object = 0; io_object < IOOBJECT_NUM_TYPES; io_object++)
|
||||
{
|
||||
for (IOContext io_context = IOCONTEXT_FIRST;
|
||||
io_context < IOCONTEXT_NUM_TYPES; io_context++)
|
||||
for (int io_context = 0; io_context < IOCONTEXT_NUM_TYPES; io_context++)
|
||||
{
|
||||
for (IOOp io_op = IOOP_FIRST;
|
||||
io_op < IOOP_NUM_TYPES; io_op++)
|
||||
for (int io_op = 0; io_op < IOOP_NUM_TYPES; io_op++)
|
||||
bktype_shstats->data[io_object][io_context][io_op] +=
|
||||
PendingIOStats.data[io_object][io_context][io_op];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user