Plugins: Optimize creation of Golang errors and slices (#69448)

* tidy up

* fix tests
This commit is contained in:
Will Browne
2023-06-07 17:22:43 +02:00
committed by GitHub
parent 8a8b5da1ee
commit 1fd4953833
13 changed files with 72 additions and 66 deletions
+4 -4
View File
@@ -81,7 +81,7 @@ func (l *Loader) Load(ctx context.Context, src plugins.PluginSource) ([]*plugins
// nolint:gocyclo
func (l *Loader) loadPlugins(ctx context.Context, src plugins.PluginSource, found []*plugins.FoundBundle) ([]*plugins.Plugin, error) {
var loadedPlugins []*plugins.Plugin
loadedPlugins := make([]*plugins.Plugin, 0, len(found))
for _, p := range found {
if _, exists := l.pluginRegistry.Plugin(ctx, p.Primary.JSONData.ID); exists {
@@ -129,7 +129,7 @@ func (l *Loader) loadPlugins(ctx context.Context, src plugins.PluginSource, foun
}
// validate signatures
verifiedPlugins := make([]*plugins.Plugin, 0)
verifiedPlugins := make([]*plugins.Plugin, 0, len(loadedPlugins))
for _, plugin := range loadedPlugins {
signingError := l.signatureValidator.Validate(plugin)
if signingError != nil {
@@ -180,7 +180,7 @@ func (l *Loader) loadPlugins(ctx context.Context, src plugins.PluginSource, foun
}
// initialize plugins
initializedPlugins := make([]*plugins.Plugin, 0)
initializedPlugins := make([]*plugins.Plugin, 0, len(verifiedPlugins))
for _, p := range verifiedPlugins {
// Detect angular for external plugins
if p.IsExternalPlugin() {
@@ -360,7 +360,7 @@ func defaultLogoPath(pluginType plugins.Type) string {
}
func (l *Loader) PluginErrors() []*plugins.Error {
errs := make([]*plugins.Error, 0)
errs := make([]*plugins.Error, 0, len(l.errs))
for _, err := range l.errs {
errs = append(errs, &plugins.Error{
PluginID: err.PluginID,