From 1d6163e363b6c963ee2f39431168a9c2c6817b31 Mon Sep 17 00:00:00 2001 From: fengyuchuanshen Date: Tue, 4 Nov 2025 23:08:33 +0800 Subject: [PATCH] refactor: replace Split in loops with more efficient SplitSeq Signed-off-by: fengyuchuanshen --- cmd/alert/main.go | 4 ++-- cmd/priv-dashboard/main.go | 4 ++-- ethstorage/flags/types/flags_types.go | 4 ++-- ethstorage/p2p/cli/load_config.go | 2 +- ethstorage/p2p/peer_scorer.go | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/cmd/alert/main.go b/cmd/alert/main.go index 0b5b42ed..35122678 100644 --- a/cmd/alert/main.go +++ b/cmd/alert/main.go @@ -115,9 +115,9 @@ func writeHtmlFile(content string, lg log.Logger) { } func addToEmailList(emailList map[string]struct{}, emailToString string) { - emails := strings.Split(emailToString, ",") + emails := strings.SplitSeq(emailToString, ",") - for _, email := range emails { + for email := range emails { emailList[email] = struct{}{} } } diff --git a/cmd/priv-dashboard/main.go b/cmd/priv-dashboard/main.go index 7e4aee23..f4954910 100644 --- a/cmd/priv-dashboard/main.go +++ b/cmd/priv-dashboard/main.go @@ -219,8 +219,8 @@ func (d *dashboard) Report() { if *emailEnableFlag && time.Now().After(d.lastNotification.Add(emailReportInterval)) { contracts := make(map[string]struct{}) - cs := strings.Split(*emailContractsFlag, ",") - for _, c := range cs { + cs := strings.SplitSeq(*emailContractsFlag, ",") + for c := range cs { c = strings.TrimSpace(c) if c == "" { // ignore empty records continue diff --git a/ethstorage/flags/types/flags_types.go b/ethstorage/flags/types/flags_types.go index 63aee1f5..2263542b 100644 --- a/ethstorage/flags/types/flags_types.go +++ b/ethstorage/flags/types/flags_types.go @@ -110,8 +110,8 @@ func (b *bigValue) Set(s string) error { } func eachName(f cli.Flag, fn func(string)) { - parts := strings.Split(f.GetName(), ",") - for _, name := range parts { + parts := strings.SplitSeq(f.GetName(), ",") + for name := range parts { name = strings.Trim(name, " ") fn(name) } diff --git a/ethstorage/p2p/cli/load_config.go b/ethstorage/p2p/cli/load_config.go index 99f1753b..d0443eeb 100644 --- a/ethstorage/p2p/cli/load_config.go +++ b/ethstorage/p2p/cli/load_config.go @@ -240,7 +240,7 @@ func loadLibp2pOpts(conf *p2p.Config, ctx *cli.Context) error { conf.StaticPeers = append(conf.StaticPeers, a) } - for _, v := range strings.Split(ctx.GlobalString(flags.HostMux.Name), ",") { + for v := range strings.SplitSeq(ctx.GlobalString(flags.HostMux.Name), ",") { v = strings.ToLower(strings.TrimSpace(v)) switch v { case "yamux": diff --git a/ethstorage/p2p/peer_scorer.go b/ethstorage/p2p/peer_scorer.go index c0cdbf64..9c787d1d 100644 --- a/ethstorage/p2p/peer_scorer.go +++ b/ethstorage/p2p/peer_scorer.go @@ -37,7 +37,7 @@ func NewBandScorer(str string) (*BandScoreThresholds, error) { bands: make([]scorePair, 0), } - for _, band := range strings.Split(str, ";") { + for band := range strings.SplitSeq(str, ";") { // Skip empty band strings. band := strings.TrimSpace(band) if band == "" {