public inbox for [email protected]
help / color / mirror / Atom feedFrom: David Rowley <[email protected]>
To: Peter Eisentraut <[email protected]>
Cc: Justin Pryzby <[email protected]>
Cc: [email protected]
Subject: Re: Add support for unit "B" to pg_size_pretty()
Date: Fri, 3 Mar 2023 08:58:02 +1300
Message-ID: <CAApHDvpzxuo5F8-zbDoK7ZFmVjMbvVK3XQjNcZZuGcMhBc0V5w@mail.gmail.com> (raw)
In-Reply-To: <[email protected]>
References: <[email protected]>
<[email protected]>
<[email protected]>
<CAApHDvrn9aznj=h1srcjyPpQVBA_B+d7izYvtUa-5ni+GZ7z0A@mail.gmail.com>
<[email protected]>
On Mon, 27 Feb 2023 at 21:34, Peter Eisentraut
<[email protected]> 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
view thread (9+ messages) latest in thread
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected], [email protected], [email protected]
Subject: Re: Add support for unit "B" to pg_size_pretty()
In-Reply-To: <CAApHDvpzxuo5F8-zbDoK7ZFmVjMbvVK3XQjNcZZuGcMhBc0V5w@mail.gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox