On Thu, 2 Mar 2023 at 19:58, David Rowley <dgrowle...@gmail.com> wrote: > > I think I'd prefer to see the size_bytes_unit_alias struct have an > index into size_pretty_units[] array. i.e: > > struct size_bytes_unit_alias > { > const char *alias; /* aliased unit name */ > const int unit_index; /* corresponding size_pretty_units element */ > }; > > then the pg_size_bytes code can be simplified to: > > /* If not found, look in the table of aliases */ > if (unit->name == NULL) > { > for (const struct size_bytes_unit_alias *a = size_bytes_aliases; > a->alias != NULL; a++) > { > if (pg_strcasecmp(strptr, a->alias) == 0) > { > unit = &size_pretty_units[a->unit_index]; > break; > } > } > } > > which saves having to have the additional and slower nested loop code. >
Hmm, I think it would be easier to just have a separate table for pg_size_bytes(), rather than reusing pg_size_pretty()'s table. I.e., size_bytes_units[], which would only need name and multiplier columns (not round and limit). Done that way, it would be easier to add other units later (e.g., non-base-2 units). Also, it looks to me as though the doc change is for pg_size_pretty() instead of pg_size_bytes(). Regards, Dean