Re: Speedup usages of pg_*toa() functions
Ranier Vilela <ranier.vf@gmail.com>
From: Ranier Vilela <ranier.vf@gmail.com>
To: Andrew Gierth <andrew@tao11.riddles.org.uk>
Cc: David Rowley <dgrowleyml@gmail.com>, PostgreSQL Developers <pgsql-hackers@lists.postgresql.org>,
Andres Freund <andres@anarazel.de>
Date: 2020-06-09T19:51:58Z
Lists: pgsql-hackers
Em ter., 9 de jun. de 2020 às 15:53, Andrew Gierth <
andrew@tao11.riddles.org.uk> escreveu:
> >>>>> "Ranier" == Ranier Vilela <ranier.vf@gmail.com> writes:
>
> Ranier> Where " ends up with two copies of pg_ultoa_n inlined into it",
> Ranier> in this simplified example?
>
> The two references to sprintf are both inlined copies of your pg_utoa.
>
> Ranier> (b) I call this tail cut, I believe it saves time, for sure.
>
> You seem to have missed the point that the pg_ultoa_n / pg_ulltoa_n
> functions DO NOT ADD A TRAILING NUL. Which means that pg_ltoa / pg_lltoa
> can't just tail call them, since they must add the NUL after.
>
> Ranier> Regarding bugs:
>
> Ranier> (c) your version don't check size of a var, when pg_ulltoa_n
> Ranier> warning about "least MAXINT8LEN bytes."
>
> Ranier> So in theory, I could blow it up, by calling pg_lltoa.
>
> No. Callers of pg_lltoa are required to provide a buffer of at least
> MAXINT8LEN+1 bytes.
>
Thanks for explanations.
So I would change, just the initialization (var uvalue), even though it is
irrelevant.
int
pg_lltoa(int64 value, char *a)
{
int len = 0;
uint64 uvalue;
if (value < 0)
{
uvalue = (uint64) 0 - uvalue;
a[len++] = '-';
}
else
uvalue = value;
len += pg_ulltoa_n(uvalue, a + len);
a[len] = '\0';
return len;
}
regards,
Ranier Vilela
Commits
-
Have pg_itoa, pg_ltoa and pg_lltoa return the length of the string
- dad75eb4a8d5 14.0 landed
-
Add missing extern keyword for a couple of numutils functions
- 095f2d95c927 13.0 landed
- 9a7fccd9eac8 14.0 landed