From 2397e0c8e2d7bec7649db2f57dea4ae53a9bd269 Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Sat, 18 Mar 2017 19:12:25 +0100 Subject: [PATCH] mescc: Refactor function-offset. * module/mes/elf-util.mes (function-offset): Recurse down. Factor 5 speedup on mini-mes.c. --- module/mes/elf-util.mes | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/module/mes/elf-util.mes b/module/mes/elf-util.mes index 82e5aca4..7a8eeb0e 100644 --- a/module/mes/elf-util.mes +++ b/module/mes/elf-util.mes @@ -72,11 +72,15 @@ (let ((cache '())) (lambda (name functions) (or (assoc-ref cache name) - (let* ((prefix (function-prefix name functions)) - (offset (if prefix (length (functions->text (cdr prefix) '() 0 0 0)) - 0))) - (if (and prefix (or (equal? name "exit") (> offset 0))) (set! cache (assoc-set! cache name offset))) - offset))))) + (let* ((functions (if (and (pair? functions) (equal? (caar functions) "exit")) functions (reverse functions))) + (prefix (and=> (function-prefix name functions) cdr)) + (offset (and prefix + (if (null? prefix) 0 + (+ (length (functions->text (list (car prefix)) '() 0 0 0)) + (if (null? (cdr prefix)) 0 + (function-offset (caar prefix) functions))))))) + (if (and offset (or (equal? name "exit") (> offset 0))) (set! cache (assoc-set! cache name offset))) + (or offset 0)))))) (define label-offset (let ((cache '()))