From 0677ba3177e3d7c506febee7a40523a645d66d94 Mon Sep 17 00:00:00 2001 From: catatsuy Date: Sun, 8 Sep 2024 14:29:11 +0900 Subject: [PATCH] Refactor image and post link extraction to use iter --- benchmarker/Makefile | 2 +- benchmarker/scenario.go | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/benchmarker/Makefile b/benchmarker/Makefile index 5f85d9dfd..0ac39b7de 100644 --- a/benchmarker/Makefile +++ b/benchmarker/Makefile @@ -1,4 +1,4 @@ all: bin/benchmarker -bin/benchmarker: *.go checker/*.go +bin/benchmarker: *.go checker/*.go go.mod go.sum go build -o bin/benchmarker diff --git a/benchmarker/scenario.go b/benchmarker/scenario.go index 871ac7871..7a65bee33 100644 --- a/benchmarker/scenario.go +++ b/benchmarker/scenario.go @@ -34,25 +34,25 @@ func loadImages(s *checker.Session, imageURLs []string) { } func extractImages(doc *goquery.Document) []string { - imageURLs := []string{} + imageURLs := make([]string, 0, PostsPerPage) - doc.Find("img.isu-image").Each(func(_ int, selection *goquery.Selection) { - if url, ok := selection.Attr("src"); ok { + for _, el := range doc.Find("img.isu-image").EachIter() { + if url, ok := el.Attr("src"); ok { imageURLs = append(imageURLs, url) } - }).Length() + } return imageURLs } func extractPostLinks(doc *goquery.Document) []string { - postLinks := []string{} + postLinks := make([]string, 0, PostsPerPage) - doc.Find("a.isu-post-permalink").Each(func(_ int, selection *goquery.Selection) { - if url, ok := selection.Attr("href"); ok { + for _, el := range doc.Find("a.isu-post-permalink").EachIter() { + if url, ok := el.Attr("href"); ok { postLinks = append(postLinks, url) } - }).Length() + } return postLinks }