cref: Replace alists with lists.
authorMatt Birkholz <matt@birkholz.chandler.az.us>
Wed, 1 Feb 2012 18:29:49 +0000 (11:29 -0700)
committerMatt Birkholz <matt@birkholz.chandler.az.us>
Wed, 1 Feb 2012 18:29:49 +0000 (11:29 -0700)
Even alists are too much when bindings and references already contain
the name.  Use find-matching-item rather than assq&cdr!

src/cref/object.scm
src/cref/redpkg.scm

index 5b95f4ac560f34e0c1b0729e0d2dc17dcf6c754b..5a021d34e3f7c959711d337a8fca1ce14e4c4319 100644 (file)
@@ -59,8 +59,8 @@ USA.
   (files '())
   parent
   (children '())
-  (%bindings '())
-  (%references '())
+  (bindings '())
+  (references '())
   (links '()))
 
 (define-integrable (package/n-files package)
@@ -70,26 +70,20 @@ USA.
   (null? (package/name package)))
 
 (define-integrable (package/find-reference package name)
-  (let ((entry (assq name (package/%references package))))
-    (and entry (cdr entry))))
+  (find-matching-item (package/references package)
+                     (lambda (ref) (eq? (reference/name ref) name))))
 
-(define-integrable (package/put-reference! package name reference)
-  (set-package/%references! package (cons (cons name reference)
-                                         (package/%references package))))
+(define-integrable (package/put-reference! package reference)
+  (set-package/references! package
+                          (cons reference (package/references package))))
 
 (define-integrable (package/find-binding package name)
-  (let ((entry (assq name (package/%bindings package))))
-    (and entry (cdr entry))))
-
-(define-integrable (package/put-binding! package name binding)
-  (set-package/%bindings! package (cons (cons name binding)
-                                       (package/%bindings package))))
-
-(define-integrable (package/bindings package)
-  (map cdr (package/%bindings package)))
+  (find-matching-item (package/bindings package)
+                     (lambda (ref) (eq? (binding/name ref) name))))
 
-(define-integrable (package/references package)
-  (map cdr (package/%references package)))
+(define-integrable (package/put-binding! package binding)
+  (set-package/bindings! package
+                        (cons binding (package/bindings package))))
 
 (define-integrable (file-case/type file-case)
   (car file-case))
index d8afa7c5c0e0a8a177763af233d5d6701a0e07ea..b4e8a55e04ffd7c69e46ac019420370728429b2a 100644 (file)
@@ -640,9 +640,7 @@ USA.
                                          destination-name
                                          (binding/value-cell source-binding)
                                          new?)))
-                      (package/put-binding! destination-package
-                                            destination-name
-                                            binding)
+                      (package/put-binding! destination-package binding)
                       binding)))
               owner-package
               new?)))
@@ -658,7 +656,7 @@ USA.
                 (let ((binding (make-binding package name value-cell new?)))
                   (set-value-cell/source-binding! value-cell binding)
                   binding))))
-         (package/put-binding! package name binding)
+         (package/put-binding! package binding)
          binding))))
 
 (define (make-reference package name expression)
@@ -677,6 +675,6 @@ USA.
                (add-reference! reference))
            reference)
          (let ((reference (%make-reference package name)))
-           (package/put-reference! package name reference)
+           (package/put-reference! package reference)
            (add-reference! reference)
            reference)))))
\ No newline at end of file