Skip to content

Commit

Permalink
structure: pre-alloc encoded key size.
Browse files Browse the repository at this point in the history
  • Loading branch information
siddontang committed Nov 27, 2015
1 parent f1b47be commit 624dd90
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions structure/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,21 @@ const (
func (t *TxStructure) encodeStringDataKey(key []byte) []byte {
// for codec Encode, we may add extra bytes data, so here and following encode
// we will use extra length like 4 for a little optimization.
ek := make([]byte, 0, len(t.prefix)+len(key)+4)
ek := make([]byte, 0, len(t.prefix)+len(key)+24)
ek = append(ek, t.prefix...)
ek = codec.EncodeBytes(ek, key)
return codec.EncodeUint(ek, uint64(StringData))
}

func (t *TxStructure) encodeHashMetaKey(key []byte) []byte {
ek := make([]byte, 0, len(t.prefix)+len(key)+4)
ek := make([]byte, 0, len(t.prefix)+len(key)+24)
ek = append(ek, t.prefix...)
ek = codec.EncodeBytes(ek, key)
return codec.EncodeUint(ek, uint64(HashMeta))
}

func (t *TxStructure) encodeHashDataKey(key []byte, field []byte) []byte {
ek := make([]byte, 0, len(t.prefix)+len(key)+len(field)+6)
ek := make([]byte, 0, len(t.prefix)+len(key)+len(field)+30)
ek = append(ek, t.prefix...)
ek = codec.EncodeBytes(ek, key)
ek = codec.EncodeUint(ek, uint64(HashData))
Expand Down Expand Up @@ -93,21 +93,21 @@ func (t *TxStructure) decodeHashDataKey(ek []byte) ([]byte, []byte, error) {
}

func (t *TxStructure) hashDataKeyPrefix(key []byte) []byte {
ek := make([]byte, 0, len(t.prefix)+len(key)+4)
ek := make([]byte, 0, len(t.prefix)+len(key)+24)
ek = append(ek, t.prefix...)
ek = codec.EncodeBytes(ek, key)
return codec.EncodeUint(ek, uint64(HashData))
}

func (t *TxStructure) encodeListMetaKey(key []byte) []byte {
ek := make([]byte, 0, len(t.prefix)+len(key)+4)
ek := make([]byte, 0, len(t.prefix)+len(key)+24)
ek = append(ek, t.prefix...)
ek = codec.EncodeBytes(ek, key)
return codec.EncodeUint(ek, uint64(ListMeta))
}

func (t *TxStructure) encodeListDataKey(key []byte, index int64) []byte {
ek := make([]byte, 0, len(t.prefix)+len(key)+13)
ek := make([]byte, 0, len(t.prefix)+len(key)+36)
ek = append(ek, t.prefix...)
ek = codec.EncodeBytes(ek, key)
ek = codec.EncodeUint(ek, uint64(ListData))
Expand Down

0 comments on commit 624dd90

Please sign in to comment.