utils: Micro-optimize 'source-properties->location'.
* guix/utils.scm (source-properties->location): Destructure LOC with 'match', adding a fast path without 'assq-ref' calls.
This commit is contained in:
		
							parent
							
								
									3059a35afe
								
							
						
					
					
						commit
						223fa5b327
					
				
					 1 changed files with 13 additions and 6 deletions
				
			
		| 
						 | 
					@ -782,12 +782,19 @@ be determined."
 | 
				
			||||||
  "Return a location object based on the info in LOC, an alist as returned
 | 
					  "Return a location object based on the info in LOC, an alist as returned
 | 
				
			||||||
by Guile's `source-properties', `frame-source', `current-source-location',
 | 
					by Guile's `source-properties', `frame-source', `current-source-location',
 | 
				
			||||||
etc."
 | 
					etc."
 | 
				
			||||||
 | 
					  ;; In accordance with the GCS, start line and column numbers at 1.  Note
 | 
				
			||||||
 | 
					  ;; that unlike LINE and `port-column', COL is actually 1-indexed here...
 | 
				
			||||||
 | 
					  (match loc
 | 
				
			||||||
 | 
					    ((('line . line) ('column . col) ('filename . file)) ;common case
 | 
				
			||||||
 | 
					     (and file line col
 | 
				
			||||||
 | 
					          (make-location file (+ line 1) col)))
 | 
				
			||||||
 | 
					    (#f
 | 
				
			||||||
 | 
					     #f)
 | 
				
			||||||
 | 
					    (_
 | 
				
			||||||
     (let ((file (assq-ref loc 'filename))
 | 
					     (let ((file (assq-ref loc 'filename))
 | 
				
			||||||
           (line (assq-ref loc 'line))
 | 
					           (line (assq-ref loc 'line))
 | 
				
			||||||
           (col  (assq-ref loc 'column)))
 | 
					           (col  (assq-ref loc 'column)))
 | 
				
			||||||
    ;; In accordance with the GCS, start line and column numbers at 1.  Note
 | 
					       (location file (and line (+ line 1)) col)))))
 | 
				
			||||||
    ;; that unlike LINE and `port-column', COL is actually 1-indexed here...
 | 
					 | 
				
			||||||
    (location file (and line (+ line 1)) col)))
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
(define (location->source-properties loc)
 | 
					(define (location->source-properties loc)
 | 
				
			||||||
  "Return the source property association list based on the info in LOC,
 | 
					  "Return the source property association list based on the info in LOC,
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Reference in a new issue