Remove meaningless const qualifier from ginCompressPostingList()

Started by Chao Li6 months ago2 messageshackers
Jump to latest
#1Chao Li
li.evan.chao@gmail.com

Hi Hacker,

While working on the other patch that fixed wrong "const" usage [1], I
found the function:
```
GinPostingList *
ginCompressPostingList(const ItemPointer ipd, int nipd, int maxsize,
int *nwritten)
```
uses "const" unnecessarily. Because it needs to assign an element of "ipd"
to the returned structure "GinPostingList->first" and "first" is a mutable
"ItemPointerData *", so that "ipd" cannot be of const pointer.

With the current usage, "const" only protects "ipd" itself from updating,
which is meaningless. Thus the "const" only adds confusion to code readers,
so I am deleting it.

/messages/by-id/CAEoWx2m2E0xE8Kvbkv31ULh_E+5zph-WA_bEdv3UR9CLhw+3vg@mail.gmail.com

Chao Li (Evan)
---------------------
HighGo Software Co., Ltd.
https://www.highgo.com/

Attachments:

v1-0001-Remove-meaningless-const-qualifier-from-ginCompre.patchapplication/octet-stream; name=v1-0001-Remove-meaningless-const-qualifier-from-ginCompre.patchDownload+2-3
#2Peter Eisentraut
peter_e@gmx.net
In reply to: Chao Li (#1)
Re: Remove meaningless const qualifier from ginCompressPostingList()

On 29.10.25 04:42, Chao Li wrote:

While working on the other patch that fixed wrong "const" usage [1], I
found the function:
```
GinPostingList *
ginCompressPostingList(const ItemPointer ipd, int nipd, int maxsize,
  int *nwritten)
```
uses "const" unnecessarily. Because it needs to assign an element of
"ipd" to the returned structure "GinPostingList->first" and "first" is a
mutable "ItemPointerData *", so that "ipd" cannot be of const pointer.

I have committed a fix for this together with the other one.

The code you are referring to here is:

result->first = ipd[0];

This is a value copy, so this does not violate the immutability of ipd.
So the const in the function prototype was the right idea, but in the
wrong place of course.