Skip to content

Commit eb68105

Browse files
sami-danielgfoidl
andauthored
Optimize Boundary Check in BinarySearch Method
This commit enhances the performance of the BinarySearch method by eliminating unnecessary boundary checks. The condition if ((uint)candidate.Length > (uint)prefix.Length) ensures that the index access candidate[prefix.Length] is safe, and the JIT compiler can now safely elide the boundary check, improving execution efficiency. Co-authored-by: Günther Foidl <[email protected]>
1 parent 324652b commit eb68105

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/Mvc/Mvc.Core/src/ModelBinding/PrefixContainer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ private int BinarySearch(string prefix)
212212
// which should not qualify as a prefix match. Therefore, we will continue searching
213213
// for valid matches in this case.
214214

215-
if (candidate.Length > prefix.Length)
215+
if ((uint)candidate.Length > (uint)prefix.Length)
216216
{
217217
var c = candidate[prefix.Length];
218218
if (c == '.' || c == '[')

0 commit comments

Comments
 (0)