Explorar o código

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 hai 7 meses
pai
achega
0a15075c00
Modificáronse 1 ficheiros con 6 adicións e 1 borrados
  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
 	}