@@ -3921,45 +3921,45 @@ template _arrayOp(Args...)
3921
3921
strings are sorted by length first, and then lexicographically.
3922
3922
* condition = string to look up in table
3923
3923
* Returns:
3924
- * index of match in caseLabels, -1 if not found
3924
+ * index of match in caseLabels, a negative integer if not found
3925
3925
*/
3926
3926
int __switch (T, caseLabels... )(/* in*/ const scope T[] condition) pure nothrow @safe @nogc
3927
3927
{
3928
3928
// This closes recursion for other cases.
3929
3929
static if (caseLabels.length == 0 )
3930
3930
{
3931
- return - 1 ;
3931
+ return int .min ;
3932
3932
}
3933
3933
else static if (caseLabels.length == 1 )
3934
3934
{
3935
- return __cmp (condition, caseLabels[0 ]) == 0 ? 0 : - 1 ;
3935
+ return __cmp (condition, caseLabels[0 ]) == 0 ? 0 : int .min ;
3936
3936
}
3937
3937
// To be adjusted after measurements
3938
3938
// Compile-time inlined binary search.
3939
3939
else static if (caseLabels.length < 7 )
3940
3940
{
3941
3941
int r = void ;
3942
- if (condition.length == caseLabels[$ / 2 ].length)
3942
+ enum mid = cast (int )caseLabels.length / 2 ;
3943
+ if (condition.length == caseLabels[mid].length)
3943
3944
{
3944
- r = __cmp(condition, caseLabels[$ / 2 ]);
3945
- if (r == 0 ) return cast ( int ) caseLabels.length / 2 ;
3945
+ r = __cmp(condition, caseLabels[mid ]);
3946
+ if (r == 0 ) return mid ;
3946
3947
}
3947
3948
else
3948
3949
{
3949
3950
// Equivalent to (but faster than) condition.length > caseLabels[$ / 2].length ? 1 : -1
3950
- r = ((condition.length > caseLabels[$ / 2 ].length) << 1 ) - 1 ;
3951
+ r = ((condition.length > caseLabels[mid ].length) << 1 ) - 1 ;
3951
3952
}
3952
3953
3953
3954
if (r < 0 )
3954
3955
{
3955
3956
// Search the left side
3956
- return __switch! (T, caseLabels[0 .. $ / 2 ])(condition);
3957
+ return __switch! (T, caseLabels[0 .. mid ])(condition);
3957
3958
}
3958
3959
else
3959
3960
{
3960
3961
// Search the right side
3961
- r = __switch! (T, caseLabels[$ / 2 + 1 .. $])(condition);
3962
- return r != - 1 ? cast (int ) (caseLabels.length / 2 + 1 + r) : - 1 ;
3962
+ return __switch! (T, caseLabels[mid + 1 .. $])(condition) + mid + 1 ;
3963
3963
}
3964
3964
}
3965
3965
else
0 commit comments