Re: gratuitous casting away const

From: Mark Dilger <hornschnorter(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: gratuitous casting away const
Date: 2016-09-20 21:33:17
Message-ID: 96DBB26C-34FF-4090-98A8-6DDA5136AC73@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers


> On Sep 20, 2016, at 1:06 PM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>
> Mark Dilger <hornschnorter(at)gmail(dot)com> writes:
>> Would patches to not cast away const be considered?
>
> In general, yes, but I'm not especially in favor of something like this:
>
>> bool
>> PageIndexTupleOverwrite(Page page, OffsetNumber offnum,
>> - Item newtup, Size newsize)
>> + const char *newtup, Size newsize)
>> {
>
> since that seems to be discarding type information in order to add
> "const"; does not seem like a net benefit from here.

The following seems somewhere in between, with ItemPointer
changing to const ItemPointerData *. I expect you would not care
for this change, but thought I'd check to see where you draw the line:

diff --git a/src/backend/access/gin/ginbulk.c b/src/backend/access/gin/ginbulk.c
index 71c64e4..903b01f 100644
--- a/src/backend/access/gin/ginbulk.c
+++ b/src/backend/access/gin/ginbulk.c
@@ -244,7 +244,7 @@ ginInsertBAEntries(BuildAccumulator *accum,
static int
qsortCompareItemPointers(const void *a, const void *b)
{
- int res = ginCompareItemPointers((ItemPointer) a, (ItemPointer) b);
+ int res = ginCompareItemPointers((const ItemPointerData *) a, (const ItemPointerData *) b);

/* Assert that there are no equal item pointers being sorted */
Assert(res != 0);
diff --git a/src/include/access/gin_private.h b/src/include/access/gin_private.h
index bf589ab..2e5a7dff 100644
--- a/src/include/access/gin_private.h
+++ b/src/include/access/gin_private.h
@@ -968,7 +968,7 @@ extern ItemPointer ginMergeItemPointers(ItemPointerData *a, uint32 na,
* so we want this to be inlined.
*/
static inline int
-ginCompareItemPointers(ItemPointer a, ItemPointer b)
+ginCompareItemPointers(const ItemPointerData *a, const ItemPointerData *b)
{
uint64 ia = (uint64) a->ip_blkid.bi_hi << 32 | (uint64) a->ip_blkid.bi_lo << 16 | a->ip_posid;
uint64 ib = (uint64) b->ip_blkid.bi_hi << 32 | (uint64) b->ip_blkid.bi_lo << 16 | b->ip_posid;

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tomas Vondra 2016-09-20 22:18:55 Re: Speed up Clog Access by increasing CLOG buffers
Previous Message Tom Lane 2016-09-20 21:13:30 Re: needlessly casting away const in localtime.c