Skip to content

Commit

Permalink
Merge pull request #108 from divebomb/master
Browse files Browse the repository at this point in the history
Imp: use gost bytes pool
  • Loading branch information
wongoo authored Jul 29, 2019
2 parents a29499a + 365519b commit 3d274e9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 29 deletions.
9 changes: 7 additions & 2 deletions binary.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
)

import (
gxbytes "github.com/dubbogo/gost/bytes"
perrors "github.com/pkg/errors"
)

Expand Down Expand Up @@ -129,8 +130,12 @@ func (d *Decoder) decBinary(flag int32) ([]byte, error) {
return []byte(""), nil
}

data := make([]byte, 0)
buf := make([]byte, 65536)
data := make([]byte, 0, 128)
bufp := gxbytes.GetBytes(65546)
buf := *bufp

defer gxbytes.PutBytes(bufp)

for {
length, err = d.getBinaryLength(tag)
if err != nil {
Expand Down
27 changes: 0 additions & 27 deletions string.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package hessian

import (
"bufio"
"bytes"
"io"
"reflect"
Expand Down Expand Up @@ -134,32 +133,6 @@ func (d *Decoder) getStringLength(tag byte) (int32, error) {
}
}

func getRune(reader io.Reader) (rune, int, error) {
var (
runeNil rune
typ reflect.Type
)

typ = reflect.TypeOf(reader.(interface{}))

switch {
case typ == reflect.TypeOf(&bufio.Reader{}):
byteReader := reader.(interface{}).(*bufio.Reader)
return byteReader.ReadRune()

case typ == reflect.TypeOf(&bytes.Buffer{}):
byteReader := reader.(interface{}).(*bytes.Buffer)
return byteReader.ReadRune()

case typ == reflect.TypeOf(&bytes.Reader{}):
byteReader := reader.(interface{}).(*bytes.Reader)
return byteReader.ReadRune()

default:
return runeNil, 0, nil
}
}

// hessian-lite/src/main/java/com/alibaba/com/caucho/hessian/io/Hessian2Input.java : readString
func (d *Decoder) decString(flag int32) (string, error) {
var (
Expand Down

0 comments on commit 3d274e9

Please sign in to comment.