Skip to content

Commit f896659

Browse files
qiulaidongfenggopherbot
authored andcommitted
archive: use predeclared function min
Change-Id: I23e0005071fcbafeaecaa05f51712dd1de6eed01 Change-Id: I23e0005071fcbafeaecaa05f51712dd1de6eed01 GitHub-Last-Rev: 364d7c7 GitHub-Pull-Request: #61661 Reviewed-on: https://go-review.googlesource.com/c/go/+/514215 TryBot-Result: Gopher Robot <[email protected]> Auto-Submit: Ian Lance Taylor <[email protected]> Reviewed-by: David Chase <[email protected]> Run-TryBot: Ian Lance Taylor <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> Run-TryBot: Ian Lance Taylor <[email protected]>
1 parent 54a540f commit f896659

File tree

3 files changed

+4
-25
lines changed

3 files changed

+4
-25
lines changed

src/archive/tar/common.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -727,10 +727,3 @@ func isHeaderOnlyType(flag byte) bool {
727727
return false
728728
}
729729
}
730-
731-
func min(a, b int64) int64 {
732-
if a < b {
733-
return a
734-
}
735-
return b
736-
}

src/archive/zip/writer.go

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -406,8 +406,8 @@ func writeHeader(w io.Writer, h *header) error {
406406
// flags.
407407
if h.raw && !h.hasDataDescriptor() {
408408
b.uint32(h.CRC32)
409-
b.uint32(uint32(min64(h.CompressedSize64, uint32max)))
410-
b.uint32(uint32(min64(h.UncompressedSize64, uint32max)))
409+
b.uint32(uint32(min(h.CompressedSize64, uint32max)))
410+
b.uint32(uint32(min(h.UncompressedSize64, uint32max)))
411411
} else {
412412
// When this package handle the compression, these values are
413413
// always written to the trailing data descriptor.
@@ -427,13 +427,6 @@ func writeHeader(w io.Writer, h *header) error {
427427
return err
428428
}
429429

430-
func min64(x, y uint64) uint64 {
431-
if x < y {
432-
return x
433-
}
434-
return y
435-
}
436-
437430
// CreateRaw adds a file to the zip archive using the provided FileHeader and
438431
// returns a Writer to which the file contents should be written. The file's
439432
// contents must be written to the io.Writer before the next call to Create,
@@ -445,8 +438,8 @@ func (w *Writer) CreateRaw(fh *FileHeader) (io.Writer, error) {
445438
return nil, err
446439
}
447440

448-
fh.CompressedSize = uint32(min64(fh.CompressedSize64, uint32max))
449-
fh.UncompressedSize = uint32(min64(fh.UncompressedSize64, uint32max))
441+
fh.CompressedSize = uint32(min(fh.CompressedSize64, uint32max))
442+
fh.UncompressedSize = uint32(min(fh.UncompressedSize64, uint32max))
450443

451444
h := &header{
452445
FileHeader: fh,

src/archive/zip/zip_test.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -198,13 +198,6 @@ func (r *rleBuffer) Write(p []byte) (n int, err error) {
198198
return len(p), nil
199199
}
200200

201-
func min(x, y int64) int64 {
202-
if x < y {
203-
return x
204-
}
205-
return y
206-
}
207-
208201
func memset(a []byte, b byte) {
209202
if len(a) == 0 {
210203
return

0 commit comments

Comments
 (0)