On Mon, 27 Feb 2023 at 21:34, Peter Eisentraut <peter.eisentr...@enterprisedb.com> wrote: > > On 22.02.23 03:39, David Rowley wrote: > > I think you'll need to find another way to make the aliases work. > > Maybe another array with the name and an int to reference the > > corresponding index in size_pretty_units. > > Ok, here is a new patch with a separate table of aliases. (Might look > like overkill, but I think the "PiB" etc. example you had could actually > be a good use case for this as well.)
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. Apart from that, the patch looks fine. David