From 237672a62c9c1cbadf7ca8b0d0e9df1177774eb1 Mon Sep 17 00:00:00 2001 From: jvoisin Date: Mon, 16 Jun 2025 12:36:28 +0200 Subject: [PATCH] perf(sanitizer): use a switch-case instead of a map This removes a heap allocation, and should be way faster. It also makes the code shorted/simpler. --- internal/reader/sanitizer/sanitizer.go | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/internal/reader/sanitizer/sanitizer.go b/internal/reader/sanitizer/sanitizer.go index 0b282057..677fc218 100644 --- a/internal/reader/sanitizer/sanitizer.go +++ b/internal/reader/sanitizer/sanitizer.go @@ -180,12 +180,6 @@ var ( "hack": {}, // https://apps.apple.com/it/app/hack-for-hacker-news-reader/id1464477788?l=en-GB } - blockedTags = map[string]struct{}{ - "noscript": {}, - "script": {}, - "style": {}, - } - dataAttributeAllowedPrefixes = []string{ "data:image/avif", "data:image/apng", @@ -537,8 +531,12 @@ func rewriteIframeURL(link string) string { } func isBlockedTag(tagName string) bool { - _, ok := blockedTags[tagName] - return ok + switch tagName { + case "noscript", "script", "style": + return true + default: + return false + } } func sanitizeSrcsetAttr(baseURL, value string) string {