mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-22 19:50:36 +00:00
dca36e8b29
* Trace first block * Fixes for CalcTrieRoots * Timings of the CalcTrieRoot * Fix lint * Add memory profiling * Reduce allocations in StreamHash * Fix * Fix * Fix * Optimise allocations * Reuse streams * Fixes * Fix * Unit test fix * Fix lint * Reuse hashbuilder * No loop * Reuse resolver * Fixed tests * Fix test * Fix test * Fix test * Fix witness threshold * Optimise allocations in RLP transform * Optimise allocations in RLP transform * Optimise branchHash * 100 times again * Replace ToStream with Iterator * StreamMergeIterator * No streams * Amplification * Minimise the use of hashOnly * 100 times * Reduce stack operations * Reduce appends * More optimisations * More optimisations * More optimisations * local hex * Small fix * Remove test * Fix lint * Fix lint * Fix lint * Add test for empty * Fix lint * More tests * Fix lint * Add measurement of stateless exec
59 lines
1.4 KiB
Go
59 lines
1.4 KiB
Go
package rlphacks
|
|
|
|
import (
|
|
"io"
|
|
)
|
|
|
|
type RlpSerializableBytes []byte
|
|
|
|
func (b RlpSerializableBytes) ToDoubleRLP(w io.Writer, prefixBuf []byte) error {
|
|
return encodeBytesAsRlpToWriter(b, w, generateByteArrayLenDouble, prefixBuf)
|
|
}
|
|
|
|
func (b RlpSerializableBytes) RawBytes() []byte {
|
|
return b
|
|
}
|
|
|
|
func (b RlpSerializableBytes) DoubleRLPLen() int {
|
|
if len(b) < 1 {
|
|
return 0
|
|
}
|
|
return generateRlpPrefixLenDouble(len(b), b[0]) + len(b)
|
|
}
|
|
|
|
type RlpEncodedBytes []byte
|
|
|
|
func (b RlpEncodedBytes) ToDoubleRLP(w io.Writer, prefixBuf []byte) error {
|
|
return encodeBytesAsRlpToWriter(b, w, generateByteArrayLen, prefixBuf)
|
|
}
|
|
|
|
func (b RlpEncodedBytes) RawBytes() []byte {
|
|
return b
|
|
}
|
|
|
|
func (b RlpEncodedBytes) DoubleRLPLen() int {
|
|
return generateRlpPrefixLen(len(b)) + len(b)
|
|
}
|
|
|
|
func encodeBytesAsRlpToWriter(source []byte, w io.Writer, prefixGenFunc func([]byte, int, int) int, prefixBuf []byte) error {
|
|
// > 1 byte, write a prefix or prefixes first
|
|
if len(source) > 1 || (len(source) == 1 && source[0] >= 0x80) {
|
|
prefixLen := prefixGenFunc(prefixBuf, 0, len(source))
|
|
|
|
if _, err := w.Write(prefixBuf[:prefixLen]); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
_, err := w.Write(source)
|
|
return err
|
|
}
|
|
|
|
func EncodeByteArrayAsRlp(raw []byte, w io.Writer, prefixBuf []byte) (int, error) {
|
|
err := encodeBytesAsRlpToWriter(raw, w, generateByteArrayLen, prefixBuf)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
return generateRlpPrefixLen(len(raw)) + len(raw), nil
|
|
}
|