mirror of
https://github.com/project-zot/zot.git
synced 2026-06-18 21:48:04 +08:00
refactor: optimize code with modern Go patterns and pre-allocation (#3576)
This commit modernizes code across multiple packages by: - Using Go 1.18+ features (slices.IndexFunc, strings.Cut) - Pre-allocating slices and maps with known capacity - Consolidating defensive checks and improving code clarity - Fixing test data and build tag issues CLI client improvements: - Pre-allocate slices in search functions and service methods - Replace strings.Split with strings.Cut for username:password parsing - Use range-based iteration instead of manual index loops Search extension optimizations: - Cache sort functions in pagination modules - Pre-allocate page buffers and maps - Consolidate defensive checks in filterBaseImages/filterDerivedImages - Fix image bas and derived logic allowing out of sequence layers for base images - Fix image pagination reporting images groupped by repos when sorted by update time - Remove duplicate resolver_test.go file Monitoring extension: - Replace manual loops with slices.IndexFunc - Pre-allocate bucketsFloat2String map Sync extension: - Pre-allocate slice in parseRegistryURLs Test utilities: - Fix build tags in oci_layout.go Signed-off-by: Andrei Aaron <andreifdaaron@gmail.com>
This commit is contained in:
@@ -46,7 +46,7 @@ func parseReference(reference string) (digest.Digest, bool) {
|
||||
|
||||
// Given a list of registry string URLs parse them and return *url.URLs slice.
|
||||
func parseRegistryURLs(rawURLs []string) ([]*url.URL, error) {
|
||||
urls := make([]*url.URL, 0)
|
||||
urls := make([]*url.URL, 0, len(rawURLs))
|
||||
|
||||
for _, rawURL := range rawURLs {
|
||||
u, err := url.Parse(rawURL)
|
||||
|
||||
Reference in New Issue
Block a user