refactor: replace Split in loops with more efficient SplitSeq (#10879)

Signed-off-by: futurehua <futurehua@outlook.com>
This commit is contained in:
futurehua
2026-07-18 04:07:16 +08:00
committed by GitHub
parent 4f592c8734
commit d3ea65a112
6 changed files with 9 additions and 9 deletions

View File

@@ -100,7 +100,7 @@ func kbCitationRawFileURL(collection, entryKey, userID string) string {
}
var escapedEntrySegments []string
for _, segment := range strings.Split(entryKey, "/") {
for segment := range strings.SplitSeq(entryKey, "/") {
if segment == "" {
continue
}

View File

@@ -218,7 +218,7 @@ func (c *Client) decodeTreePage(req *http.Request) ([]snapshotTreeItem, string,
}
func nextPage(link string, current *url.URL) (string, error) {
for _, entry := range strings.Split(link, ",") {
for entry := range strings.SplitSeq(link, ",") {
parts := strings.Split(entry, ";")
if len(parts) >= 2 && strings.TrimSpace(parts[1]) == `rel="next"` {
raw := strings.Trim(strings.TrimSpace(parts[0]), "<>")

View File

@@ -76,8 +76,8 @@ func ValidateRelativeHubPath(candidate string) error {
if candidate == "" || filepath.IsAbs(candidate) || strings.ContainsAny(candidate, "\\\x00") {
return fmt.Errorf("unsafe Hub path %q", candidate)
}
parts := strings.Split(candidate, "/")
for _, part := range parts {
parts := strings.SplitSeq(candidate, "/")
for part := range parts {
if part == "" || part == "." || part == ".." {
return fmt.Errorf("unsafe Hub path %q", candidate)
}

View File

@@ -142,7 +142,7 @@ func validatePattern(pattern string) error {
if pattern == "" || path.IsAbs(pattern) || strings.ContainsAny(pattern, "\\\x00") {
return fmt.Errorf("invalid artifact pattern %q", pattern)
}
for _, part := range strings.Split(pattern, "/") {
for part := range strings.SplitSeq(pattern, "/") {
if part == ".." {
return fmt.Errorf("invalid artifact pattern %q", pattern)
}

View File

@@ -438,7 +438,7 @@ func detectNVIDIAComputeCapability() string {
best := ""
bestMajor, bestMinor := -1, -1
for _, line := range strings.Split(strings.TrimSpace(stdout.String()), "\n") {
for line := range strings.SplitSeq(strings.TrimSpace(stdout.String()), "\n") {
line = strings.TrimSpace(line)
if line == "" {
continue
@@ -500,9 +500,9 @@ func getNVIDIAGPUMemory() []GPUMemoryInfo {
}
var gpus []GPUMemoryInfo
lines := strings.Split(strings.TrimSpace(stdout.String()), "\n")
lines := strings.SplitSeq(strings.TrimSpace(stdout.String()), "\n")
for _, line := range lines {
for line := range lines {
if line == "" {
continue
}

View File

@@ -56,7 +56,7 @@ func parseCgroupV1Limit(raw string) uint64 {
// /proc/meminfo contents. MemTotal is reported in kibibytes, so the parsed
// value is multiplied by 1024. Returns 0 when the field is missing.
func parseMemTotal(raw string) uint64 {
for _, line := range strings.Split(raw, "\n") {
for line := range strings.SplitSeq(raw, "\n") {
if !strings.HasPrefix(line, "MemTotal:") {
continue
}