do not check unsigned windowsize for < 0
collapsing duplicate branch
reducing scope of loop counters, and micro-optimising loops by using != where safe and pre-increment wherever return value is not used
optimisation: replacing all unnecessary post-increments and post-decrements with their pre-increment and pre-decrement equivalents wherever the return value isn't used