Skip to content

Commit ec93656

Browse files
committed
perf: preallocate slices
1 parent 317aaee commit ec93656

File tree

8 files changed

+13
-12
lines changed

8 files changed

+13
-12
lines changed

.golangci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ linters:
1010
- loggercheck
1111
- misspell
1212
- perfsprint
13+
- prealloc
1314
- sqlclosecheck
1415
- staticcheck
1516
- whitespace

internal/googlereader/request_modifier.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,19 @@ func (r RequestModifiers) String() string {
2929

3030
results = append(results, fmt.Sprintf("UserID: %d", r.UserID))
3131

32-
var streamStr []string
32+
streamStr := make([]string, 0, len(r.Streams))
3333
for _, s := range r.Streams {
3434
streamStr = append(streamStr, s.String())
3535
}
3636
results = append(results, fmt.Sprintf("Streams: [%s]", strings.Join(streamStr, ", ")))
3737

38-
var exclusions []string
38+
exclusions := make([]string, 0, len(r.ExcludeTargets))
3939
for _, s := range r.ExcludeTargets {
4040
exclusions = append(exclusions, s.String())
4141
}
4242
results = append(results, fmt.Sprintf("Exclusions: [%s]", strings.Join(exclusions, ", ")))
4343

44-
var filters []string
44+
filters := make([]string, 0, len(r.FilterTargets))
4545
for _, s := range r.FilterTargets {
4646
filters = append(filters, s.String())
4747
}

internal/integration/matrixbot/matrixbot.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ func PushEntries(feed *model.Feed, entries model.Entries, matrixBaseURL, matrixU
2323
return err
2424
}
2525

26-
var textMessages []string
27-
var formattedTextMessages []string
26+
textMessages := make([]string, 0, len(entries))
27+
formattedTextMessages := make([]string, 0, len(entries))
2828

2929
for _, entry := range entries {
3030
textMessages = append(textMessages, fmt.Sprintf(`[%s] %s - %s`, feed.Title, entry.Title, entry.URL))

internal/integration/webhook/webhook.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func (c *Client) SendNewEntriesWebhookEvent(feed *model.Feed, entries model.Entr
7373
return nil
7474
}
7575

76-
var webhookEntries []*WebhookEntry
76+
webhookEntries := make([]*WebhookEntry, 0, len(entries))
7777
for _, entry := range entries {
7878
webhookEntries = append(webhookEntries, &WebhookEntry{
7979
ID: entry.ID,

internal/reader/itunes/itunes.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ type ItunesChannelElement struct {
2323
}
2424

2525
func (i *ItunesChannelElement) GetItunesCategories() []string {
26-
var categories []string
26+
categories := make([]string, 0, len(i.ItunesCategories))
2727
for _, category := range i.ItunesCategories {
2828
categories = append(categories, category.Text)
2929
if category.SubCategory != nil {

internal/reader/processor/youtube.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ func fetchYouTubeWatchTimeForSingleEntry(websiteURL string) (int, error) {
4343
}
4444

4545
func fetchYouTubeWatchTimeInBulk(entries []*model.Entry) {
46-
var videosEntriesMapping = make(map[string]*model.Entry, len(entries))
47-
var videoIDs []string
46+
videosEntriesMapping := make(map[string]*model.Entry, len(entries))
47+
videoIDs := make([]string, 0, len(entries))
4848

4949
for _, entry := range entries {
5050
if !isYouTubeVideoURL(entry.URL) {

internal/reader/readability/readability.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,10 @@ func (c *candidate) String() string {
6262
type candidateList map[*html.Node]*candidate
6363

6464
func (c candidateList) String() string {
65-
var output []string
65+
output := make([]string, 0, len(c))
6666
for _, candidate := range c {
6767
output = append(output, candidate.String())
6868
}
69-
7069
return strings.Join(output, ", ")
7170
}
7271

internal/reader/sanitizer/sanitizer.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,8 @@ func SanitizeHTML(baseURL, rawHTML string, sanitizerOptions *SanitizerOptions) s
305305
}
306306

307307
func sanitizeAttributes(parsedBaseUrl *url.URL, tagName string, attributes []html.Attribute, sanitizerOptions *SanitizerOptions) ([]string, string) {
308-
var htmlAttrs, attrNames []string
308+
htmlAttrs := make([]string, 0, len(attributes))
309+
attrNames := make([]string, 0, len(attributes))
309310
var err error
310311
var isAnchorLink bool
311312

0 commit comments

Comments
 (0)