Bläddra i källkod

Don't mix up capacity and length

- `make([]a, b)` create a slice of `b` elements `a`
- `make([]a, b, c)` create a slice of `0` elements `a`, but reserve space for `c` of them

When using `append` on the former, it will result on a slice with `b` leading
elements, which is unlikely to be what we want. This commit replaces the two
instances where this happens with the latter construct.
jvoisin 2 år sedan
förälder
incheckning
1f5c8ce353
2 ändrade filer med 2 tillägg och 2 borttagningar
  1. 1 1
      internal/googlereader/handler.go
  2. 1 1
      internal/storage/enclosure.go

+ 1 - 1
internal/googlereader/handler.go

@@ -984,7 +984,7 @@ func (h *handler) streamItemContentsHandler(w http.ResponseWriter, r *http.Reque
 	}
 	contentItems := make([]contentItem, len(entries))
 	for i, entry := range entries {
-		enclosures := make([]contentItemEnclosure, len(entry.Enclosures))
+		enclosures := make([]contentItemEnclosure, 0, len(entry.Enclosures))
 		for _, enclosure := range entry.Enclosures {
 			enclosures = append(enclosures, contentItemEnclosure{URL: enclosure.URL, Type: enclosure.MimeType})
 		}

+ 1 - 1
internal/storage/enclosure.go

@@ -132,7 +132,7 @@ func (s *Storage) updateEnclosures(tx *sql.Tx, entry *model.Entry) error {
 		return nil
 	}
 
-	sqlValues := make([]string, len(entry.Enclosures))
+	sqlValues := make([]string, 0, len(entry.Enclosures))
 	for _, enclosure := range entry.Enclosures {
 		sqlValues = append(sqlValues, strings.TrimSpace(enclosure.URL))