cs: cache object-name
for procedures
Extracting the name from a procedure involves `string->symbol` and possibly some string parsing. Map the code object to the result symbol to speed up multiple requests for the same code object.
This commit is contained in:
parent
f5f2cd9345
commit
272271f36f
|
@ -24,6 +24,8 @@
|
||||||
"(or/c exact-nonnegative-integer? (procedure-arity-includes/c 1))"
|
"(or/c exact-nonnegative-integer? (procedure-arity-includes/c 1))"
|
||||||
v)]))))
|
v)]))))
|
||||||
|
|
||||||
|
(define-thread-local procedure-names (make-weak-eq-hashtable))
|
||||||
|
|
||||||
(define (object-name v)
|
(define (object-name v)
|
||||||
(cond
|
(cond
|
||||||
[(object-name? v)
|
[(object-name? v)
|
||||||
|
@ -38,10 +40,16 @@
|
||||||
[(wrapper-procedure? v)
|
[(wrapper-procedure? v)
|
||||||
(extract-wrapper-procedure-name v)]
|
(extract-wrapper-procedure-name v)]
|
||||||
[else
|
[else
|
||||||
(let ([name (#%$code-name (#%$closure-code v))])
|
(let ([names procedure-names]
|
||||||
(and name
|
[code (#%$closure-code v)])
|
||||||
(let ([n (procedure-name-string->visible-name-string name)])
|
(or (eq-hashtable-ref names code #f)
|
||||||
(and n (string->symbol n)))))])]
|
(let ([name (#%$code-name code)])
|
||||||
|
(and name
|
||||||
|
(let ([n (procedure-name-string->visible-name-string name)])
|
||||||
|
(and n
|
||||||
|
(let ([sym (string->symbol n)])
|
||||||
|
(eq-hashtable-set! names code sym)
|
||||||
|
sym)))))))])]
|
||||||
[(impersonator? v)
|
[(impersonator? v)
|
||||||
(object-name (impersonator-val v))]
|
(object-name (impersonator-val v))]
|
||||||
[(procedure? v)
|
[(procedure? v)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user