From: | David Rowley <dgrowleyml(at)gmail(dot)com> |
---|---|
To: | Peter Eisentraut <peter(dot)eisentraut(at)enterprisedb(dot)com> |
Cc: | Justin Pryzby <pryzby(at)telsasoft(dot)com>, pgsql-hackers(at)postgresql(dot)org |
Subject: | Re: Add support for unit "B" to pg_size_pretty() |
Date: | 2023-03-02 19:58:02 |
Message-ID: | CAApHDvpzxuo5F8-zbDoK7ZFmVjMbvVK3XQjNcZZuGcMhBc0V5w@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On Mon, 27 Feb 2023 at 21:34, Peter Eisentraut
<peter(dot)eisentraut(at)enterprisedb(dot)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
From | Date | Subject | |
---|---|---|---|
Next Message | Jacob Champion | 2023-03-02 20:04:34 | Re: Auth extensions, with an LDAP/SCRAM example [was: Proposal: Support custom authentication methods using hooks] |
Previous Message | Jeff Davis | 2023-03-02 19:45:51 | Re: Minimal logical decoding on standbys |