mirror of
https://github.com/miniflux/v2.git
synced 2025-08-06 17:41:00 +00:00
perf(sanitizer): improve the performances of the sanitizer (#3497)
- Grow the underlying buffer of SanitizeHTML's strings.Builder to 3/4 of the raw HTML from the start, to reduce the amount of iterative allocations. This number is a complete guesstimation, but it sounds reasonable to me. - Add a `absoluteURLParsedBase` function to avoid parsing baseURL over and over.
This commit is contained in:
parent
15e4c3a374
commit
a8b4e88742
2 changed files with 48 additions and 15 deletions
|
@ -18,22 +18,34 @@ func IsAbsoluteURL(link string) bool {
|
|||
return u.IsAbs()
|
||||
}
|
||||
|
||||
// AbsoluteURL converts the input URL as absolute URL if necessary.
|
||||
func AbsoluteURL(baseURL, input string) (string, error) {
|
||||
// GetAbsoluteURL return the absolute form of `input` is possible, as well as its parser form.
|
||||
func GetAbsoluteURL(input string) (string, *url.URL, error) {
|
||||
if strings.HasPrefix(input, "//") {
|
||||
return "https:" + input, nil
|
||||
return "https:" + input, nil, nil
|
||||
}
|
||||
if strings.HasPrefix(input, "https://") || strings.HasPrefix(input, "http://") {
|
||||
return input, nil
|
||||
return input, nil, nil
|
||||
}
|
||||
|
||||
u, err := url.Parse(input)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("unable to parse input URL: %v", err)
|
||||
return "", nil, fmt.Errorf("unable to parse input URL: %v", err)
|
||||
}
|
||||
|
||||
if u.IsAbs() {
|
||||
return u.String(), nil
|
||||
return u.String(), u, nil
|
||||
}
|
||||
return "", u, nil
|
||||
}
|
||||
|
||||
// AbsoluteURL converts the input URL as absolute URL if necessary.
|
||||
func AbsoluteURL(baseURL, input string) (string, error) {
|
||||
absURL, u, err := GetAbsoluteURL(input)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if absURL != "" {
|
||||
return absURL, nil
|
||||
}
|
||||
|
||||
base, err := url.Parse(baseURL)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue