Optimize write-derivation' and derivation-path->output-path'.
				
					
				
			* guix/derivations.scm (write-derivation): Explicitly use `simple-format'. (derivation-path->output-path): Memoize.
This commit is contained in:
		
							parent
							
								
									f39bd08ad2
								
							
						
					
					
						commit
						aaa848f3af
					
				
					 1 changed files with 12 additions and 5 deletions
				
			
		| 
						 | 
					@ -200,6 +200,10 @@ available in STORE, recursively."
 | 
				
			||||||
  "Write the ATerm-like serialization of DRV to PORT.  See Section 2.4 of
 | 
					  "Write the ATerm-like serialization of DRV to PORT.  See Section 2.4 of
 | 
				
			||||||
Eelco Dolstra's PhD dissertation for an overview of a previous version of
 | 
					Eelco Dolstra's PhD dissertation for an overview of a previous version of
 | 
				
			||||||
that form."
 | 
					that form."
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  ;; Make sure we're using the faster implementation.
 | 
				
			||||||
 | 
					  (define format simple-format)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  (define (list->string lst)
 | 
					  (define (list->string lst)
 | 
				
			||||||
    (string-append "[" (string-join lst ",") "]"))
 | 
					    (string-append "[" (string-join lst ",") "]"))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -269,12 +273,15 @@ that form."
 | 
				
			||||||
                              (string<? (car e1) (car e2))))))
 | 
					                              (string<? (car e1) (car e2))))))
 | 
				
			||||||
     (display ")" port))))
 | 
					     (display ")" port))))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
(define* (derivation-path->output-path path #:optional (output "out"))
 | 
					(define derivation-path->output-path
 | 
				
			||||||
  "Read the derivation from PATH (`/nix/store/xxx.drv'), and return the store
 | 
					  ;; This procedure is called frequently, so memoize it.
 | 
				
			||||||
 | 
					  (memoize
 | 
				
			||||||
 | 
					   (lambda* (path #:optional (output "out"))
 | 
				
			||||||
 | 
					     "Read the derivation from PATH (`/nix/store/xxx.drv'), and return the store
 | 
				
			||||||
path of its output OUTPUT."
 | 
					path of its output OUTPUT."
 | 
				
			||||||
  (let* ((drv     (call-with-input-file path read-derivation))
 | 
					     (let* ((drv     (call-with-input-file path read-derivation))
 | 
				
			||||||
         (outputs (derivation-outputs drv)))
 | 
					            (outputs (derivation-outputs drv)))
 | 
				
			||||||
    (and=> (assoc-ref outputs output) derivation-output-path)))
 | 
					       (and=> (assoc-ref outputs output) derivation-output-path)))))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
;;;
 | 
					;;;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Reference in a new issue