Improve efficiency of window size check