Skip to content

Commit cb3bb74

Browse files
committed
Fix spurious BoundsErrors when running with --check-bounds=yes
Travis runs with this setting, so the tests were failing
1 parent f22d08c commit cb3bb74

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/search.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,16 @@ function Base.searchsorted(a::Range, I::Interval)
3636
searchsortedfirst(a, I.lo):searchsortedlast(a, I.hi)
3737
end
3838

39+
if VERSION > v"0.5.0-dev+4557"
40+
# When running with "--check-bounds=yes" (like on Travis), the bounds-check isn't elided
41+
@inline function Base.unsafe_getindex{T}(r::FloatRange{T}, i::Integer)
42+
convert(T, (r.start + (i-1)*r.step)/r.divisor)
43+
end
44+
@inline function Base.unsafe_getindex(r::FloatRange, s::OrdinalRange)
45+
FloatRange(r.start + (first(s)-1)*r.step, step(s)*r.step, length(s), r.divisor)
46+
end
47+
end
48+
3949
function unsafe_searchsortedlast{T<:Number}(a::Range{T}, x::Number)
4050
step(a) == 0 && throw(ArgumentError("ranges with a zero step are unsupported"))
4151
n = round(Integer,(x-first(a))/step(a))+1

0 commit comments

Comments
 (0)