]> 127.0.0.1 Git - part/.git/commitdiff
fix large allocs
authorqydysky <qydysky@foxmail.com>
Wed, 11 May 2022 02:03:54 +0000 (10:03 +0800)
committerqydysky <qydysky@foxmail.com>
Wed, 11 May 2022 02:03:54 +0000 (10:03 +0800)
io/io.go

index fb0be3302b69707eb0d9f0ac12eef2a657fec03e..3499cd3b87fb88d523e342f8357707757721152e 100644 (file)
--- a/io/io.go
+++ b/io/io.go
@@ -6,13 +6,13 @@ import (
 
 //no close rc any time
 //you can close wc, r, w.
-func RW2Chan(r io.ReadCloser,w io.WriteCloser) (rc,wc chan[]byte) {
+func RW2Chan(r io.ReadCloser, w io.WriteCloser) (rc, wc chan []byte) {
        if r != nil {
-               rc = make(chan[]byte, 1<<16)
-               go func(rc chan[]byte,r io.ReadCloser){
+               rc = make(chan []byte, 10)
+               go func(rc chan []byte, r io.ReadCloser) {
                        for {
                                buf := make([]byte, 1<<16)
-                               n,e := r.Read(buf)
+                               n, e := r.Read(buf)
                                if n != 0 {
                                        rc <- buf[:n]
                                } else if e != nil {
@@ -20,25 +20,25 @@ func RW2Chan(r io.ReadCloser,w io.WriteCloser) (rc,wc chan[]byte) {
                                        break
                                }
                        }
-               }(rc,r)
+               }(rc, r)
        }
-       
+
        if w != nil {
-               wc = make(chan[]byte, 1<<16)
-               go func(wc chan[]byte,w io.WriteCloser){
+               wc = make(chan []byte, 10)
+               go func(wc chan []byte, w io.WriteCloser) {
                        for {
-                               buf :=<- wc
-                               if len(buf) == 0 {//chan close
+                               buf := <-wc
+                               if len(buf) == 0 { //chan close
                                        w.Close()
                                        break
                                }
-                               _,e := w.Write(buf)
+                               _, e := w.Write(buf)
                                if e != nil {
                                        close(wc)
                                        break
                                }
                        }
-               }(wc,w)
+               }(wc, w)
        }
        return
-}
\ No newline at end of file
+}