printHexPtr outputs a uintptr formatted as hexadecimal with a leading '0x' prefix to Writer w.
(w io.Writer, p uintptr)
| 183 | // printHexPtr outputs a uintptr formatted as hexadecimal with a leading '0x' |
| 184 | // prefix to Writer w. |
| 185 | func printHexPtr(w io.Writer, p uintptr) { |
| 186 | // Null pointer. |
| 187 | num := uint64(p) |
| 188 | if num == 0 { |
| 189 | w.Write(nilAngleBytes) |
| 190 | return |
| 191 | } |
| 192 | |
| 193 | // Max uint64 is 16 bytes in hex + 2 bytes for '0x' prefix |
| 194 | buf := make([]byte, 18) |
| 195 | |
| 196 | // It's simpler to construct the hex string right to left. |
| 197 | base := uint64(16) |
| 198 | i := len(buf) - 1 |
| 199 | for num >= base { |
| 200 | buf[i] = hexDigits[num%base] |
| 201 | num /= base |
| 202 | i-- |
| 203 | } |
| 204 | buf[i] = hexDigits[num] |
| 205 | |
| 206 | // Add '0x' prefix. |
| 207 | i-- |
| 208 | buf[i] = 'x' |
| 209 | i-- |
| 210 | buf[i] = '0' |
| 211 | |
| 212 | // Strip unused leading bytes. |
| 213 | buf = buf[i:] |
| 214 | w.Write(buf) |
| 215 | } |
| 216 | |
| 217 | // valuesSorter implements sort.Interface to allow a slice of reflect.Value |
| 218 | // elements to be sorted. |