From 1a4be103a523db8d47b464463ba175cc664442b2 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Fri, 9 Sep 2016 18:17:07 -0400 Subject: [PATCH] Convert PageAddItem into a macro to save a few cycles. Nowadays this is just a backwards-compatibility wrapper around PageAddItemExtended, so let's avoid the extra level of function call. In addition, because pretty much all callers are passing constants for the two bool arguments, compilers will be able to constant-fold the conversion to a flags bitmask. Discussion: <552.1473445163@sss.pgh.pa.us> --- src/backend/storage/page/bufpage.c | 20 -------------------- src/include/storage/bufpage.h | 7 +++++-- 2 files changed, 5 insertions(+), 22 deletions(-) diff --git a/src/backend/storage/page/bufpage.c b/src/backend/storage/page/bufpage.c index 08e222e583..41a7dd0d62 100644 --- a/src/backend/storage/page/bufpage.c +++ b/src/backend/storage/page/bufpage.c @@ -338,26 +338,6 @@ PageAddItemExtended(Page page, return offsetNumber; } -/* - * PageAddItem - * - * Add an item to a page. Return value is offset at which it was - * inserted, or InvalidOffsetNumber if the item is not inserted for - * any reason. - * - * Passing the 'overwrite' and 'is_heap' parameters as true causes the - * PAI_OVERWRITE and PAI_IS_HEAP flags to be set, respectively. - * - * !!! EREPORT(ERROR) IS DISALLOWED HERE !!! - */ -OffsetNumber -PageAddItem(Page page, Item item, Size size, OffsetNumber offsetNumber, - bool overwrite, bool is_heap) -{ - return PageAddItemExtended(page, item, size, offsetNumber, - overwrite ? PAI_OVERWRITE : 0 | - is_heap ? PAI_IS_HEAP : 0); -} /* * PageGetTempPage diff --git a/src/include/storage/bufpage.h b/src/include/storage/bufpage.h index 0ea47f5457..4cedff7fa4 100644 --- a/src/include/storage/bufpage.h +++ b/src/include/storage/bufpage.h @@ -410,10 +410,13 @@ do { \ #define PAI_OVERWRITE (1 << 0) #define PAI_IS_HEAP (1 << 1) +#define PageAddItem(page, item, size, offsetNumber, overwrite, is_heap) \ + PageAddItemExtended(page, item, size, offsetNumber, \ + ((overwrite) ? PAI_OVERWRITE : 0) | \ + ((is_heap) ? PAI_IS_HEAP : 0)) + extern void PageInit(Page page, Size pageSize, Size specialSize); extern bool PageIsVerified(Page page, BlockNumber blkno); -extern OffsetNumber PageAddItem(Page page, Item item, Size size, - OffsetNumber offsetNumber, bool overwrite, bool is_heap); extern OffsetNumber PageAddItemExtended(Page page, Item item, Size size, OffsetNumber offsetNumber, int flags); extern Page PageGetTempPage(Page page); -- 2.40.0