Skip to content

Commit

Permalink
mmcdole#151: Atom parser: Avoid superfluous intermediate variables
Browse files Browse the repository at this point in the history
  • Loading branch information
Necoro committed Mar 5, 2023
1 parent 1e5f390 commit ad2f724
Showing 1 changed file with 4 additions and 24 deletions.
28 changes: 4 additions & 24 deletions atom/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,6 @@ func (ap *Parser) parseEntry(p *xpp.XMLPullParser) (*Entry, error) {
}
entry := &Entry{}

contributors := []*Person{}
authors := []*Person{}
categories := []*Category{}
links := []*Link{}
extensions := ext.Extensions{}

for {
Expand Down Expand Up @@ -276,25 +272,25 @@ func (ap *Parser) parseEntry(p *xpp.XMLPullParser) (*Entry, error) {
if err != nil {
return nil, err
}
contributors = append(contributors, result)
entry.Contributors = append(entry.Contributors, result)
} else if name == "author" {
result, err := ap.parsePerson("author", p)
if err != nil {
return nil, err
}
authors = append(authors, result)
entry.Authors = append(entry.Authors, result)
} else if name == "category" {
result, err := ap.parseCategory(p)
if err != nil {
return nil, err
}
categories = append(categories, result)
entry.Categories = append(entry.Categories, result)
} else if name == "link" {
result, err := ap.parseLink(p)
if err != nil {
return nil, err
}
links = append(links, result)
entry.Links = append(entry.Links, result)
} else if name == "published" ||
name == "issued" {
result, err := ap.parseAtomText(p)
Expand Down Expand Up @@ -322,22 +318,6 @@ func (ap *Parser) parseEntry(p *xpp.XMLPullParser) (*Entry, error) {
}
}

if len(categories) > 0 {
entry.Categories = categories
}

if len(authors) > 0 {
entry.Authors = authors
}

if len(links) > 0 {
entry.Links = links
}

if len(contributors) > 0 {
entry.Contributors = contributors
}

if len(extensions) > 0 {
entry.Extensions = extensions
}
Expand Down

0 comments on commit ad2f724

Please sign in to comment.