Permalink
Browse files

Extracted string size check so that it's only run once at most.

  • Loading branch information...
1 parent 60dfffe commit 5c61c5f9b14052e2553d85356b5dac6bc9189715 @richard-lyman committed Aug 4, 2012
Showing with 3 additions and 2 deletions.
  1. +3 −2 src/com/lithinos/amotoen/core.clj
@@ -30,11 +30,12 @@
The function 'charAt' is part of the mechanism to walk through the string."
([#^String s] (wrap-string s 0))
([#^String s j] ; 'j' is where we currently are in the input... 'i' was skipped since it was too close to 'i'nput
- (let [a (int-array 1 j)]
+ (let [a (int-array 1 j)
+ size (count s)]
(reify IAmotoen
(gp [t] (aget a 0))
(sp [t k] (aset-int a 0 k))
- (end [t] (= (aget a 0) (count s)))
+ (end [t] (= (aget a 0) size))
(c [t] (try (.charAt s (aget a 0)) (catch Exception e nil)))
(m [t] (let [r (c t)]
(when (nil? r) (throw (Exception. "Consuming nil")))

0 comments on commit 5c61c5f

Please sign in to comment.