1
0
Fork 0
mirror of https://github.com/miniflux/v2.git synced 2025-08-16 18:01:37 +00:00

refactor(opml): reduce indirections

Don't use a slice of pointers to opml items, when we can simply use a slice of
items instead. This should reduce the amount of memory allocations and the
number of indirections the GC has to process, speedup up the import process.

Note that this doesn't introduce any additional copies, as the only time a
slice of subscription is created, the items are created and inserted inline.
This commit is contained in:
jvoisin 2025-08-11 16:15:44 +02:00 committed by Frédéric Guillot
parent 8bca777a6d
commit 93fc206f42
6 changed files with 42 additions and 43 deletions

View file

@ -11,8 +11,8 @@ import (
"miniflux.app/v2/internal/reader/encoding"
)
// parse reads an OPML file and returns a SubcriptionList.
func parse(data io.Reader) (subcriptionList, error) {
// parse reads an OPML file and returns a list of subscription.
func parse(data io.Reader) ([]subcription, error) {
opmlDocument := &opmlDocument{}
decoder := xml.NewDecoder(data)
decoder.Entity = xml.HTMLEntity
@ -27,10 +27,12 @@ func parse(data io.Reader) (subcriptionList, error) {
return getSubscriptionsFromOutlines(opmlDocument.Outlines, ""), nil
}
func getSubscriptionsFromOutlines(outlines opmlOutlineCollection, category string) (subscriptions subcriptionList) {
func getSubscriptionsFromOutlines(outlines opmlOutlineCollection, category string) []subcription {
subscriptions := make([]subcription, 0, len(outlines))
for _, outline := range outlines {
if outline.IsSubscription() {
subscriptions = append(subscriptions, &subcription{
subscriptions = append(subscriptions, subcription{
Title: outline.GetTitle(),
FeedURL: outline.FeedURL,
SiteURL: outline.GetSiteURL(),