diff --git a/lib/logstorage/stream_id.go b/lib/logstorage/stream_id.go index 6d00e35f8..effe3893e 100644 --- a/lib/logstorage/stream_id.go +++ b/lib/logstorage/stream_id.go @@ -28,10 +28,8 @@ func (sid *streamID) reset() { // marshalString returns _stream_id value for the given sid. func (sid *streamID) marshalString(dst []byte) []byte { - bb := bbPool.Get() - bb.B = sid.marshal(bb.B) - dst = hex.AppendEncode(dst, bb.B) - bbPool.Put(bb) + dst = sid.tenantID.marshalString(dst) + dst = sid.id.marshalString(dst) return dst } diff --git a/lib/logstorage/tenant_id.go b/lib/logstorage/tenant_id.go index 101f53bd7..235d611e3 100644 --- a/lib/logstorage/tenant_id.go +++ b/lib/logstorage/tenant_id.go @@ -44,6 +44,12 @@ func (tid *TenantID) less(a *TenantID) bool { return tid.ProjectID < a.ProjectID } +func (tid *TenantID) marshalString(dst []byte) []byte { + n := uint64(tid.AccountID)<<32 | uint64(tid.ProjectID) + dst = marshalUint64Hex(dst, n) + return dst +} + // marshal appends the marshaled tid to dst and returns the result func (tid *TenantID) marshal(dst []byte) []byte { dst = encoding.MarshalUint32(dst, tid.AccountID) diff --git a/lib/logstorage/u128.go b/lib/logstorage/u128.go index f28fa20d3..d564e4862 100644 --- a/lib/logstorage/u128.go +++ b/lib/logstorage/u128.go @@ -32,6 +32,30 @@ func (u *u128) equal(a *u128) bool { return u.hi == a.hi && u.lo == a.lo } +func (u *u128) marshalString(dst []byte) []byte { + dst = marshalUint64Hex(dst, u.hi) + dst = marshalUint64Hex(dst, u.lo) + return dst +} + +func marshalUint64Hex(dst []byte, n uint64) []byte { + dst = marshalByteHex(dst, byte(n>>56)) + dst = marshalByteHex(dst, byte(n>>48)) + dst = marshalByteHex(dst, byte(n>>40)) + dst = marshalByteHex(dst, byte(n>>32)) + dst = marshalByteHex(dst, byte(n>>24)) + dst = marshalByteHex(dst, byte(n>>16)) + dst = marshalByteHex(dst, byte(n>>8)) + dst = marshalByteHex(dst, byte(n)) + return dst +} + +func marshalByteHex(dst []byte, x byte) []byte { + return append(dst, hexByteMap[(x>>4)&15], hexByteMap[x&15]) +} + +var hexByteMap = [16]byte{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'} + // marshal appends the marshaled u to dst and returns the result. func (u *u128) marshal(dst []byte) []byte { dst = encoding.MarshalUint64(dst, u.hi)