remove some unnecessary overhead in typed Cython code

These are untested changes, I just went through the code and removed anything that looked unnecessarily complicated or slowish at first sight.