I wanted to create a custom type for precise fractions in postgres. They are useful for making user-defined row ordering (like a todo list) that you can rearrange without having to renumber surrounding items.
This is my first extension, and also the first time I’ve used C in many years. I wrote a lot of tests for this extension, and would love a code review.
Some coding questions that came to mind:
- I use pointers in many places where I could have passed a 128-bit argument by value. Does this give a speed boost? Is it worth the messier looking code?
- How portable is my use of
- I have guards for dangerous two’s complement operations, but do some CPUs use another representation that I ought to respect with conditional compilation?
- In a few places I turned some loops into a goto construction. Sounds nasty, I know, but I thought it helped emphasize that the common code path is not to loop at all.
- Coding conventions: naming, indentation, etc.
- Any optimizations I’m missing?
- Any bugs?
(Cross-posted on r/PostgreSQL)