Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some slice append usages (#26778) #26798

Merged
merged 1 commit into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion modules/setting/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ func loadServiceFrom(rootCfg ConfigProvider) {
Service.UserDeleteWithCommentsMaxTime = sec.Key("USER_DELETE_WITH_COMMENTS_MAX_TIME").MustDuration(0)
sec.Key("VALID_SITE_URL_SCHEMES").MustString("http,https")
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 {
scheme = strings.ToLower(strings.TrimSpace(scheme))
if scheme != "" {
Expand Down
16 changes: 7 additions & 9 deletions routers/api/v1/repo/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,11 +326,9 @@ func CreatePullRequest(ctx *context.APIContext) {
return
}

labelIDs = make([]int64, len(form.Labels))
orgLabelIDs := make([]int64, len(form.Labels))

for i := range labels {
labelIDs[i] = labels[i].ID
labelIDs = make([]int64, 0, len(labels))
for _, label := range labels {
labelIDs = append(labelIDs, label.ID)
}

if ctx.Repo.Owner.IsOrganization() {
Expand All @@ -340,12 +338,12 @@ func CreatePullRequest(ctx *context.APIContext) {
return
}

for i := range orgLabels {
orgLabelIDs[i] = orgLabels[i].ID
orgLabelIDs := make([]int64, 0, len(orgLabels))
for _, orgLabel := range orgLabels {
orgLabelIDs = append(orgLabelIDs, orgLabel.ID)
}
labelIDs = append(labelIDs, orgLabelIDs...)
}

labelIDs = append(labelIDs, orgLabelIDs...)
}

if form.Milestone > 0 {
Expand Down
6 changes: 3 additions & 3 deletions services/repository/files/temp_repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,12 @@ func (t *TemporaryUploadRepository) LsFiles(filenames ...string) ([]string, erro
return nil, err
}

filelist := make([]string, len(filenames))
fileList := make([]string, 0, len(filenames))
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
Expand Down