Re: [PATCH] Add function to_oct

From: Nathan Bossart <nathandbossart(at)gmail(dot)com>
To: John Naylor <john(dot)naylor(at)enterprisedb(dot)com>
Cc: Kirk Wolak <wolakk(at)gmail(dot)com>, Peter Eisentraut <peter(dot)eisentraut(at)enterprisedb(dot)com>, Eric Radman <ericshane(at)eradman(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: [PATCH] Add function to_oct
Date: 2023-08-20 15:19:37
Message-ID: 20230820151937.GA290672@nathanxps13
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Sat, Aug 19, 2023 at 11:41:56AM +0700, John Naylor wrote:
> This looks nicer, but still doesn't save the starting pointer, and so needs
> to lug around that big honking macro. This is what I mean:
>
> static inline text *
> convert_to_base(uint64 value, int base)
> {
> const char *digits = "0123456789abcdef";
> /* We size the buffer for to_binary's longest possible return value. */
> char buf[sizeof(uint64) * BITS_PER_BYTE];
> char * const end = buf + sizeof(buf);
> char *ptr = end;
>
> Assert(base > 1);
> Assert(base <= 16);
>
> do
> {
> *--ptr = digits[value % base];
> value /= base;
> } while (ptr > buf && value);
>
> return cstring_to_text_with_len(ptr, end - ptr);
> }

I will use this in v8.

--
Nathan Bossart
Amazon Web Services: https://aws.amazon.com

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Masahiko Sawada 2023-08-20 15:20:45 Re: [PoC] pg_upgrade: allow to upgrade publisher node
Previous Message Tom Lane 2023-08-20 14:50:40 Re: PostgreSQL 16 RC1 + GA release dates