Cachegrind tells me that your rewrites is actually a little slower, on the standard SQLite performance test benchmark. I get 1,035,083,032 CPU cycles with the existing SQLITE_WITHIN and 1,035,107,651 CPU cycles with your rewrite. Your rewrite also makes the executable 45 bytes larger. What performance measurement tool is telling you that the rewrite is faster? The numbers above are using cachegrind on a x64 with a binary generated using gcc 5.4.0 and -Os.