From 3f1946a3b8b061b7f8a03e1681471212ff79ac71 Mon Sep 17 00:00:00 2001 From: Artemis Everfree Date: Wed, 22 Mar 2023 21:44:40 -0700 Subject: [PATCH] use faster string split --- lib/xexpr-utils.rkt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/xexpr-utils.rkt b/lib/xexpr-utils.rkt index 018d8c3..cb40510 100644 --- a/lib/xexpr-utils.rkt +++ b/lib/xexpr-utils.rkt @@ -190,7 +190,9 @@ '(body "Hey" (& nbsp) (a (@ (href "/")))))) (define (has-class? name attributes) - (and (member name (string-split (or (get-attribute 'class attributes) "") " ")) #t)) + ;; splitting without specifying separator or splitting on #px"\\s+" makes + ;; string-split use a faster whitespace-specialized implementation. + (and (member name (string-split (or (get-attribute 'class attributes) "") #px"\\s+")) #t)) (module+ test (check-true (has-class? "red" '((class "yellow red blue")))) (check-false (has-class? "red" '((class "yellow blue"))))