I'd like to see a comment here explicitly about why this code is obtuse, specifically because it's an optimization.  It should be clear so readers understand why.