From f5529ed12a3b6de478e30fdfbfe74ed787f65234 Mon Sep 17 00:00:00 2001 From: Artemis Everfree Date: Wed, 22 Mar 2023 21:45:09 -0700 Subject: [PATCH] precompile regexp patterns --- lib/tree-updater.rkt | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/tree-updater.rkt b/lib/tree-updater.rkt index 074c5a1..6c369b5 100644 --- a/lib/tree-updater.rkt +++ b/lib/tree-updater.rkt @@ -66,6 +66,11 @@ (iframe (@ (src "https://example.com/iframe-src"))))))) (define (updater wikiname #:strict-proxy? [strict-proxy? #f]) + ;; precompute wikiurl regex for efficency + (define wikiurl-regex (pregexp (format "^https://(~a)\\.fandom\\.com(/wiki/.*)$" px-wikiname))) + ;; precompute link replacement string for efficiency + (define wiki-substitution (format "/~a\\1" wikiname)) + (define classlist-updater (compose1 ; uncollapse all navbox items (bottom of page mass navigation) @@ -110,8 +115,8 @@ (curry attribute-maybe-update 'href (λ (href) ((compose1 - (λ (href) (regexp-replace #rx"^(/wiki/.*)" href (format "/~a\\1" wikiname))) - (λ (href) (regexp-replace (pregexp (format "^https://(~a)\\.fandom\\.com(/wiki/.*)" px-wikiname)) href "/\\1\\2"))) + (λ (href) (regexp-replace #rx"^(/wiki/.*)$" href wiki-substitution)) + (λ (href) (regexp-replace wikiurl-regex href "/\\1\\2"))) href))) ; add noreferrer to a.image (curry u