Improve O(n^2) implementation to O(n) about NOP removal