mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-18 02:40:45 +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 {
|
for _, env := range cfg.Account.Passwords {
|
||||||
if trimmed := strings.TrimSpace(env); trimmed != "" {
|
if trimmed := strings.TrimSpace(env); trimmed != "" {
|
||||||
value := os.Getenv(trimmed)
|
value := os.Getenv(trimmed)
|
||||||
for _, info := range strings.Split(value, ",") {
|
for info := range strings.SplitSeq(value, ",") {
|
||||||
if trimmed2 := strings.TrimSpace(info); trimmed2 != "" {
|
if trimmed2 := strings.TrimSpace(info); trimmed2 != "" {
|
||||||
passwords = append(passwords, trimmed2)
|
passwords = append(passwords, trimmed2)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1824,7 +1824,7 @@ func MakeConsolePreloads(ctx *cli.Context) []string {
|
||||||
preloads := []string{}
|
preloads := []string{}
|
||||||
|
|
||||||
assets := ctx.String(JSpathFlag.Name)
|
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)))
|
preloads = append(preloads, common.AbsolutePath(assets, strings.TrimSpace(file)))
|
||||||
}
|
}
|
||||||
return preloads
|
return preloads
|
||||||
|
|
|
||||||
|
|
@ -131,7 +131,7 @@ func New(stack *node.Node, config *ethconfig.Config, XDCXServ *XDCx.XDCX, lendin
|
||||||
common.CopyConstants(networkID)
|
common.CopyConstants(networkID)
|
||||||
|
|
||||||
log.Info(strings.Repeat("-", 153))
|
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(line)
|
||||||
}
|
}
|
||||||
log.Info(strings.Repeat("-", 153))
|
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"
|
// sets V to 3 in all files of any packages whose import path contains "foo"
|
||||||
func (h *GlogHandler) Vmodule(ruleset string) error {
|
func (h *GlogHandler) Vmodule(ruleset string) error {
|
||||||
var filter []pattern
|
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
|
// Empty strings such as from a trailing comma can be ignored
|
||||||
if len(rule) == 0 {
|
if len(rule) == 0 {
|
||||||
continue
|
continue
|
||||||
|
|
@ -113,7 +113,7 @@ func (h *GlogHandler) Vmodule(ruleset string) error {
|
||||||
}
|
}
|
||||||
// Compile the rule pattern into a regular expression
|
// Compile the rule pattern into a regular expression
|
||||||
matcher := ".*"
|
matcher := ".*"
|
||||||
for _, comp := range strings.Split(parts[0], "/") {
|
for comp := range strings.SplitSeq(parts[0], "/") {
|
||||||
if comp == "*" {
|
if comp == "*" {
|
||||||
matcher += "(/.*)?"
|
matcher += "(/.*)?"
|
||||||
} else if comp != "" {
|
} 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 {
|
if cors != nil {
|
||||||
config.CorsAllowedOrigins = nil
|
config.CorsAllowedOrigins = nil
|
||||||
for _, origin := range strings.Split(*cors, ",") {
|
for origin := range strings.SplitSeq(*cors, ",") {
|
||||||
config.CorsAllowedOrigins = append(config.CorsAllowedOrigins, strings.TrimSpace(origin))
|
config.CorsAllowedOrigins = append(config.CorsAllowedOrigins, strings.TrimSpace(origin))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if vhosts != nil {
|
if vhosts != nil {
|
||||||
config.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))
|
config.Vhosts = append(config.Vhosts, strings.TrimSpace(vhost))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if apis != nil {
|
if apis != nil {
|
||||||
config.Modules = nil
|
config.Modules = nil
|
||||||
for _, m := range strings.Split(*apis, ",") {
|
for m := range strings.SplitSeq(*apis, ",") {
|
||||||
config.Modules = append(config.Modules, strings.TrimSpace(m))
|
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 {
|
if apis != nil {
|
||||||
config.Modules = nil
|
config.Modules = nil
|
||||||
for _, m := range strings.Split(*apis, ",") {
|
for m := range strings.SplitSeq(*apis, ",") {
|
||||||
config.Modules = append(config.Modules, strings.TrimSpace(m))
|
config.Modules = append(config.Modules, strings.TrimSpace(m))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if allowedOrigins != nil {
|
if allowedOrigins != nil {
|
||||||
config.Origins = nil
|
config.Origins = nil
|
||||||
for _, origin := range strings.Split(*allowedOrigins, ",") {
|
for origin := range strings.SplitSeq(*allowedOrigins, ",") {
|
||||||
config.Origins = append(config.Origins, strings.TrimSpace(origin))
|
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.
|
// A message code of '*' or '-1' is considered a wildcard and matches any code.
|
||||||
func NewMsgFilters(filterParam string) (MsgFilters, error) {
|
func NewMsgFilters(filterParam string) (MsgFilters, error) {
|
||||||
filters := make(MsgFilters)
|
filters := make(MsgFilters)
|
||||||
for _, filter := range strings.Split(filterParam, "-") {
|
for filter := range strings.SplitSeq(filterParam, "-") {
|
||||||
proto, codes, found := strings.Cut(filter, ":")
|
proto, codes, found := strings.Cut(filter, ":")
|
||||||
if !found || proto == "" || codes == "" {
|
if !found || proto == "" || codes == "" {
|
||||||
return nil, fmt.Errorf("invalid message filter: %s", filter)
|
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" {
|
if code == "*" || code == "-1" {
|
||||||
filters[MsgFilter{Proto: proto, Code: -1}] = struct{}{}
|
filters[MsgFilter{Proto: proto, Code: -1}] = struct{}{}
|
||||||
continue
|
continue
|
||||||
|
|
|
||||||
|
|
@ -148,7 +148,7 @@ func parseTag(field Field, lastPublic int) (Tags, error) {
|
||||||
name := field.Name
|
name := field.Name
|
||||||
tag := reflect.StructTag(field.Tag)
|
tag := reflect.StructTag(field.Tag)
|
||||||
var ts Tags
|
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 {
|
switch t = strings.TrimSpace(t); t {
|
||||||
case "":
|
case "":
|
||||||
// empty tag is allowed for some reason
|
// empty tag is allowed for some reason
|
||||||
|
|
|
||||||
|
|
@ -92,7 +92,7 @@ func runTestScript(t *testing.T, file string) {
|
||||||
defer clientConn.Close()
|
defer clientConn.Close()
|
||||||
go server.ServeCodec(NewCodec(serverConn), 0)
|
go server.ServeCodec(NewCodec(serverConn), 0)
|
||||||
readbuf := bufio.NewReader(clientConn)
|
readbuf := bufio.NewReader(clientConn)
|
||||||
for _, line := range strings.Split(string(content), "\n") {
|
for line := range strings.SplitSeq(string(content), "\n") {
|
||||||
line = strings.TrimSpace(line)
|
line = strings.TrimSpace(line)
|
||||||
switch {
|
switch {
|
||||||
case len(line) == 0 || strings.HasPrefix(line, "//"):
|
case len(line) == 0 || strings.HasPrefix(line, "//"):
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue