From fd6520dbe88a834421426147e2f1c1373be2ef31 Mon Sep 17 00:00:00 2001 From: alex-eg Date: Wed, 14 Oct 2026 20:07:20 +0300 Subject: [PATCH] compile the name spellings once, and skip a name that has none Read from a table, the patterns were compiled again for every symbol written; that tripled what unkebabify cost. --- fmt-c-writer.scm | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/fmt-c-writer.scm b/fmt-c-writer.scm index 0ddd64d..de7562f 100644 --- a/fmt-c-writer.scm +++ b/fmt-c-writer.scm @@ -133,17 +133,19 @@ forms, and what remains." ;;; exclamation mark, both letters. Not the retroflex click ǃ, which ;;; looks more like `!' -- enough that clang warns at every use. (define +name-spellings+ - '(("-(?!>)" . "_") ("/" . "ː") ("\\?" . "ʔ") ("!" . "ꜝ"))) + (map (lambda (spelling) (cons (irregex (car spelling)) (cdr spelling))) + '(("-(?!>)" . "_") ("/" . "ː") ("\\?" . "ʔ") ("!" . "ꜝ")))) (define (unkebabify sym) - (case sym - ((- -- -> -= / /= ! != ?) sym) ; bare operators, not names - (else - (string->symbol - (fold (lambda (spelling name) - (irregex-replace/all (car spelling) name (cdr spelling))) - (symbol->string sym) - +name-spellings+))))) + (let ((name (symbol->string sym))) + (if (or (memq sym '(- -- -> -= / /= ! != ?)) ; bare operators, not names + (not (string-index name (lambda (c) (memv c '(#\- #\/ #\? #\!)))))) + sym + (string->symbol + (fold (lambda (spelling name) + (irregex-replace/all (car spelling) name (cdr spelling))) + name + +name-spellings+))))) (define (atom-to-fmt-c atom) (case atom