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.
This commit is contained in:
2026-10-14 20:07:20 +03:00
parent 4ad4133d92
commit fd6520dbe8

View File

@@ -133,16 +133,18 @@ forms, and what remains."
;;; exclamation mark, both letters. Not the retroflex click ǃ, which ;;; exclamation mark, both letters. Not the retroflex click ǃ, which
;;; looks more like `!' -- enough that clang warns at every use. ;;; looks more like `!' -- enough that clang warns at every use.
(define +name-spellings+ (define +name-spellings+
'(("-(?!>)" . "_") ("/" . "ː") ("\\?" . "ʔ") ("!" . "ꜝ"))) (map (lambda (spelling) (cons (irregex (car spelling)) (cdr spelling)))
'(("-(?!>)" . "_") ("/" . "ː") ("\\?" . "ʔ") ("!" . "ꜝ"))))
(define (unkebabify sym) (define (unkebabify sym)
(case sym (let ((name (symbol->string sym)))
((- -- -> -= / /= ! != ?) sym) ; bare operators, not names (if (or (memq sym '(- -- -> -= / /= ! != ?)) ; bare operators, not names
(else (not (string-index name (lambda (c) (memv c '(#\- #\/ #\? #\!))))))
sym
(string->symbol (string->symbol
(fold (lambda (spelling name) (fold (lambda (spelling name)
(irregex-replace/all (car spelling) name (cdr spelling))) (irregex-replace/all (car spelling) name (cdr spelling)))
(symbol->string sym) name
+name-spellings+))))) +name-spellings+)))))
(define (atom-to-fmt-c atom) (define (atom-to-fmt-c atom)