From d7590729f112f581b3fc3888b30621fdb07d8760 Mon Sep 17 00:00:00 2001 From: aeoluswing Date: Fri, 26 Mar 2021 18:50:06 +0800 Subject: [PATCH] Fix the assignment of sync buf --- httpstaticserver.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/httpstaticserver.go b/httpstaticserver.go index 7e946a7..06be457 100644 --- a/httpstaticserver.go +++ b/httpstaticserver.go @@ -251,11 +251,14 @@ func (s *HTTPStaticServer) hUploadOrMkdir(w http.ResponseWriter, req *http.Reque } // Note: very large size file might cause poor performance // _, copyErr = io.Copy(dst, file) + // use sync.Pool caching buf to reduce gc ratio - var bufPtr = &sync.Pool{ + bufPool := sync.Pool{ New: func() interface{} { return make([]byte, 32*1024) }, } - _, copyErr = io.CopyBuffer(dst, file, bufPtr.Get().([]byte)) + buf := bufPool.Get().([]byte) + _, copyErr = io.CopyBuffer(dst, file, buf) + defer bufPool.Put(&buf) dst.Close() // } if copyErr != nil {