From 965bf11233f305fcb6635c319756a96c4c4202af Mon Sep 17 00:00:00 2001 From: "Kevin M. Rosenberg" Date: Mon, 8 Jan 2007 13:19:15 +0000 Subject: [PATCH] r11481: make vff macro more efficient --- parse-common.lisp | 9 +-------- parse-rrf.lisp | 20 +++++++++++++++----- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/parse-common.lisp b/parse-common.lisp index f712e76..4c2855e 100644 --- a/parse-common.lisp +++ b/parse-common.lisp @@ -230,14 +230,8 @@ Currently, these are the LEX and NET files." "Returns umls-file structure for a filename" (find-if #'(lambda (f) (string= filename (fil f))) *umls-files*)) -(defvar *position-hash* (make-hash-table :test 'eq)) - -(defun position-field-file (filename fieldname key) +(defun position-field-file (filename fieldname) "Returns the position of a field in a file" - (multiple-value-bind (pos found) (gethash key *position-hash*) - (if found - (return-from position-field-file pos))) - (let ((ufile (find-ufile filename))) (unless ufile (warn "Unable to find ufile for filename ~A." filename) @@ -246,7 +240,6 @@ Currently, these are the LEX and NET files." (unless pos (warn "Unable to find field ~A in ufile ~S." fieldname ufile) (return-from position-field-file nil)) - (setf (gethash key *position-hash*) pos) pos))) (defun find-ucols-for-ufile (ufile) diff --git a/parse-rrf.lisp b/parse-rrf.lisp index e8e919d..90a11fc 100644 --- a/parse-rrf.lisp +++ b/parse-rrf.lisp @@ -187,14 +187,24 @@ used in the United States. We create a new scale (SRLUS) where SRL to SRLUS mapp '(("KCON" "SELECT CUI,STR FROM MRCONSO WHERE STT='PF' AND TS='P' AND ISPREF='Y' AND LAT='ENG'")) "Custom tables to create") +(defvar *vff-position-hash* (make-hash-table :size 100 :test 'eq)) + + (defmacro vff (filename fieldname record) (let ((pos (gensym "POS-")) + (found (gensym "FOUND-")) (key (kmrcl:ensure-keyword (concatenate 'string filename "^" fieldname)))) - `(let ((,pos (position-field-file ,filename ,fieldname ,key))) - (unless ,pos - (error "Did not find fieldname ~A in filename ~A." ,fieldname ,filename)) - (locally (declare (type (integer 0 100000) ,pos)) - (nth ,pos ,record))))) + `(locally (declare (optimize (speed 3) (size 0) (safety 0))) + (multiple-value-bind (,pos ,found) (gethash ,key *vff-position-hash*) + (if ,pos + (locally (declare (type (integer 0 100000) ,pos)) + (nth ,pos ,record)) + (let ((,pos (position-field-file ,filename ,fieldname))) + (unless ,pos + (error "Did not find fieldname ~A in filename ~A." ,fieldname ,filename)) + (locally (declare (type (integer 0 100000) ,pos)) + (setf (gethash ,key *vff-position-hash*) ,pos) + (nth ,pos ,record)))))))) (defparameter +custom-cols+ '(#+nil ("MRCONSO.RRF" "KPFSTR" "TEXT" -- 2.34.1