some optimizations on shift.cpp