1
0
Fork 0
mirror of https://github.com/miniflux/v2.git synced 2025-08-26 18:21: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:
Julien Voisin 2025-08-03 21:53:10 +02:00 committed by GitHub
parent 3bb965913d
commit a43d150a27
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 7 additions and 5 deletions

View file

@ -22,6 +22,9 @@ const (
// DetectFeedFormat tries to guess the feed format from input data.
func DetectFeedFormat(r io.ReadSeeker) (string, string) {
r.Seek(0, io.SeekStart)
defer r.Seek(0, io.SeekStart)
if isJSON, err := detectJSONFormat(r); err == nil && isJSON {
return FormatJSON, ""
}
@ -70,6 +73,10 @@ func detectJSONFormat(r io.ReadSeeker) (bool, error) {
return false, err
}
if len(buffer) < n {
panic("unreachable") // bounds check hint to compiler
}
// Check each byte in the buffer
for i := range n {
ch := buffer[i]