mirror of https://github.com/poanetwork/gecko.git
pack pointer to string instead of string...halves memory footprint
This commit is contained in:
parent
ee1cf620a1
commit
9c4cfecf4e
|
@ -284,6 +284,16 @@ func (p *Packer) PackStr(str string) {
|
|||
p.PackFixedBytes([]byte(str))
|
||||
}
|
||||
|
||||
// PackStrPtr appends a string to the byte array
|
||||
func (p *Packer) PackStrPtr(str *string) {
|
||||
strSize := len(*str)
|
||||
if strSize > MaxStringLen {
|
||||
p.Add(errInvalidInput)
|
||||
}
|
||||
p.PackShort(uint16(strSize))
|
||||
p.PackFixedBytes([]byte(*str))
|
||||
}
|
||||
|
||||
// UnpackStr unpacks a string from the byte array
|
||||
func (p *Packer) UnpackStr() string {
|
||||
strSize := p.UnpackShort()
|
||||
|
|
|
@ -127,12 +127,11 @@ func (c *codec) marshal(value reflect.Value, index int, funcs *[]func(*wrappers.
|
|||
// Case: Value can't be marshalled
|
||||
switch valueKind {
|
||||
case reflect.Interface, reflect.Ptr, reflect.Invalid:
|
||||
if value.IsNil() { // Can't marshal nil or nil pointers
|
||||
if value.IsNil() { // Can't marshal nil (except nil slices)
|
||||
return 0, 0, errNil
|
||||
}
|
||||
}
|
||||
|
||||
// Case: Value is of known size; return its byte repr.
|
||||
switch valueKind {
|
||||
case reflect.Uint8:
|
||||
size = 1
|
||||
|
@ -211,7 +210,7 @@ func (c *codec) marshal(value reflect.Value, index int, funcs *[]func(*wrappers.
|
|||
asStr := value.String()
|
||||
size = len(asStr) + wrappers.ShortLen
|
||||
(*funcs)[index] = func(p *wrappers.Packer) error {
|
||||
p.PackStr(asStr)
|
||||
p.PackStrPtr(&asStr)
|
||||
return p.Err
|
||||
}
|
||||
return
|
||||
|
|
Loading…
Reference in New Issue