r11480: make field position lookup more efficient by computing 'eq key at compile...
authorKevin M. Rosenberg <kevin@rosenberg.net>
Mon, 8 Jan 2007 13:00:12 +0000 (13:00 +0000)
committerKevin M. Rosenberg <kevin@rosenberg.net>
Mon, 8 Jan 2007 13:00:12 +0000 (13:00 +0000)
parse-common.lisp
parse-rrf.lisp

index a0c7c2afce6afea1c94dbc0c132041be7d42238d..f712e7627dd632b3ad651cc69d29f1303043764e 100644 (file)
@@ -230,25 +230,24 @@ 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 'equal))
+(defvar *position-hash* (make-hash-table :test 'eq))
 
-(defun position-field-file (filename fieldname)
+(defun position-field-file (filename fieldname key)
   "Returns the position of a field in a file"
-  (let ((key (cons filename fieldname)))
-    (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)
+  (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)
+      (return-from position-field-file nil))
+    (let ((pos (position fieldname (fields ufile) :test #'string=)))
+      (unless pos
+        (warn "Unable to find field ~A in ufile ~S." fieldname ufile)
         (return-from position-field-file nil))
-      (let ((pos (position fieldname (fields ufile) :test #'string=)))
-        (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))))
+      (setf (gethash key *position-hash*) pos)
+      pos)))
 
 (defun find-ucols-for-ufile (ufile)
   "Returns list of umls-cols for a file structure"
index 8a1bb1ebd47f116fcd5cdc7710a50d9634cdf83e..e8e919de245a0e34da419ac546bf35b7072cfc9c 100644 (file)
@@ -187,13 +187,14 @@ 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")
 
-(declaim (inline vff))
-(defun vff (filename fieldname record)
-  (let ((pos (position-field-file filename fieldname)))
-    (unless pos
-      (error "Did not find fieldname ~A in filename ~A." fieldname filename))
-    (locally (declare (fixnum pos))
-      (nth pos record))))
+(defmacro vff (filename fieldname record)
+  (let ((pos (gensym "POS-"))
+        (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)))))
 
 (defparameter +custom-cols+
     '(#+nil ("MRCONSO.RRF" "KPFSTR" "TEXT"