1
0
Fork 0
mirror of https://github.com/miniflux/v2.git synced 2025-06-27 16:36:00 +00:00

perf(media): minor regex simplification

The previous regex was using the [ABC..D]*[ABC] pattern, resulting in a lot of
backtracking. The new regex is stopping the matching at the first space or end
of text (and removes the trailing `.` should one be present).

The backtracking was taking around 50% of the CPU time spent in atom.Parse
This commit is contained in:
jvoisin 2025-06-17 16:19:12 +02:00 committed by Frédéric Guillot
parent da4ab4263c
commit 8660f5e3c7

View file

@ -9,7 +9,7 @@ import (
"strings"
)
var textLinkRegex = regexp.MustCompile(`(?mi)(\bhttps?:\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])`)
var textLinkRegex = regexp.MustCompile(`(?mi)(\bhttps?://[^\s]+)[.]?(?:\s|$)`)
// Specs: https://www.rssboard.org/media-rss
type MediaItemElement struct {