pg.ddx.io pgsql-hackers@postgresql.org mailing list archive
help / color / mirror / Atom feed From: Nathan Bossart <nathandbossart@gmail.com>
To: John Naylor <john.naylor@enterprisedb.com>
Cc: Kirk Wolak <wolakk@gmail.com>
Cc: Peter Eisentraut <peter.eisentraut@enterprisedb.com>
Cc: Eric Radman <ericshane@eradman.com>
Cc: pgsql-hackers@postgresql.org
Subject: Re: [PATCH] Add function to_oct
Date: Sun, 20 Aug 2023 08:19:37 -0700
Message-ID: <20230820151937.GA290672@nathanxps13> (raw )
In-Reply-To: <CAFBsxsEsY3G8Qrsv8YWsDrcQ93p=N7t73dxEGfznfJ3-1phUZw@mail.gmail.com >
References: <20230726001656.GC2992317@nathanxps13 >
<20230726032917.GA3151386@nathanxps13 >
<20230815041129.GB2294364@nathanxps13 >
<CAFBsxsGkBKO276L476BWDgNGbkaH0S_ZcnevOK_0s=Dz0=Utrw@mail.gmail.com >
<20230815171715.GA2312399@nathanxps13 >
<CAFBsxsEm0VGAipmQNK-EZ1a8ej6PDF+2aEkYGbktKH9aHFb4Dw@mail.gmail.com >
<20230816142410.GA2651383@nathanxps13 >
<CAFBsxsEVR_M4_eGgP_zdugerq8iTUHeVJP-DBRj7yPh2xcuh4g@mail.gmail.com >
<20230817152628.GA3148583@nathanxps13 >
<CAFBsxsEsY3G8Qrsv8YWsDrcQ93p=N7t73dxEGfznfJ3-1phUZw@mail.gmail.com >
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
view thread (34+ messages) latest in thread
Message-ID: <20230820151937.GA290672@nathanxps13>
Permalink: ../20230820151937.GA290672@nathanxps13/
Also on: postgresql.org/message-id/20230820151937.GA290672@nathanxps13
copy link · copy postgr.es
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: pgsql-hackers@postgresql.org
Cc: nathandbossart@gmail.com, john.naylor@enterprisedb.com, wolakk@gmail.com, peter.eisentraut@enterprisedb.com, ericshane@eradman.com
Subject: Re: [PATCH] Add function to_oct
In-Reply-To: <20230820151937.GA290672@nathanxps13>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox