Skip to content

Commit 9d80765

Browse files
authored
Limit the scope of @inbounds in searchsorted* (#56882)
This removes bounds-checking only in the indexing operation, instead of for the entire block.
1 parent b772be3 commit 9d80765

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

base/sort.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -186,10 +186,10 @@ partialsort(v::AbstractVector, k::Union{Integer,OrdinalRange}; kws...) =
186186
function searchsortedfirst(v::AbstractVector, x, lo::T, hi::T, o::Ordering)::keytype(v) where T<:Integer
187187
hi = hi + T(1)
188188
len = hi - lo
189-
@inbounds while len != 0
189+
while len != 0
190190
half_len = len >>> 0x01
191191
m = lo + half_len
192-
if lt(o, v[m], x)
192+
if lt(o, @inbounds(v[m]), x)
193193
lo = m + 1
194194
len -= half_len + 1
195195
else
@@ -206,9 +206,9 @@ function searchsortedlast(v::AbstractVector, x, lo::T, hi::T, o::Ordering)::keyt
206206
u = T(1)
207207
lo = lo - u
208208
hi = hi + u
209-
@inbounds while lo != hi - u
209+
while lo != hi - u
210210
m = midpoint(lo, hi)
211-
if lt(o, x, v[m])
211+
if lt(o, x, @inbounds(v[m]))
212212
hi = m
213213
else
214214
lo = m
@@ -224,11 +224,11 @@ function searchsorted(v::AbstractVector, x, ilo::T, ihi::T, o::Ordering)::UnitRa
224224
u = T(1)
225225
lo = ilo - u
226226
hi = ihi + u
227-
@inbounds while lo != hi - u
227+
while lo != hi - u
228228
m = midpoint(lo, hi)
229-
if lt(o, v[m], x)
229+
if lt(o, @inbounds(v[m]), x)
230230
lo = m
231-
elseif lt(o, x, v[m])
231+
elseif lt(o, x, @inbounds(v[m]))
232232
hi = m
233233
else
234234
a = searchsortedfirst(v, x, lo+u, m, o)

0 commit comments

Comments
 (0)