Thanks much for this performance improvement. I puzzled for a while to figure out what was going on, and was confused by that tricky macro expansion. Nowadays functions are typically not significantly slower than macros, so unless there's a major performance difference I'd prefer to use functions. I installed the performance improvement patch and followed up with the attached patch, which uses C functions instead of macros and which coalesces some of the near-duplicate code. The followup patch also includes some comments to try to explain the new functions.