Обсуждение: remove redundant check of item pointer

Поиск
Список
Период
Сортировка

remove redundant check of item pointer

От
Junwang Zhao
Дата:
In function ItemPointerEquals, the ItemPointerGetBlockNumber
already checked the ItemPointer if valid, there is no need
to check it again in ItemPointerGetOffset, so use
ItemPointerGetOffsetNumberNoCheck instead.

-- 
Regards
Junwang Zhao

Вложения

Re: remove redundant check of item pointer

От
Tom Lane
Дата:
Junwang Zhao <zhjwpku@gmail.com> writes:
> In function ItemPointerEquals, the ItemPointerGetBlockNumber
> already checked the ItemPointer if valid, there is no need
> to check it again in ItemPointerGetOffset, so use
> ItemPointerGetOffsetNumberNoCheck instead.

I do not think this change is worth making.  The point of
ItemPointerGetOffsetNumberNoCheck is not to save some cycles,
it's to be able to fetch the offset field in cases where it might
validly be zero.  The assertion will be compiled out anyway in
production builds --- and even in assert-enabled builds, I'd kind
of expect the compiler to optimize away the duplicated tests.

            regards, tom lane



Re: remove redundant check of item pointer

От
Junwang Zhao
Дата:
got it, thanks for the explanation.

On Wed, Apr 27, 2022 at 11:34 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
>
> Junwang Zhao <zhjwpku@gmail.com> writes:
> > In function ItemPointerEquals, the ItemPointerGetBlockNumber
> > already checked the ItemPointer if valid, there is no need
> > to check it again in ItemPointerGetOffset, so use
> > ItemPointerGetOffsetNumberNoCheck instead.
>
> I do not think this change is worth making.  The point of
> ItemPointerGetOffsetNumberNoCheck is not to save some cycles,
> it's to be able to fetch the offset field in cases where it might
> validly be zero.  The assertion will be compiled out anyway in
> production builds --- and even in assert-enabled builds, I'd kind
> of expect the compiler to optimize away the duplicated tests.
>
>                         regards, tom lane



-- 
Regards
Junwang Zhao