Skip to content

Commit

Permalink
*: Use AppendUint64 for byte slice appending
Browse files Browse the repository at this point in the history
Signed-off-by: Pavel Karpy <[email protected]>
  • Loading branch information
carpawell committed Aug 10, 2023
1 parent 3aa6607 commit 6c83d5d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 20 deletions.
7 changes: 1 addition & 6 deletions pkg/innerring/processors/governance/process_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,7 @@ func (gp *Processor) processAlphabetSync(txHash util.Uint256) {
}

// 4. Update NeoFS contract in the mainnet.
epoch := gp.epochState.EpochCounter()

buf := make([]byte, 8)
binary.LittleEndian.PutUint64(buf, epoch)

id := append([]byte(alphabetUpdateIDPrefix), buf...)
id := binary.LittleEndian.AppendUint64([]byte(alphabetUpdateIDPrefix), gp.epochState.EpochCounter())

prm := neofscontract.AlphabetUpdatePrm{}

Expand Down
25 changes: 11 additions & 14 deletions pkg/local_object_storage/pilorama/boltdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -845,19 +845,19 @@ func (t *boltForest) logFromBytes(lm *LogMove, data []byte) error {
func (t *boltForest) logToBytes(lm *LogMove) []byte {
w := io.NewBufBinWriter()
size := 8 + 8 + lm.Meta.Size() + 1
//if lm.HasOld {
// if lm.HasOld {
// size += 8 + lm.Old.Meta.Size()
//}
// }

w.Grow(size)
w.WriteU64LE(lm.Child)
w.WriteU64LE(lm.Parent)
lm.Meta.EncodeBinary(w.BinWriter)
//w.WriteBool(lm.HasOld)
//if lm.HasOld {
// w.WriteBool(lm.HasOld)
// if lm.HasOld {
// w.WriteU64LE(lm.Old.Parent)
// lm.Old.Meta.EncodeBinary(w.BinWriter)
//}
// }
return w.Bytes()
}

Expand All @@ -883,10 +883,10 @@ func stateKey(key []byte, child Node) []byte {
}

func (t *boltForest) putState(b *bbolt.Bucket, key []byte, parent Node, timestamp Timestamp, meta []byte) error {
data := make([]byte, len(meta)+8+8)
binary.LittleEndian.PutUint64(data, parent)
binary.LittleEndian.PutUint64(data[8:], timestamp)
copy(data[16:], meta)
data := make([]byte, 0, len(meta)+8+8)
data = binary.LittleEndian.AppendUint64(data, parent)
data = binary.LittleEndian.AppendUint64(data, timestamp)
data = append(data, meta...)
return b.Put(key, data)
}

Expand Down Expand Up @@ -927,11 +927,8 @@ func internalKey(key []byte, k, v string, parent, node Node) []byte {
key = append(key, byte(l), byte(l>>8))
key = append(key, v...)

var raw [8]byte
binary.LittleEndian.PutUint64(raw[:], parent)
key = append(key, raw[:]...)
key = binary.LittleEndian.AppendUint64(key, parent)
key = binary.LittleEndian.AppendUint64(key, node)

binary.LittleEndian.PutUint64(raw[:], node)
key = append(key, raw[:]...)
return key
}

0 comments on commit 6c83d5d

Please sign in to comment.