Re: Convert macros to static inline functions
Peter Eisentraut <peter.eisentraut@enterprisedb.com>
From: Peter Eisentraut <peter.eisentraut@enterprisedb.com>
To: Amul Sul <sulamul@gmail.com>
Cc: pgsql-hackers <pgsql-hackers@postgresql.org>
Date: 2022-05-23T05:38:32Z
Lists: pgsql-hackers
Attachments
- v2-0001-Convert-macros-to-static-inline-functions-block.h.patch (text/plain) patch v2-0001
- v2-0002-Convert-macros-to-static-inline-functions-bufpage.patch (text/plain) patch v2-0002
- v2-0003-Convert-macros-to-static-inline-functions-itemptr.patch (text/plain) patch v2-0003
- v2-0004-Convert-macros-to-static-inline-functions-bufmgr..patch (text/plain) patch v2-0004
- v2-0005-Convert-macros-to-static-inline-functions-xlog_in.patch (text/plain) patch v2-0005
- v2-0006-Convert-macros-to-static-inline-functions-tupmacs.patch (text/plain) patch v2-0006
- v2-0007-Convert-macros-to-static-inline-functions-itup.h.patch (text/plain) patch v2-0007
- v2-0008-Convert-macros-to-static-inline-functions-pgstat..patch (text/plain) patch v2-0008
On 16.05.22 15:23, Amul Sul wrote:
> +static inline OffsetNumber
> +PageGetMaxOffsetNumber(Page page)
> +{
> + if (((PageHeader) page)->pd_lower <= SizeOfPageHeaderData)
> + return 0;
> + else
> + return ((((PageHeader) page)->pd_lower - SizeOfPageHeaderData)
> / sizeof(ItemIdData));
> +}
>
> The "else" is not necessary, we can have the return statement directly
> which would save some indentation as well. The Similar pattern can be
> considered for 0004 and 0007 patches as well.
I kind of like it better this way. It preserves the functional style of
the original macro.
> +static inline void
> +XLogFromFileName(const char *fname, TimeLineID *tli, XLogSegNo
> *logSegNo, int wal_segsz_bytes)
> +{
> + uint32 log;
> + uint32 seg;
> + sscanf(fname, "%08X%08X%08X", tli, &log, &seg);
> + *logSegNo = (uint64) log * XLogSegmentsPerXLogId(wal_segsz_bytes) + seg;
> +}
>
> Can we have a blank line after variable declarations that we usually have?
done
> 0006 patch:
> +static inline Datum
> +fetch_att(const void *T, bool attbyval, int attlen)
> +{
> + if (attbyval)
> + {
> +#if SIZEOF_DATUM == 8
> + if (attlen == sizeof(Datum))
> + return *((const Datum *) T);
> + else
> +#endif
>
> Can we have a switch case like store_att_byval() instead of if-else,
> code would look more symmetric, IMO.
done
Commits
-
Add some const decorations (htup.h)
- b15b8c5cf882 18.0 landed
-
Convert macros to static inline functions (htup_details.h, itup.h)
- 34694ec888d6 18.0 landed
-
Convert macros to static inline functions (rel.h)
- 3edc71ec0438 16.0 landed
-
Convert macros to static inline functions (itup.h)
- 14a8bd98274a 16.0 landed
-
Convert macros to static inline functions (tupmacs.h)
- f58d7073b775 16.0 landed
-
Convert macros to static inline functions (xlog_internal.h)
- 507ba16b28c7 16.0 landed
-
Convert macros to static inline functions (bufmgr.h)
- 9c727360bcc7 16.0 landed
-
Convert macros to static inline functions (itemptr.h)
- aeb767ca0b02 16.0 landed
-
Convert macros to static inline functions (bufpage.h)
- 2cd2569c72b8 16.0 landed
-
Convert macros to static inline functions (block.h)
- d63d957e330c 16.0 landed