Re: [PATCH] Add function to_oct

From: Dag Lem <dag(at)nimrod(dot)no>
To: pgsql-hackers(at)lists(dot)postgresql(dot)org
Cc: Eric Radman <ericshane(at)eradman(dot)com>
Subject: Re: [PATCH] Add function to_oct
Date: 2022-12-22 10:08:17
Message-ID: 167170369754.1121.7881078512513671914.pgcf@coridan.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
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

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message John Naylor 2022-12-22 10:24:16 Re: [PoC] Improve dead tuple storage for lazy vacuum
Previous Message Amit Kapila 2022-12-22 10:04:10 Re: Perform streaming logical transactions by background workers and parallel apply