From: | "Smith, Peter" <peters(at)fast(dot)au(dot)fujitsu(dot)com> |
---|---|
To: | PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Proposal: Make use of C99 designated initialisers for nulls/values arrays |
Date: | 2019-10-01 07:55:26 |
Message-ID: | 201DD0641B056142AC8C6645EC1B5F62014B919631@SYD1217 |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
Dear Hackers,
I have identified some OSS code which maybe can make use of C99 designated initialisers for nulls/values arrays.
~
Background:
There are lots of tuple operations where arrays of values and flags are being passed.
Typically these arrays are being previously initialised 0/false by memset.
By modifying code to use C99 designated initialiser syntax [1], most of these memsets can become redundant.
Actually, this mechanism is already being used in some of the existing OSS code. This patch/proposal just propagates the same idea to all other similar places I could find.
~
Result:
Less code. Removes ~200 unnecessary memsets.
More consistent initialisation.
~
Typical Example:
Before:
Datum values[Natts_pg_attribute];
bool nulls[Natts_pg_attribute];
...
memset(values, 0, sizeof(values));
memset(nulls, false, sizeof(nulls));
After:
Datum values[Natts_pg_attribute] = {0};
bool nulls[Natts_pg_attribute] = {0};
---
[1] REF C99 [$6.7.8/21] If there are fewer initializers in a brace-enclosed list than there are elements or members of an aggregate,
or fewer characters in a string literal used to initialize an array of known size than there are elements in the array,
the remainder of the aggregate shall be initialized implicitly the same as objects that have static storage duration
~
Please refer to the attached patch.
Kind Regards,
---
Peter Smith
Fujitsu Australia
Attachment | Content-Type | Size |
---|---|---|
init_nulls.patch | application/octet-stream | 81.4 KB |
From | Date | Subject | |
---|---|---|---|
Next Message | Moon, Insung | 2019-10-01 08:10:49 | Re: Transparent Data Encryption (TDE) and encrypted files |
Previous Message | Andres Freund | 2019-10-01 07:38:50 | Declaring a strict function returns not null / eval speed |