Merge rizzo's range optimizations (bug #6101)