@@ -37,26 +37,28 @@ function Base.searchsorted(a::Range, I::ClosedInterval)
37
37
end
38
38
39
39
# When running with "--check-bounds=yes" (like on Travis), the bounds-check isn't elided
40
- @inline function Base . unsafe_getindex {T} (v:: Range{T} , i:: Integer )
40
+ @inline function inbounds_getindex {T} (v:: Range{T} , i:: Integer )
41
41
convert (T, first (v) + (i- 1 )* step (v))
42
42
end
43
- @inline function Base. unsafe_getindex {T<:Integer} (r:: StepRange , s:: Range{T} )
44
- st = oftype (r. start, r. start + (first (s)- 1 )* step (r))
43
+ @inline function inbounds_getindex {T<:Integer} (r:: Range , s:: Range{T} )
44
+ f = first (r)
45
+ st = oftype (f, f + (first (s)- 1 )* step (r))
45
46
range (st, step (r)* step (s), length (s))
46
47
end
47
48
if VERSION < v " 0.6.0-dev.2390"
48
49
include_string ("""
49
- @inline function Base.unsafe_getindex {T}(r::FloatRange{T}, i::Integer)
50
+ @inline function inbounds_getindex {T}(r::FloatRange{T}, i::Integer)
50
51
convert(T, (r.start + (i-1)*r.step)/r.divisor)
51
52
end
52
- @inline function Base.unsafe_getindex (r::FloatRange, s::OrdinalRange)
53
+ @inline function inbounds_getindex (r::FloatRange, s::OrdinalRange)
53
54
FloatRange(r.start + (first(s)-1)*r.step, step(s)*r.step, length(s), r.divisor)
54
55
end
55
56
""" )
56
57
else
57
58
include_string ("""
58
- @inline function Base.unsafe_getindex(r::StepRangeLen, s::OrdinalRange)
59
- vfirst = unsafe_getindex(r, first(s))
59
+ @inline inbounds_getindex(r::StepRangeLen, i::Integer) = Base.unsafe_getindex(r, i)
60
+ @inline function inbounds_getindex(r::StepRangeLen, s::OrdinalRange)
61
+ vfirst = Base.unsafe_getindex(r, first(s))
60
62
StepRangeLen(vfirst, r.step*step(s), length(s))
61
63
end
62
64
""" )
65
67
function unsafe_searchsortedlast {T<:Number} (a:: Range{T} , x:: Number )
66
68
step (a) == 0 && throw (ArgumentError (" ranges with a zero step are unsupported" ))
67
69
n = round (Integer,(x- first (a))/ step (a))+ 1
68
- isless (x, unsafe_getindex (a, n)) ? n- 1 : n
70
+ isless (x, inbounds_getindex (a, n)) ? n- 1 : n
69
71
end
70
72
function unsafe_searchsortedfirst {T<:Number} (a:: Range{T} , x:: Number )
71
73
step (a) == 0 && throw (ArgumentError (" ranges with a zero step are unsupported" ))
72
74
n = round (Integer,(x- first (a))/ step (a))+ 1
73
- isless (unsafe_getindex (a, n), x) ? n+ 1 : n
75
+ isless (inbounds_getindex (a, n), x) ? n+ 1 : n
74
76
end
75
77
function unsafe_searchsortedlast {T<:Integer} (a:: Range{T} , x:: Number )
76
78
step (a) == 0 && throw (ArgumentError (" ranges with a zero step are unsupported" ))
0 commit comments