Core: optimization to avoid unnecessary swap function calls.