Skip to content

Commit

Permalink
further optimize rdx id
Browse files Browse the repository at this point in the history
  • Loading branch information
Termina1 committed Sep 16, 2024
1 parent 53fd3bc commit fb5d353
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions rdx/id.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,21 @@ func TakeIDWary(lit byte, pack []byte) (id ID, rest []byte, err error) {
}

func (id ID) String() string {
seq := id.Seq()
off := id.Off()
src := id.Src()
if off == 0 {
return strconv.FormatInt(int64(src), 16) + "-" + strconv.FormatInt(int64(seq), 16)
} else {
return strconv.FormatInt(int64(src), 16) + "-" + strconv.FormatInt(int64(seq), 16) + "-" + strconv.FormatInt(int64(off), 16)

var buf [64]byte
b := buf[:0]

b = strconv.AppendInt(b, int64(id.Src()), 16)
b = append(b, '-')
b = strconv.AppendInt(b, int64(id.Seq()), 16)

if off := id.Off(); off != 0 {
b = append(b, '-')
b = strconv.AppendInt(b, int64(off), 16)
}

return string(b)

}

const Hex = "0123456789abcdef"
Expand Down

0 comments on commit fb5d353

Please sign in to comment.