mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-19 13:21:37 +00:00
all: replace strings.Split with more efficient strings.SplitSeq (#1698)
This commit is contained in:
parent
4d790e6c45
commit
c922f26d0c
8 changed files with 14 additions and 14 deletions
|
|
@ -176,7 +176,7 @@ func loadBaseConfig(ctx *cli.Context) XDCConfig {
|
|||
for _, env := range cfg.Account.Passwords {
|
||||
if trimmed := strings.TrimSpace(env); trimmed != "" {
|
||||
value := os.Getenv(trimmed)
|
||||
for _, info := range strings.Split(value, ",") {
|
||||
for info := range strings.SplitSeq(value, ",") {
|
||||
if trimmed2 := strings.TrimSpace(info); trimmed2 != "" {
|
||||
passwords = append(passwords, trimmed2)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1824,7 +1824,7 @@ func MakeConsolePreloads(ctx *cli.Context) []string {
|
|||
preloads := []string{}
|
||||
|
||||
assets := ctx.String(JSpathFlag.Name)
|
||||
for _, file := range strings.Split(ctx.String(PreloadJSFlag.Name), ",") {
|
||||
for file := range strings.SplitSeq(ctx.String(PreloadJSFlag.Name), ",") {
|
||||
preloads = append(preloads, common.AbsolutePath(assets, strings.TrimSpace(file)))
|
||||
}
|
||||
return preloads
|
||||
|
|
|
|||
|
|
@ -131,7 +131,7 @@ func New(stack *node.Node, config *ethconfig.Config, XDCXServ *XDCx.XDCX, lendin
|
|||
common.CopyConstants(networkID)
|
||||
|
||||
log.Info(strings.Repeat("-", 153))
|
||||
for _, line := range strings.Split(chainConfig.Description(), "\n") {
|
||||
for line := range strings.SplitSeq(chainConfig.Description(), "\n") {
|
||||
log.Info(line)
|
||||
}
|
||||
log.Info(strings.Repeat("-", 153))
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ func (h *GlogHandler) Verbosity(level slog.Level) {
|
|||
// sets V to 3 in all files of any packages whose import path contains "foo"
|
||||
func (h *GlogHandler) Vmodule(ruleset string) error {
|
||||
var filter []pattern
|
||||
for _, rule := range strings.Split(ruleset, ",") {
|
||||
for rule := range strings.SplitSeq(ruleset, ",") {
|
||||
// Empty strings such as from a trailing comma can be ignored
|
||||
if len(rule) == 0 {
|
||||
continue
|
||||
|
|
@ -113,7 +113,7 @@ func (h *GlogHandler) Vmodule(ruleset string) error {
|
|||
}
|
||||
// Compile the rule pattern into a regular expression
|
||||
matcher := ".*"
|
||||
for _, comp := range strings.Split(parts[0], "/") {
|
||||
for comp := range strings.SplitSeq(parts[0], "/") {
|
||||
if comp == "*" {
|
||||
matcher += "(/.*)?"
|
||||
} else if comp != "" {
|
||||
|
|
|
|||
10
node/api.go
10
node/api.go
|
|
@ -205,19 +205,19 @@ func (api *adminAPI) StartHTTP(host *string, port *int, cors *string, apis *stri
|
|||
}
|
||||
if cors != nil {
|
||||
config.CorsAllowedOrigins = nil
|
||||
for _, origin := range strings.Split(*cors, ",") {
|
||||
for origin := range strings.SplitSeq(*cors, ",") {
|
||||
config.CorsAllowedOrigins = append(config.CorsAllowedOrigins, strings.TrimSpace(origin))
|
||||
}
|
||||
}
|
||||
if vhosts != nil {
|
||||
config.Vhosts = nil
|
||||
for _, vhost := range strings.Split(*host, ",") {
|
||||
for vhost := range strings.SplitSeq(*host, ",") {
|
||||
config.Vhosts = append(config.Vhosts, strings.TrimSpace(vhost))
|
||||
}
|
||||
}
|
||||
if apis != nil {
|
||||
config.Modules = nil
|
||||
for _, m := range strings.Split(*apis, ",") {
|
||||
for m := range strings.SplitSeq(*apis, ",") {
|
||||
config.Modules = append(config.Modules, strings.TrimSpace(m))
|
||||
}
|
||||
}
|
||||
|
|
@ -283,13 +283,13 @@ func (api *adminAPI) StartWS(host *string, port *int, allowedOrigins *string, ap
|
|||
|
||||
if apis != nil {
|
||||
config.Modules = nil
|
||||
for _, m := range strings.Split(*apis, ",") {
|
||||
for m := range strings.SplitSeq(*apis, ",") {
|
||||
config.Modules = append(config.Modules, strings.TrimSpace(m))
|
||||
}
|
||||
}
|
||||
if allowedOrigins != nil {
|
||||
config.Origins = nil
|
||||
for _, origin := range strings.Split(*allowedOrigins, ",") {
|
||||
for origin := range strings.SplitSeq(*allowedOrigins, ",") {
|
||||
config.Origins = append(config.Origins, strings.TrimSpace(origin))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -480,13 +480,13 @@ func (s *Server) StreamNetworkEvents(w http.ResponseWriter, req *http.Request) {
|
|||
// A message code of '*' or '-1' is considered a wildcard and matches any code.
|
||||
func NewMsgFilters(filterParam string) (MsgFilters, error) {
|
||||
filters := make(MsgFilters)
|
||||
for _, filter := range strings.Split(filterParam, "-") {
|
||||
for filter := range strings.SplitSeq(filterParam, "-") {
|
||||
proto, codes, found := strings.Cut(filter, ":")
|
||||
if !found || proto == "" || codes == "" {
|
||||
return nil, fmt.Errorf("invalid message filter: %s", filter)
|
||||
}
|
||||
|
||||
for _, code := range strings.Split(codes, ",") {
|
||||
for code := range strings.SplitSeq(codes, ",") {
|
||||
if code == "*" || code == "-1" {
|
||||
filters[MsgFilter{Proto: proto, Code: -1}] = struct{}{}
|
||||
continue
|
||||
|
|
|
|||
|
|
@ -148,7 +148,7 @@ func parseTag(field Field, lastPublic int) (Tags, error) {
|
|||
name := field.Name
|
||||
tag := reflect.StructTag(field.Tag)
|
||||
var ts Tags
|
||||
for _, t := range strings.Split(tag.Get("rlp"), ",") {
|
||||
for t := range strings.SplitSeq(tag.Get("rlp"), ",") {
|
||||
switch t = strings.TrimSpace(t); t {
|
||||
case "":
|
||||
// empty tag is allowed for some reason
|
||||
|
|
|
|||
|
|
@ -92,7 +92,7 @@ func runTestScript(t *testing.T, file string) {
|
|||
defer clientConn.Close()
|
||||
go server.ServeCodec(NewCodec(serverConn), 0)
|
||||
readbuf := bufio.NewReader(clientConn)
|
||||
for _, line := range strings.Split(string(content), "\n") {
|
||||
for line := range strings.SplitSeq(string(content), "\n") {
|
||||
line = strings.TrimSpace(line)
|
||||
switch {
|
||||
case len(line) == 0 || strings.HasPrefix(line, "//"):
|
||||
|
|
|
|||
Loading…
Reference in a new issue