Dave Hudson

hashingit.com

c8: Improving comparisons

2017-03-29 00:00 - 1 min read

The original approach to comparison operators was to have a single compare function and then compare the value returned from it. This has the advantage of being easy to implement, but the disadvantage that we can’t easily take early-outs in cases that might help. Our compilers might do that for us, but there’s no guarantee.

Instead, if we make these things explicit we get better performance, but also eliminate some abstractions that aren’t obviously useful. The most noticeable examples are for the == and != operators where many tests simplify. In the case of rational numbers these simplifications also avoid any arithmetic operations too.

More journal entries