Skip to content

refactor: replace Split in loops with more efficient SplitSeq #79

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions cmd/website/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,8 @@ func getFoldersFromS3(dir string) ([]string, error) {
}

// Print the output
lines := strings.Split(string(stdout), "\n")
for _, line := range lines {
lines := strings.SplitSeq(string(stdout), "\n")
for line := range lines {
if line != "" && strings.HasPrefix(line, "20") {
folders = append(folders, strings.TrimSuffix(line, "/"))
}
Expand All @@ -250,8 +250,8 @@ func getFilesFromS3(month string) ([]website.FileEntry, error) {
}

space := regexp.MustCompile(`\s+`)
lines := strings.Split(string(stdout), "\n")
for _, line := range lines {
lines := strings.SplitSeq(string(stdout), "\n")
for line := range lines {
if line != "" {
line = space.ReplaceAllString(line, " ")
parts := strings.Split(line, " ")
Expand Down
4 changes: 2 additions & 2 deletions common/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ func SourceAliasesFromEnv() map[string]string {
aliases := make(map[string]string)
aliasesRaw := os.Getenv("SRC_ALIASES") // format: alias=url,alias=url
if aliasesRaw != "" {
entries := strings.Split(aliasesRaw, ",")
for _, entry := range entries {
entries := strings.SplitSeq(aliasesRaw, ",")
for entry := range entries {
parts := strings.Split(entry, "=")
if len(parts) != 2 {
continue
Expand Down