mirror of
https://github.com/rclone/rclone.git
synced 2025-12-06 00:03:32 +00:00
refactor: use strings.Builder to improve performance
This commit is contained in:
@@ -178,7 +178,7 @@ func constructProviders(options fs.Options, providerMap map[string]*Provider) st
|
||||
}
|
||||
}
|
||||
|
||||
var providerList string
|
||||
var providerList strings.Builder
|
||||
|
||||
for _, p := range providers {
|
||||
for i := range options {
|
||||
@@ -189,7 +189,7 @@ func constructProviders(options fs.Options, providerMap map[string]*Provider) st
|
||||
Value: p.Name,
|
||||
Help: p.Description,
|
||||
})
|
||||
providerList += p.Name + ", "
|
||||
providerList.WriteString(p.Name + ", ")
|
||||
case "region":
|
||||
addExample(opt, p, p.Region, defaults.Region)
|
||||
case "endpoint":
|
||||
@@ -232,5 +232,5 @@ func constructProviders(options fs.Options, providerMap map[string]*Provider) st
|
||||
}
|
||||
}
|
||||
|
||||
return strings.TrimSuffix(providerList, ", ")
|
||||
return strings.TrimSuffix(providerList.String(), ", ")
|
||||
}
|
||||
|
||||
@@ -150,13 +150,13 @@ func TestAsyncReaderSizes(t *testing.T) {
|
||||
|
||||
var texts [31]string
|
||||
str := ""
|
||||
all := ""
|
||||
var all strings.Builder
|
||||
for i := range len(texts) - 1 {
|
||||
texts[i] = str + "\n"
|
||||
all += texts[i]
|
||||
all.WriteString(texts[i])
|
||||
str += string(rune(i)%26 + 'a')
|
||||
}
|
||||
texts[len(texts)-1] = all
|
||||
texts[len(texts)-1] = all.String()
|
||||
|
||||
for h := range len(texts) {
|
||||
text := texts[h]
|
||||
@@ -191,13 +191,13 @@ func TestAsyncReaderWriteTo(t *testing.T) {
|
||||
|
||||
var texts [31]string
|
||||
str := ""
|
||||
all := ""
|
||||
var all strings.Builder
|
||||
for i := range len(texts) - 1 {
|
||||
texts[i] = str + "\n"
|
||||
all += texts[i]
|
||||
all.WriteString(texts[i])
|
||||
str += string(rune(i)%26 + 'a')
|
||||
}
|
||||
texts[len(texts)-1] = all
|
||||
texts[len(texts)-1] = all.String()
|
||||
|
||||
for h := range len(texts) {
|
||||
text := texts[h]
|
||||
|
||||
@@ -158,11 +158,11 @@ func (d Duration) readableString(maxNumberOfUnits int) string {
|
||||
return "0s"
|
||||
}
|
||||
|
||||
readableString := ""
|
||||
var readableString strings.Builder
|
||||
|
||||
// Check for minus durations.
|
||||
if d < 0 {
|
||||
readableString += "-"
|
||||
readableString.WriteString("-")
|
||||
}
|
||||
|
||||
duration := time.Duration(math.Abs(float64(d)))
|
||||
@@ -205,14 +205,14 @@ func (d Duration) readableString(maxNumberOfUnits int) string {
|
||||
if v == 0 {
|
||||
continue
|
||||
}
|
||||
readableString += strval + u
|
||||
readableString.WriteString(strval + u)
|
||||
numberOfUnits++
|
||||
if maxNumberOfUnits > 0 && numberOfUnits >= maxNumberOfUnits {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return readableString
|
||||
return readableString.String()
|
||||
}
|
||||
|
||||
// Set a Duration
|
||||
|
||||
Reference in New Issue
Block a user