@@ -107,10 +107,10 @@ typemin(::String) = typemin(String)
107
107
108
108
# # thisind, nextind ##
109
109
110
- thisind (s:: String , i:: Int ) = _thisind_str (s, i)
110
+ Base . @propagate_inbounds thisind (s:: String , i:: Int ) = _thisind_str (s, i)
111
111
112
112
# s should be String or SubString{String}
113
- function _thisind_str (s, i:: Int )
113
+ @inline function _thisind_str (s, i:: Int )
114
114
i == 0 && return 0
115
115
n = ncodeunits (s)
116
116
i == n + 1 && return i
@@ -128,10 +128,10 @@ function _thisind_str(s, i::Int)
128
128
return i
129
129
end
130
130
131
- nextind (s:: String , i:: Int ) = _nextind_str (s, i)
131
+ Base . @propagate_inbounds nextind (s:: String , i:: Int ) = _nextind_str (s, i)
132
132
133
133
# s should be String or SubString{String}
134
- function _nextind_str (s, i:: Int )
134
+ @inline function _nextind_str (s, i:: Int )
135
135
i == 0 && return 1
136
136
n = ncodeunits (s)
137
137
@boundscheck between (i, 1 , n) || throw (BoundsError (s, i))
237
237
238
238
getindex (s:: String , r:: UnitRange{<:Integer} ) = s[Int (first (r)): Int (last (r))]
239
239
240
- function getindex (s:: String , r:: UnitRange{Int} )
240
+ @inline function getindex (s:: String , r:: UnitRange{Int} )
241
241
isempty (r) && return " "
242
242
i, j = first (r), last (r)
243
243
@boundscheck begin
@@ -248,14 +248,11 @@ function getindex(s::String, r::UnitRange{Int})
248
248
j = nextind (s, j) - 1
249
249
n = j - i + 1
250
250
ss = _string_n (n)
251
- p = pointer (ss)
252
- for k = 1 : n
253
- unsafe_store! (p, codeunit (s, i + k - 1 ), k)
254
- end
251
+ unsafe_copyto! (pointer (ss), pointer (s, i), n)
255
252
return ss
256
253
end
257
254
258
- function length (s:: String , i:: Int , j:: Int )
255
+ @inline function length (s:: String , i:: Int , j:: Int )
259
256
@boundscheck begin
260
257
0 < i ≤ ncodeunits (s)+ 1 || throw (BoundsError (s, i))
261
258
0 ≤ j < ncodeunits (s)+ 1 || throw (BoundsError (s, j))
0 commit comments