Skip to content

Commit 7434cd7

Browse files
committed
Avoid redundant compilation of archive name regex
Previously, the compilation of the regular expression used to convert the library name to the release archive root folder and file name was done inside the function, which caused it to be compiled redundantly for every subsequent call. Moving it to the package scope improves the function's efficiency.
1 parent d0f3044 commit 7434cd7

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

internal/libraries/archive/archive.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,11 @@ func (archive *Archive) Create() error {
9494
return nil
9595
}
9696

97+
var zipFolderNamePattern = regexp.MustCompile("[^a-zA-Z0-9]")
98+
9799
// zipFolderName returns the name to use for the folder.
98100
func zipFolderName(library *metadata.LibraryMetadata) string {
99-
pattern := regexp.MustCompile("[^a-zA-Z0-9]")
100-
return pattern.ReplaceAllString(library.Name, "_") + "-" + library.Version
101+
return zipFolderNamePattern.ReplaceAllString(library.Name, "_") + "-" + library.Version
101102
}
102103

103104
// getSizeAndCalculateChecksum returns the size and SHA-256 checksum for the given file.

0 commit comments

Comments
 (0)