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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user