MCPcopy
hub / github.com/segmentio/ksuid / fastDecodeBase62

Function fastDecodeBase62

base62.go:102–175  ·  view source on GitHub ↗

This function decodes the base 62 representation of the src KSUID to the binary form into dst. In order to support a couple of optimizations the function assumes that src is 27 bytes long and dst is 20 bytes long. Any unused bytes in dst will be set to zero.

(dst []byte, src []byte)

Source from the content-addressed store, hash-verified

100//
101// Any unused bytes in dst will be set to zero.
102func fastDecodeBase62(dst []byte, src []byte) error {
103 const srcBase = 62
104 const dstBase = 4294967296
105
106 // This line helps BCE (Bounds Check Elimination).
107 // It may be safely removed.
108 _ = src[26]
109
110 parts := [27]byte{
111 base62Value(src[0]),
112 base62Value(src[1]),
113 base62Value(src[2]),
114 base62Value(src[3]),
115 base62Value(src[4]),
116 base62Value(src[5]),
117 base62Value(src[6]),
118 base62Value(src[7]),
119 base62Value(src[8]),
120 base62Value(src[9]),
121
122 base62Value(src[10]),
123 base62Value(src[11]),
124 base62Value(src[12]),
125 base62Value(src[13]),
126 base62Value(src[14]),
127 base62Value(src[15]),
128 base62Value(src[16]),
129 base62Value(src[17]),
130 base62Value(src[18]),
131 base62Value(src[19]),
132
133 base62Value(src[20]),
134 base62Value(src[21]),
135 base62Value(src[22]),
136 base62Value(src[23]),
137 base62Value(src[24]),
138 base62Value(src[25]),
139 base62Value(src[26]),
140 }
141
142 n := len(dst)
143 bp := parts[:]
144 bq := [stringEncodedLength]byte{}
145
146 for len(bp) > 0 {
147 quotient := bq[:0]
148 remainder := uint64(0)
149
150 for _, c := range bp {
151 value := uint64(c) + uint64(remainder)*srcBase
152 digit := value / dstBase
153 remainder = value % dstBase
154
155 if len(quotient) != 0 || digit != 0 {
156 quotient = append(quotient, byte(digit))
157 }
158 }
159

Callers 2

fastAppendDecodeBase62Function · 0.85
ParseFunction · 0.85

Calls 1

base62ValueFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…