MAINT various micro-optimizations to Cython code

Trimmed away some dead code and used lower-level APIs were it didn't hurt readability. This is intended to get smaller code, not extra speed, and the generated C code is hundreds of lines shorter.