Perfomance: add preallocation for some slices (#59263)

add preallocation for some slices
This commit is contained in:
Denis Limarev 2022-11-28 18:10:24 +06:00 committed by GitHub
parent 254577ba56
commit b814c66c1d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 9 additions and 9 deletions

View File

@ -156,7 +156,7 @@ func (hs *HTTPServer) UpdateDashboardPermissions(c *models.ReqContext) response.
return dashboardGuardianResponse(err)
}
var items []*models.DashboardACL
items := make([]*models.DashboardACL, 0, len(apiCmd.Items))
for _, item := range apiCmd.Items {
items = append(items, &models.DashboardACL{
OrgID: c.OrgID,

View File

@ -105,7 +105,7 @@ func (hs *HTTPServer) UpdateFolderPermissions(c *models.ReqContext) response.Res
return apierrors.ToFolderErrorResponse(dashboards.ErrFolderAccessDenied)
}
var items []*models.DashboardACL
items := make([]*models.DashboardACL, 0, len(apiCmd.Items))
for _, item := range apiCmd.Items {
items = append(items, &models.DashboardACL{
OrgID: c.OrgID,

View File

@ -306,7 +306,7 @@ var allowedTSVeneers = map[string]bool{
}
func allowedTSVeneersString() string {
var list []string
list := make([]string, 0, len(allowedTSVeneers))
for tgt := range allowedTSVeneers {
list = append(list, tgt)
}

View File

@ -49,7 +49,7 @@ type slotandname struct {
var allslots []slotandname
func init() {
var all []string
all := make([]string, 0, len(PermittedCUEImports()))
for _, im := range PermittedCUEImports() {
all = append(all, fmt.Sprintf("\t%s", im))
}

View File

@ -55,7 +55,7 @@ func (fs *FS) Add(ctx context.Context, pluginID string, pluginArchive *zip.ReadC
fs.log.Successf("Downloaded and extracted %s v%s zip successfully to %s", res.ID, res.Info.Version, pluginDir)
var deps []*Dependency
deps := make([]*Dependency, 0, len(res.Dependencies.Plugins))
for _, plugin := range res.Dependencies.Plugins {
deps = append(deps, &Dependency{
ID: plugin.ID,

View File

@ -124,7 +124,7 @@ func (a allEvaluator) Evaluate(permissions map[string][]string) bool {
}
func (a allEvaluator) MutateScopes(ctx context.Context, mutate ScopeAttributeMutator) (Evaluator, error) {
var modified []Evaluator
modified := make([]Evaluator, 0, len(a.allOf))
for _, e := range a.allOf {
i, err := e.MutateScopes(ctx, mutate)
if err != nil {
@ -174,7 +174,7 @@ func (a anyEvaluator) Evaluate(permissions map[string][]string) bool {
}
func (a anyEvaluator) MutateScopes(ctx context.Context, mutate ScopeAttributeMutator) (Evaluator, error) {
var modified []Evaluator
modified := make([]Evaluator, 0, len(a.anyOf))
for _, e := range a.anyOf {
i, err := e.MutateScopes(ctx, mutate)
if err != nil {

View File

@ -53,7 +53,7 @@ func New(
ac accesscontrol.AccessControl, service accesscontrol.Service, sqlStore db.DB,
teamService team.Service, userService user.Service,
) (*Service, error) {
var permissions []string
permissions := make([]string, 0, len(options.PermissionsToActions))
actionSet := make(map[string]struct{})
for permission, actions := range options.PermissionsToActions {
permissions = append(permissions, permission)

View File

@ -608,7 +608,7 @@ func (s *store) createPermissions(sess *db.Session, roleID int64, resource, reso
if len(actions) == 0 {
return nil
}
var permissions []accesscontrol.Permission
permissions := make([]accesscontrol.Permission, 0, len(actions))
for action := range actions {
p := managedPermission(action, resource, resourceID, resourceAttribute)
p.RoleID = roleID