aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2018-07-02 14:49:14 +0200
committerLudovic Courtès <ludo@gnu.org>2018-07-02 15:28:35 +0200
commit223fa5b327b0892cf45d22e4a9fbfb06164e409d (patch)
tree7784b68f3697da889cb063007d4e9c3a59583054
parent3059a35afe3f0ff2561870e0a0fb21e03fc3247a (diff)
downloadgnu-guix-223fa5b327b0892cf45d22e4a9fbfb06164e409d.tar
gnu-guix-223fa5b327b0892cf45d22e4a9fbfb06164e409d.tar.gz
utils: Micro-optimize 'source-properties->location'.
* guix/utils.scm (source-properties->location): Destructure LOC with 'match', adding a fast path without 'assq-ref' calls.
-rw-r--r--guix/utils.scm19
1 files changed, 13 insertions, 6 deletions
diff --git a/guix/utils.scm b/guix/utils.scm
index 9fbb95d31c..f934b6ed13 100644
--- a/guix/utils.scm
+++ b/guix/utils.scm
@@ -782,12 +782,19 @@ be determined."
"Return a location object based on the info in LOC, an alist as returned
by Guile's `source-properties', `frame-source', `current-source-location',
etc."
- (let ((file (assq-ref loc 'filename))
- (line (assq-ref loc 'line))
- (col (assq-ref loc 'column)))
- ;; 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...
- (location file (and line (+ line 1)) col)))
+ ;; 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))
+ (line (assq-ref loc 'line))
+ (col (assq-ref loc 'column)))
+ (location file (and line (+ line 1)) col)))))
(define (location->source-properties loc)
"Return the source property association list based on the info in LOC,