Re: appendBinaryStringInfo stuff

From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Andrew Dunstan <andrew(at)dunslane(dot)net>
Cc: David Rowley <dgrowleyml(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Eisentraut <peter(dot)eisentraut(at)enterprisedb(dot)com>, Andres Freund <andres(at)anarazel(dot)de>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: appendBinaryStringInfo stuff
Date: 2022-12-20 21:43:58
Message-ID: CA+TgmoZgjJQJCk=zF8m65S9beWvsjOQo1wWs1C8nOF5AsKe9nA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Tue, Dec 20, 2022 at 10:47 AM Andrew Dunstan <andrew(at)dunslane(dot)net> wrote:
> There are 5 uses in the jsonb code where the length param is a compile
> time constant:
>
> andrew(at)ub22:adt $ grep appendBinary.*[0-9] jsonb*
> jsonb.c: appendBinaryStringInfo(out, "null", 4);
> jsonb.c: appendBinaryStringInfo(out, "true", 4);
> jsonb.c: appendBinaryStringInfo(out, "false", 5);
> jsonb.c: appendBinaryStringInfo(out, ": ", 2);
> jsonb.c: appendBinaryStringInfo(out, " ", 4);
>
> None of these really bother me much, TBH. In fact the last one is
> arguably nicer because it tells you without counting how many spaces
> there are.

+1. There are certainly cases where this kind of style can create
confusion, but I have a hard time putting any of these instances into
that category. It's obvious at a glance that null is 4 bytes, false is
5, etc.

--
Robert Haas
EDB: http://www.enterprisedb.com

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Eric Radman 2022-12-20 22:08:13 [PATCH] Add function to_oct
Previous Message Robert Haas 2022-12-20 21:41:54 Re: Minimal logical decoding on standbys