Note that the hilbert function wasn't written by me, just merely ported from C++ — here's a post about it by the original author: http://threadlocalmutex.com/?p=126
Nice!
But still: you did port it from C++, and consciously or not, that optimization still applies.