Skip to content
Browse files

Add build-slice to mmap-index-input and buffered-index-input.

  • Loading branch information...
1 parent c274cd8 commit ee101395c8b7a1a86a057446a4831df481efcaa8 @quek committed Oct 13, 2012
View
5 src/index/compound-file-io.lisp
@@ -49,10 +49,7 @@
(let ((entry (table-value entries id)))
(if (null entry)
(error "No sub-file with id ~S found in ~S" id self)
- (make-instance 'cs-index-input
- :base stream
- :file-offset (offset entry)
- :size (size entry))))))
+ (build-slice stream (offset entry) (size entry))))))
(defmethod files ((self compound-file-reader))
(with-slots (entries) self
View
2 src/index/segment-merger.lisp
@@ -289,7 +289,7 @@
(unwind-protect
(dosequence (reader readers)
(let* ((max-doc (max-doc reader))
- (input (make-array max-doc)))
+ (input (make-array max-doc :element-type '(unsigned-byte 8))))
(get-norms-into reader (field-name fi) input 0)
(dotimes (k max-doc)
(unless (deleted-p reader k)
View
2 src/index/segment-reader.lisp
@@ -234,7 +234,7 @@
nil
(progn
(when (null (bytes norm))
- (let ((bytes (make-array (max-doc self) :initial-element #\space)))
+ (let ((bytes (make-array (max-doc self) :element-type '(unsigned-byte 8))))
(get-norms-into self field bytes 0)
(setf (bytes norm) bytes)))
(bytes norm)))))
View
6 src/store/buffered-index-io.lisp
@@ -160,3 +160,9 @@
(setf buffer-start start)
(setf buffer-position 0))))
+
+(defmethod build-slice ((self buffered-index-input) offset length)
+ (make-instance 'cs-index-input
+ :base self
+ :file-offset offset
+ :size length))
View
2 src/store/index-io.lisp
@@ -1,5 +1,7 @@
(in-package #:montezuma)
+(defgeneric build-slice (index-input offset length))
+
(defclass index-input ()
())
View
22 src/store/mmap-store.lisp
@@ -7,7 +7,8 @@
(defclass mmap-index-input (index-input)
((addr)
(size :reader size :type 'fixnum)
- (position :initform 0 :type 'fixnum)))
+ (position :initform 0 :type 'fixnum)
+ (is-clone-p :initform nil)))
(defmethod open-input ((self mmap-directory) file)
@@ -27,6 +28,12 @@
0)))
(osicat-posix:close fd))))
+(defmethod initialize-copy :after ((self mmap-index-input) other)
+ (declare (ignore other))
+ (with-slots (is-clone-p) self
+ (setf is-clone-p t)))
+
+
(defmethod read-byte ((self mmap-index-input))
(with-slots (addr position) self
(prog1 (cffi:mem-ref addr :unsigned-char position)
@@ -49,9 +56,18 @@
(setf position pos)))
(defmethod close ((self mmap-index-input))
- (with-slots (addr size) self
- (osicat-posix:munmap addr size)))
+ (with-slots (addr size is-clone-p) self
+ (unless is-clone-p
+ (osicat-posix:munmap addr size))))
(defmethod size ((self mmap-index-input))
(with-slots (size) self
size))
+
+(defmethod build-slice ((self mmap-index-input) offset length)
+ (let ((clone (clone self)))
+ (with-slots (addr size position) clone
+ (cffi:incf-pointer addr offset)
+ (setf size length)
+ (setf position 0)
+ clone)))

0 comments on commit ee10139

Please sign in to comment.
Something went wrong with that request. Please try again.