From 460402ee43447321e93288fa69ec9d5e923db1c4 Mon Sep 17 00:00:00 2001 From: Jameson Nash Date: Thu, 1 Feb 2024 09:34:51 -0500 Subject: [PATCH] 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. --- src/utils.jl | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/utils.jl b/src/utils.jl index 42fcca28..efb6437a 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -555,7 +555,8 @@ else if c === 'x' || c === 'u' || c === 'U' maxiter = c === 'x' ? 2 : c === 'u' ? 4 : 8 n = 0 - for _ in 1:min(length(a), maxiter) + for _ in 1:maxiter + isempty(a) && break nc = popfirst!(a) n = '0' <= nc <= '9' ? n << 4 + (nc - '0') : 'a' <= nc <= 'f' ? n << 4 + (nc - 'a' + 10) : @@ -564,7 +565,8 @@ else ok = n <= 0x10ffff elseif '0' <= c <= '7' n = c - '0' - for _ in 1:min(length(a), 3) + for _ in 1:3 + isempty(a) && break nc = popfirst!(a) n = ('0' <= c <= '7') ? n << 3 + nc - '0' : return false end