Issue #5096: Optimization code about speed