Commit 47541520 authored by Joshua Gutow's avatar Joshua Gutow

Use sync.Pool for zlib Writers

parent eb09231b
......@@ -9,10 +9,18 @@ import (
"fmt"
"io"
"regexp"
"sync"
"github.com/ethereum/go-ethereum/crypto"
)
var zlibWriterPool = sync.Pool{
New: func() any {
var buf bytes.Buffer
return zlib.NewWriter(&buf)
},
}
func detectEncoding(data []byte) (string, error) {
// Regular expressions to check for base64 and hex patterns
base64Pattern := "^[A-Za-z0-9+/]*={0,2}$"
......@@ -36,7 +44,9 @@ func (p *Page) MarshalText() ([]byte, error) {
func (p *Page) MarshalJSON() ([]byte, error) {
var out bytes.Buffer
w := zlib.NewWriter(&out)
w := zlibWriterPool.Get().(*zlib.Writer)
defer zlibWriterPool.Put(w)
w.Reset(&out)
w.Write(p[:])
w.Close()
return json.Marshal(out.Bytes())
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment