Fix some slice append usages (#26778) (#26798)

Backport #26778 by @harryzcy

Co-authored-by: Chongyi Zheng <git@zcy.dev>
Co-authored-by: delvh <dev.lh@web.de>
(cherry picked from commit 4013f3f600)
This commit is contained in:
Giteabot 2023-08-30 00:13:24 +08:00 committed by Earl Warren
parent 1d228e6ee9
commit 4d2b4008d3
No known key found for this signature in database
GPG key ID: 0579CB2928A78A00
3 changed files with 11 additions and 13 deletions

View file

@ -221,7 +221,7 @@ func loadServiceFrom(rootCfg ConfigProvider) {
Service.UserDeleteWithCommentsMaxTime = sec.Key("USER_DELETE_WITH_COMMENTS_MAX_TIME").MustDuration(0) Service.UserDeleteWithCommentsMaxTime = sec.Key("USER_DELETE_WITH_COMMENTS_MAX_TIME").MustDuration(0)
sec.Key("VALID_SITE_URL_SCHEMES").MustString("http,https") sec.Key("VALID_SITE_URL_SCHEMES").MustString("http,https")
Service.ValidSiteURLSchemes = sec.Key("VALID_SITE_URL_SCHEMES").Strings(",") Service.ValidSiteURLSchemes = sec.Key("VALID_SITE_URL_SCHEMES").Strings(",")
schemes := make([]string, len(Service.ValidSiteURLSchemes)) schemes := make([]string, 0, len(Service.ValidSiteURLSchemes))
for _, scheme := range Service.ValidSiteURLSchemes { for _, scheme := range Service.ValidSiteURLSchemes {
scheme = strings.ToLower(strings.TrimSpace(scheme)) scheme = strings.ToLower(strings.TrimSpace(scheme))
if scheme != "" { if scheme != "" {

View file

@ -326,11 +326,9 @@ func CreatePullRequest(ctx *context.APIContext) {
return return
} }
labelIDs = make([]int64, len(form.Labels)) labelIDs = make([]int64, 0, len(labels))
orgLabelIDs := make([]int64, len(form.Labels)) for _, label := range labels {
labelIDs = append(labelIDs, label.ID)
for i := range labels {
labelIDs[i] = labels[i].ID
} }
if ctx.Repo.Owner.IsOrganization() { if ctx.Repo.Owner.IsOrganization() {
@ -340,13 +338,13 @@ func CreatePullRequest(ctx *context.APIContext) {
return return
} }
for i := range orgLabels { orgLabelIDs := make([]int64, 0, len(orgLabels))
orgLabelIDs[i] = orgLabels[i].ID for _, orgLabel := range orgLabels {
orgLabelIDs = append(orgLabelIDs, orgLabel.ID)
} }
}
labelIDs = append(labelIDs, orgLabelIDs...) labelIDs = append(labelIDs, orgLabelIDs...)
} }
}
if form.Milestone > 0 { if form.Milestone > 0 {
milestone, err := issues_model.GetMilestoneByRepoID(ctx, ctx.Repo.Repository.ID, form.Milestone) milestone, err := issues_model.GetMilestoneByRepoID(ctx, ctx.Repo.Repository.ID, form.Milestone)

View file

@ -114,12 +114,12 @@ func (t *TemporaryUploadRepository) LsFiles(filenames ...string) ([]string, erro
return nil, err return nil, err
} }
filelist := make([]string, len(filenames)) fileList := make([]string, 0, len(filenames))
for _, line := range bytes.Split(stdOut.Bytes(), []byte{'\000'}) { for _, line := range bytes.Split(stdOut.Bytes(), []byte{'\000'}) {
filelist = append(filelist, string(line)) fileList = append(fileList, string(line))
} }
return filelist, nil return fileList, nil
} }
// RemoveFilesFromIndex removes the given files from the index // RemoveFilesFromIndex removes the given files from the index