Skip to content

Commit 460402e

Browse files
authored
Improve code to avoid reliance on computation of length
The `length` of a String is expensive to compute, and the `length` of a `Stateful` is deprecated. It does not appear to be necessary to compute however.
1 parent a1d330c commit 460402e

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/utils.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,8 @@ else
555555
if c === 'x' || c === 'u' || c === 'U'
556556
maxiter = c === 'x' ? 2 : c === 'u' ? 4 : 8
557557
n = 0
558-
for _ in 1:min(length(a), maxiter)
558+
for _ in 1:maxiter
559+
isempty(a) && break
559560
nc = popfirst!(a)
560561
n = '0' <= nc <= '9' ? n << 4 + (nc - '0') :
561562
'a' <= nc <= 'f' ? n << 4 + (nc - 'a' + 10) :
@@ -564,7 +565,8 @@ else
564565
ok = n <= 0x10ffff
565566
elseif '0' <= c <= '7'
566567
n = c - '0'
567-
for _ in 1:min(length(a), 3)
568+
for _ in 1:3
569+
isempty(a) && break
568570
nc = popfirst!(a)
569571
n = ('0' <= c <= '7') ? n << 3 + nc - '0' : return false
570572
end

0 commit comments

Comments
 (0)