Bläddra i källkod

refactor(sanitizer): save some cycles in hasRequiredAttributes

There is no need to iterate twice on the attributes of source and img tags,
when we can do it once. This shouldn't bring any noticeable performances
improvements, except maybe in some extreme cases on pages with a lot of images
with a lot of attributes.
jvoisin 6 månader sedan
förälder
incheckning
0a15075c00
1 ändrade filer med 6 tillägg och 1 borttagningar
  1. 6 1
      internal/reader/sanitizer/sanitizer.go

+ 6 - 1
internal/reader/sanitizer/sanitizer.go

@@ -467,7 +467,12 @@ func hasRequiredAttributes(tagName string, attributes []string) bool {
 	case "iframe":
 		return slices.Contains(attributes, "src")
 	case "source", "img":
-		return slices.Contains(attributes, "src") || slices.Contains(attributes, "srcset")
+		for _, attribute := range attributes {
+			if attribute == "src" || attribute == "srcset" {
+				return true
+			}
+		}
+		return false
 	default:
 		return true
 	}