Fixed performance regression caused by the fix for bug 2158