mirror of
https://github.com/miniflux/v2.git
synced 2025-08-11 17:51:01 +00:00
refactor(parser): centralize seek logic and provide a hint for the compiler to eliminate a useless bound check
- Move the seeking inside of DetectFeedFormat instead of having it everywhere in ParseFeed - Provide a hint for the compiler to eliminate a useless bound check in DetectJSONFormat, otherwise it'll check that buffer[i] is valid on every iteration of the loop. This shouldn't make a big difference, but oh well.
This commit is contained in:
parent
3bb965913d
commit
a43d150a27
2 changed files with 7 additions and 5 deletions
|
@ -18,20 +18,15 @@ var ErrFeedFormatNotDetected = errors.New("parser: unable to detect feed format"
|
|||
|
||||
// ParseFeed analyzes the input data and returns a normalized feed object.
|
||||
func ParseFeed(baseURL string, r io.ReadSeeker) (*model.Feed, error) {
|
||||
r.Seek(0, io.SeekStart)
|
||||
format, version := DetectFeedFormat(r)
|
||||
switch format {
|
||||
case FormatAtom:
|
||||
r.Seek(0, io.SeekStart)
|
||||
return atom.Parse(baseURL, r, version)
|
||||
case FormatRSS:
|
||||
r.Seek(0, io.SeekStart)
|
||||
return rss.Parse(baseURL, r)
|
||||
case FormatJSON:
|
||||
r.Seek(0, io.SeekStart)
|
||||
return json.Parse(baseURL, r)
|
||||
case FormatRDF:
|
||||
r.Seek(0, io.SeekStart)
|
||||
return rdf.Parse(baseURL, r)
|
||||
default:
|
||||
return nil, ErrFeedFormatNotDetected
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue