Skip to content

Commit 3ba6b9d

Browse files
committed
Add specialized context-interval for vectors.
1 parent e7df403 commit 3ba6b9d

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

contexts.lisp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,13 @@
8585
(call-next-method)))))))
8686

8787
(defgeneric context-interval (context1 context2 &optional result-type)
88-
(:method ((context1 context) (context2 context) &optional (result-type 'string))
88+
(:method :before ((context1 context) (context2 context) &optional result-type)
89+
(declare (ignore result-type))
8990
(assert (eql (common-of context1)
9091
(common-of context2)))
9192
(assert (<= (position-of context1)
92-
(position-of context2)))
93+
(position-of context2))))
94+
(:method ((context1 context) (context2 context) &optional (result-type 'string))
9395
(if (= (position-of context1) (position-of context2))
9496
(coerce nil result-type)
9597
(coerce (iter (for c initially context1 then (context-next c))
@@ -143,6 +145,14 @@
143145
(defmethod context-peek ((context vector-context))
144146
(aref (storage-of context) (position-of context)))
145147

148+
(defmethod context-interval ((context1 vector-context) (context2 vector-context) &optional (result-type 'string))
149+
(let ((storage (storage-of context1)))
150+
(coerce (subseq storage (position-of context1) (position-of context2)) result-type)))
151+
152+
(defmethod context-interval ((context1 vector-context) (context2 end-context) &optional (result-type 'string))
153+
(let ((storage (storage-of context1)))
154+
(coerce (subseq storage (position-of context1)) result-type)))
155+
146156
(defvar *default-context-cache* :vector)
147157

148158
(defun make-cache (cache-type length)

0 commit comments

Comments
 (0)