Skip to content

Commit

Permalink
Limit the scope of @inbounds in searchsorted* (#56882)
Browse files Browse the repository at this point in the history
This removes bounds-checking only in the indexing operation, instead of
for the entire block.
  • Loading branch information
jishnub authored Dec 21, 2024
1 parent b772be3 commit 9d80765
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions base/sort.jl
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,10 @@ partialsort(v::AbstractVector, k::Union{Integer,OrdinalRange}; kws...) =
function searchsortedfirst(v::AbstractVector, x, lo::T, hi::T, o::Ordering)::keytype(v) where T<:Integer
hi = hi + T(1)
len = hi - lo
@inbounds while len != 0
while len != 0
half_len = len >>> 0x01
m = lo + half_len
if lt(o, v[m], x)
if lt(o, @inbounds(v[m]), x)
lo = m + 1
len -= half_len + 1
else
Expand All @@ -206,9 +206,9 @@ function searchsortedlast(v::AbstractVector, x, lo::T, hi::T, o::Ordering)::keyt
u = T(1)
lo = lo - u
hi = hi + u
@inbounds while lo != hi - u
while lo != hi - u
m = midpoint(lo, hi)
if lt(o, x, v[m])
if lt(o, x, @inbounds(v[m]))
hi = m
else
lo = m
Expand All @@ -224,11 +224,11 @@ function searchsorted(v::AbstractVector, x, ilo::T, ihi::T, o::Ordering)::UnitRa
u = T(1)
lo = ilo - u
hi = ihi + u
@inbounds while lo != hi - u
while lo != hi - u
m = midpoint(lo, hi)
if lt(o, v[m], x)
if lt(o, @inbounds(v[m]), x)
lo = m
elseif lt(o, x, v[m])
elseif lt(o, x, @inbounds(v[m]))
hi = m
else
a = searchsortedfirst(v, x, lo+u, m, o)
Expand Down

1 comment on commit 9d80765

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Executing the daily package evaluation, I will reply here when finished:

@nanosoldier runtests(isdaily = true)

Please sign in to comment.