@@ -150,12 +150,10 @@ is_valid_continuation(c) = c & 0xc0 == 0x80
150
150
151
151
# # required core functionality ##
152
152
153
- function next (s:: String , i:: Int )
154
- @boundscheck checkbounds (s, i)
155
- @inbounds b = codeunit (s, i)
156
- # TODO : check index validity
153
+ @propagate_inbounds function next (s:: String , i:: Int )
154
+ b = codeunit (s, i)
157
155
u = UInt32 (b) << 24
158
- (b < 0x80 ) | ( 0xf8 ≤ b) && return reinterpret (Char, u), i+ 1
156
+ between (b, 0x80 , 0xf7 ) || return reinterpret (Char, u), i+ 1
159
157
return next_continued (s, i, u)
160
158
end
161
159
@@ -187,29 +185,30 @@ end
187
185
@propagate_inbounds function getindex (s:: String , i:: Int )
188
186
b = codeunit (s, i)
189
187
u = UInt32 (b) << 24
190
- (b < 0x80 ) | ( 0xf8 ≤ b) && return reinterpret (Char, u)
188
+ between (b, 0x80 , 0xf7 ) || return reinterpret (Char, u)
191
189
return getindex_continued (s, i, u)
192
190
end
193
191
194
- @noinline function getindex_continued (s:: String , i:: Int , u:: UInt32 )
192
+ function getindex_continued (s:: String , i:: Int , u:: UInt32 )
195
193
if u < 0xc0000000
196
- isvalid (s, i) && @goto ret
194
+ # called from `getindex` which checks bounds
195
+ @inbounds isvalid (s, i) && @goto ret
197
196
string_index_err (s, i)
198
197
end
199
198
n = ncodeunits (s)
200
- # first continuation byte
199
+
201
200
(i += 1 ) > n && @goto ret
202
- @inbounds b = codeunit (s, i)
201
+ @inbounds b = codeunit (s, i) # cont byte 1
203
202
b & 0xc0 == 0x80 || @goto ret
204
203
u |= UInt32 (b) << 16
205
- # second continuation byte
204
+
206
205
((i += 1 ) > n) | (u < 0xe0000000 ) && @goto ret
207
- @inbounds b = codeunit (s, i)
206
+ @inbounds b = codeunit (s, i) # cont byte 2
208
207
b & 0xc0 == 0x80 || @goto ret
209
208
u |= UInt32 (b) << 8
210
- # third continuation byte
209
+
211
210
((i += 1 ) > n) | (u < 0xf0000000 ) && @goto ret
212
- @inbounds b = codeunit (s, i)
211
+ @inbounds b = codeunit (s, i) # cont byte 3
213
212
b & 0xc0 == 0x80 || @goto ret
214
213
u |= UInt32 (b)
215
214
@label ret
@@ -252,13 +251,13 @@ end
252
251
253
252
length (s:: String ) = _length (s, 1 , ncodeunits (s), ncodeunits (s))
254
253
255
- function _length (s:: String , i:: Int , n:: Int , c:: Int )
254
+ @inline function _length (s:: String , i:: Int , n:: Int , c:: Int )
256
255
i < n || return c
257
256
@inbounds b = codeunit (s, i)
258
257
@inbounds while true
259
258
while true
260
259
(i += 1 ) ≤ n || return c
261
- between (b, 0xc0 , 0xf7 ) && break
260
+ 0xc0 ≤ b ≤ 0xf7 && break
262
261
b = codeunit (s, i)
263
262
end
264
263
l = b
0 commit comments