Merge pull request #2303 from kolyshkin/minmax
Use min/max to simplify the code
This commit is contained in:
commit
3fc5c23095
|
|
@ -496,10 +496,7 @@ type slowEmptyTarReader struct {
|
|||
// Read is a slow reader of an empty tar (like the output of "tar c --files-from /dev/null")
|
||||
func (s *slowEmptyTarReader) Read(p []byte) (int, error) {
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
count := s.chunkSize
|
||||
if len(p) < s.chunkSize {
|
||||
count = len(p)
|
||||
}
|
||||
count := min(len(p), s.chunkSize)
|
||||
for i := 0; i < count; i++ {
|
||||
p[i] = 0
|
||||
}
|
||||
|
|
|
|||
|
|
@ -142,10 +142,7 @@ func (rc *rollingChecksumReader) Read(b []byte) (bool, int, error) {
|
|||
rc.IsLastChunkZeros = false
|
||||
|
||||
if rc.pendingHole > 0 {
|
||||
toCopy := int64(len(b))
|
||||
if rc.pendingHole < toCopy {
|
||||
toCopy = rc.pendingHole
|
||||
}
|
||||
toCopy := min(rc.pendingHole, int64(len(b)))
|
||||
rc.pendingHole -= toCopy
|
||||
for i := int64(0); i < toCopy; i++ {
|
||||
b[i] = 0
|
||||
|
|
|
|||
|
|
@ -698,18 +698,12 @@ func (c *chunkedDiffer) prepareCompressedStreamToFile(partCompression compressed
|
|||
|
||||
// hashHole writes SIZE zeros to the specified hasher
|
||||
func hashHole(h hash.Hash, size int64, copyBuffer []byte) error {
|
||||
count := int64(len(copyBuffer))
|
||||
if size < count {
|
||||
count = size
|
||||
}
|
||||
count := min(size, int64(len(copyBuffer)))
|
||||
for i := int64(0); i < count; i++ {
|
||||
copyBuffer[i] = 0
|
||||
}
|
||||
for size > 0 {
|
||||
count = int64(len(copyBuffer))
|
||||
if size < count {
|
||||
count = size
|
||||
}
|
||||
count = min(size, int64(len(copyBuffer)))
|
||||
if _, err := h.Write(copyBuffer[:count]); err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -93,10 +93,7 @@ loop0:
|
|||
}
|
||||
|
||||
// add new byte slice to the buffers slice and continue writing
|
||||
nextCap := b.Cap() * 2
|
||||
if nextCap > maxCap {
|
||||
nextCap = maxCap
|
||||
}
|
||||
nextCap := min(b.Cap()*2, maxCap)
|
||||
bp.buf = append(bp.buf, getBuffer(nextCap))
|
||||
}
|
||||
bp.wait.Broadcast()
|
||||
|
|
|
|||
|
|
@ -276,10 +276,7 @@ func (s *store) getAutoUserNS(options *types.AutoUserNsOptions, image *Image, rl
|
|||
// bigger than s.autoNsMaxSize.
|
||||
// This is a best effort heuristic.
|
||||
if requestedSize == 0 {
|
||||
size = initialSize
|
||||
if s.autoNsMinSize > size {
|
||||
size = s.autoNsMinSize
|
||||
}
|
||||
size = max(s.autoNsMinSize, initialSize)
|
||||
if image != nil {
|
||||
sizeFromImage, err := s.getMaxSizeFromImage(image, rlstore, lstores, options.PasswdFile, options.GroupFile)
|
||||
if err != nil {
|
||||
|
|
|
|||
Loading…
Reference in New Issue