Well, thanks for explaining the mechanism. O(m) feels much better, and a cleaner code is also preferable.