The behavior of subs is undefined in the following case: (subs "" 1).
subs
(subs "" 1)
Yet, re-seq calls subs like this in the following expression (re-seq #"a" "a").
re-seq
(re-seq #"a" "a")
In the expression (re-seq #"a" "") a call is made like (subs "" -1) which is also undefined.
(re-seq #"a" "")
(subs "" -1)
re-seq doesn't actually use the result of these undefined calls, but we are relying on the undefined behavior that this doesn't throw.
Solution in patch: only make call to subs when needed.
The patch also optimizes the case where match-data is nil.
match-data
nil
CLJS-2979-2.patch contains various optimizations which lead to the following speedups:
tested with
Credits to Mike Fikes and Jesse Wertheim for providing many optimization suggestions.
The behavior of
subs
is undefined in the following case:(subs "" 1)
.Yet,
re-seq
callssubs
like this in the following expression(re-seq #"a" "a")
.In the expression
(re-seq #"a" "")
a call is made like(subs "" -1)
which is also undefined.re-seq
doesn't actually use the result of these undefined calls, but we are relying on the undefined behavior that this doesn't throw.Solution in patch: only make call to
subs
when needed.The patch also optimizes the case where
match-data
isnil
.CLJS-2979-2.patch contains various optimizations which lead to the following speedups:
tested with
Credits to Mike Fikes and Jesse Wertheim for providing many optimization suggestions.