mirror of
https://github.com/yannh/kubeconform.git
synced 2026-02-18 17:37:03 +00:00
Increase buffer size when needed as guessed from file size
This commit is contained in:
parent
c4b044f3be
commit
3f2c768703
1 changed files with 14 additions and 2 deletions
|
|
@ -127,10 +127,22 @@ func FromFiles(ctx context.Context, paths []string, ignoreFilePatterns []string)
|
|||
files, errors := findFilesInFolders(ctx, paths, ignoreFilePatterns)
|
||||
|
||||
go func() {
|
||||
maxResourceSize := 4 * 1024 * 1024 // 4MB ought to be enough for everybody
|
||||
buf := make([]byte, maxResourceSize) // We reuse this to avoid multiple large memory allocations
|
||||
maxResourceSize := int64(1 * 1024 * 1024) // 4MB ought to be enough for everybody
|
||||
buf := make([]byte, maxResourceSize) // We reuse this to avoid multiple large memory allocations
|
||||
|
||||
for p := range files {
|
||||
fi, err := os.Stat(p)
|
||||
if err != nil {
|
||||
errors <- DiscoveryError{p, err}
|
||||
continue
|
||||
}
|
||||
if filesize := fi.Size(); maxResourceSize <= filesize {
|
||||
for maxResourceSize <= filesize {
|
||||
// We increase by factors of 2 every time to avoid allocating too often
|
||||
maxResourceSize *= 2
|
||||
}
|
||||
buf = make([]byte, maxResourceSize) // We reuse this to avoid multiple large memory allocations
|
||||
}
|
||||
findResourcesInFile(p, resources, errors, buf)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue