Re: [PATCH] Add function to_oct

Dag Lem <dag@nimrod.no>

From: Dag Lem <dag@nimrod.no>
To: pgsql-hackers@lists.postgresql.org
Cc: Eric Radman <ericshane@eradman.com>
Date: 2022-12-22T10:08:17Z
Lists: pgsql-hackers
The following review has been posted through the commitfest application:
make installcheck-world:  not tested
Implements feature:       not tested
Spec compliant:           not tested
Documentation:            not tested

This is a mini-review of to_oct :-)

The function seems useful to me, and is obviously correct.

I don't know whether optimization at such a low level is considered in PostgreSQL, but here goes.

The calculation of quotient and remainder can be replaced by less costly masking and shifting.

Defining

#define OCT_DIGIT_BITS 3
#define OCT_DIGIT_BITMASK 0x7

the content of the loop can be replaced by

		*--ptr = digits[value & OCT_DIGIT_BITMASK];
		value >>= OCT_DIGIT_BITS;

Also, the check for ptr > buf in the while loop can be removed. The check is superfluous, since buf cannot possibly be exhausted by a 32 bit integer (the maximum octal number being 37777777777).


Best regards

Dag Lem

The new status of this patch is: Waiting on Author

Commits

  1. Add to_bin() and to_oct().