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:
parent
8bca777a6d
commit
93fc206f42
6 changed files with 42 additions and 43 deletions
|
@ -9,7 +9,7 @@ import (
|
|||
)
|
||||
|
||||
// equals compare two subscriptions.
|
||||
func (s subcription) equals(subscription *subcription) bool {
|
||||
func (s subcription) equals(subscription subcription) bool {
|
||||
return s.Title == subscription.Title && s.SiteURL == subscription.SiteURL &&
|
||||
s.FeedURL == subscription.FeedURL && s.CategoryName == subscription.CategoryName &&
|
||||
s.Description == subscription.Description
|
||||
|
@ -39,8 +39,8 @@ func TestParseOpmlWithoutCategories(t *testing.T) {
|
|||
</opml>
|
||||
`
|
||||
|
||||
var expected subcriptionList
|
||||
expected = append(expected, &subcription{Title: "CNET News.com", FeedURL: "http://news.com.com/2547-1_3-0-5.xml", SiteURL: "http://news.com.com/", Description: "Tech news and business reports by CNET News.com. Focused on information technology, core topics include computers, hardware, software, networking, and Internet media."})
|
||||
var expected []subcription
|
||||
expected = append(expected, subcription{Title: "CNET News.com", FeedURL: "http://news.com.com/2547-1_3-0-5.xml", SiteURL: "http://news.com.com/", Description: "Tech news and business reports by CNET News.com. Focused on information technology, core topics include computers, hardware, software, networking, and Internet media."})
|
||||
|
||||
subscriptions, err := parse(bytes.NewBufferString(data))
|
||||
if err != nil {
|
||||
|
@ -74,10 +74,10 @@ func TestParseOpmlWithCategories(t *testing.T) {
|
|||
</opml>
|
||||
`
|
||||
|
||||
var expected subcriptionList
|
||||
expected = append(expected, &subcription{Title: "Feed 1", FeedURL: "http://example.org/feed1/", SiteURL: "http://example.org/1", CategoryName: "My Category 1"})
|
||||
expected = append(expected, &subcription{Title: "Feed 2", FeedURL: "http://example.org/feed2/", SiteURL: "http://example.org/2", CategoryName: "My Category 1"})
|
||||
expected = append(expected, &subcription{Title: "Feed 3", FeedURL: "http://example.org/feed3/", SiteURL: "http://example.org/3", CategoryName: "My Category 2"})
|
||||
var expected []subcription
|
||||
expected = append(expected, subcription{Title: "Feed 1", FeedURL: "http://example.org/feed1/", SiteURL: "http://example.org/1", CategoryName: "My Category 1"})
|
||||
expected = append(expected, subcription{Title: "Feed 2", FeedURL: "http://example.org/feed2/", SiteURL: "http://example.org/2", CategoryName: "My Category 1"})
|
||||
expected = append(expected, subcription{Title: "Feed 3", FeedURL: "http://example.org/feed3/", SiteURL: "http://example.org/3", CategoryName: "My Category 2"})
|
||||
|
||||
subscriptions, err := parse(bytes.NewBufferString(data))
|
||||
if err != nil {
|
||||
|
@ -108,9 +108,9 @@ func TestParseOpmlWithEmptyTitleAndEmptySiteURL(t *testing.T) {
|
|||
</opml>
|
||||
`
|
||||
|
||||
var expected subcriptionList
|
||||
expected = append(expected, &subcription{Title: "http://example.org/1", FeedURL: "http://example.org/feed1/", SiteURL: "http://example.org/1", CategoryName: ""})
|
||||
expected = append(expected, &subcription{Title: "http://example.org/feed2/", FeedURL: "http://example.org/feed2/", SiteURL: "http://example.org/feed2/", CategoryName: ""})
|
||||
var expected []subcription
|
||||
expected = append(expected, subcription{Title: "http://example.org/1", FeedURL: "http://example.org/feed1/", SiteURL: "http://example.org/1", CategoryName: ""})
|
||||
expected = append(expected, subcription{Title: "http://example.org/feed2/", FeedURL: "http://example.org/feed2/", SiteURL: "http://example.org/feed2/", CategoryName: ""})
|
||||
|
||||
subscriptions, err := parse(bytes.NewBufferString(data))
|
||||
if err != nil {
|
||||
|
@ -146,9 +146,9 @@ func TestParseOpmlVersion1(t *testing.T) {
|
|||
</opml>
|
||||
`
|
||||
|
||||
var expected subcriptionList
|
||||
expected = append(expected, &subcription{Title: "Feed 1", FeedURL: "http://example.org/feed1/", SiteURL: "http://example.org/1", CategoryName: "Category 1"})
|
||||
expected = append(expected, &subcription{Title: "Feed 2", FeedURL: "http://example.org/feed2/", SiteURL: "http://example.org/2", CategoryName: "Category 2"})
|
||||
var expected []subcription
|
||||
expected = append(expected, subcription{Title: "Feed 1", FeedURL: "http://example.org/feed1/", SiteURL: "http://example.org/1", CategoryName: "Category 1"})
|
||||
expected = append(expected, subcription{Title: "Feed 2", FeedURL: "http://example.org/feed2/", SiteURL: "http://example.org/2", CategoryName: "Category 2"})
|
||||
|
||||
subscriptions, err := parse(bytes.NewBufferString(data))
|
||||
if err != nil {
|
||||
|
@ -180,9 +180,9 @@ func TestParseOpmlVersion1WithoutOuterOutline(t *testing.T) {
|
|||
</opml>
|
||||
`
|
||||
|
||||
var expected subcriptionList
|
||||
expected = append(expected, &subcription{Title: "Feed 1", FeedURL: "http://example.org/feed1/", SiteURL: "http://example.org/1", CategoryName: ""})
|
||||
expected = append(expected, &subcription{Title: "Feed 2", FeedURL: "http://example.org/feed2/", SiteURL: "http://example.org/2", CategoryName: ""})
|
||||
var expected []subcription
|
||||
expected = append(expected, subcription{Title: "Feed 1", FeedURL: "http://example.org/feed1/", SiteURL: "http://example.org/1", CategoryName: ""})
|
||||
expected = append(expected, subcription{Title: "Feed 2", FeedURL: "http://example.org/feed2/", SiteURL: "http://example.org/2", CategoryName: ""})
|
||||
|
||||
subscriptions, err := parse(bytes.NewBufferString(data))
|
||||
if err != nil {
|
||||
|
@ -221,10 +221,10 @@ func TestParseOpmlVersion1WithSeveralNestedOutlines(t *testing.T) {
|
|||
</opml>
|
||||
`
|
||||
|
||||
var expected subcriptionList
|
||||
expected = append(expected, &subcription{Title: "Feed 1", FeedURL: "http://example.org/feed1/", SiteURL: "http://example.org/1", CategoryName: "Some Category"})
|
||||
expected = append(expected, &subcription{Title: "Feed 2", FeedURL: "http://example.org/feed2/", SiteURL: "http://example.org/2", CategoryName: "Some Category"})
|
||||
expected = append(expected, &subcription{Title: "Feed 3", FeedURL: "http://example.org/feed3/", SiteURL: "http://example.org/3", CategoryName: "Another Category"})
|
||||
var expected []subcription
|
||||
expected = append(expected, subcription{Title: "Feed 1", FeedURL: "http://example.org/feed1/", SiteURL: "http://example.org/1", CategoryName: "Some Category"})
|
||||
expected = append(expected, subcription{Title: "Feed 2", FeedURL: "http://example.org/feed2/", SiteURL: "http://example.org/2", CategoryName: "Some Category"})
|
||||
expected = append(expected, subcription{Title: "Feed 3", FeedURL: "http://example.org/feed3/", SiteURL: "http://example.org/3", CategoryName: "Another Category"})
|
||||
|
||||
subscriptions, err := parse(bytes.NewBufferString(data))
|
||||
if err != nil {
|
||||
|
@ -256,8 +256,8 @@ func TestParseOpmlWithInvalidCharacterEntity(t *testing.T) {
|
|||
</opml>
|
||||
`
|
||||
|
||||
var expected subcriptionList
|
||||
expected = append(expected, &subcription{Title: "Feed 1", FeedURL: "http://example.org/feed1/a&b", SiteURL: "http://example.org/c&d", CategoryName: "Feed 1"})
|
||||
var expected []subcription
|
||||
expected = append(expected, subcription{Title: "Feed 1", FeedURL: "http://example.org/feed1/a&b", SiteURL: "http://example.org/c&d", CategoryName: "Feed 1"})
|
||||
|
||||
subscriptions, err := parse(bytes.NewBufferString(data))
|
||||
if err != nil {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue