fix Issue 10866 - Regression (2.064 git-head) Massive compiler slowdown

Revert part of the change in commit 805dd761dd85c98d60b3957bd5679cdbbf23c7f2.
Read the detailed comment in code.
Merge pull request #2496 from 9rnsr/fix10866

Issue 10866 - Regression (2.064 git-head) Massive compiler slowdown