Skip to content

Commit

Permalink
Improve performance of match? by avoiding handler-case.
Browse files Browse the repository at this point in the history
  • Loading branch information
fukamachi committed Jul 31, 2015
1 parent f0ecdad commit d612fb2
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions src/proc-parse.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -306,11 +306,13 @@
(with-gensyms (start start-elem)
`(let ((,start ,',p)
(,start-elem ,',elem))
(handler-case
(progn (match ,@vectors) t)
(match-failed ()
(setq ,',p ,start
,',elem ,start-elem) nil)))))
(block match?-block
(tagbody
(match ,@vectors)
(return-from match?-block t)
:match-failed
(setq ,',p ,start
,',elem ,start-elem))))))
(match-i (&rest vectors)
`(match-i-case
,@(loop for vec in vectors
Expand Down Expand Up @@ -353,7 +355,7 @@
,@(if (find 'otherwise cases :key #'car :test #'eq)
cases
(append cases
'((otherwise (error 'match-failed))))))
'((otherwise (go :match-failed))))))
(when (eofp) (go :eof))))
(match-i-case (&rest cases)
(check-match-cases cases)
Expand All @@ -362,14 +364,16 @@
,@(if (find 'otherwise cases :key #'car :test #'eq)
cases
(append cases
'((otherwise (error 'match-failed))))))
'((otherwise (go :match-failed))))))
(when (eofp) (go :eof)))))
(block ,body-block
(tagbody
(when (eofp)
(go :eof))
(setq ,elem (aref ,data ,p))
(return-from ,body-block (progn ,@body))
:match-failed
(error 'match-failed)
:eof)))))))

(defmacro with-octets-parsing ((data &key start end) &body body)
Expand Down Expand Up @@ -407,7 +411,7 @@
,@(if (find 'otherwise cases :key #'car :test #'eq)
cases
(append cases
'((otherwise (error 'match-failed))))))
'((otherwise (go :match-failed))))))
(when (eofp) (go :eof))))
(match-i-case (&rest cases)
(check-match-cases cases)
Expand All @@ -423,14 +427,16 @@
,@(if (find 'otherwise cases :key #'car :test #'eq)
cases
(append cases
'((otherwise (error 'match-failed))))))
'((otherwise (go :match-failed))))))
(when (eofp) (go :eof)))))
(block ,body-block
(tagbody
(when (eofp)
(go :eof))
(setq ,elem (aref ,data ,p))
(return-from ,body-block (progn ,@body))
:match-failed
(error 'match-failed)
:eof)))))))

(defmacro with-vector-parsing ((data &key (start 0) end) &body body &environment env)
Expand Down

0 comments on commit d612fb2

Please sign in to comment.