Neat -- the Go runtime has a staticBytes array that contains every byte value, so you can convert any single-byte []byte to a string by indexing into staticBytes. No allocation required!https://twitter.com/golang_cls/status/969273003900096513 …
I was hoping that there would be some way to modify staticbytes (via unsafe), so that e.g. string([]byte{'a'}) -> "b". But there's no way to get a pointer to it, and modifying the string contents directly results in a segfault.
-
-
btw, apparently strconv does this too: https://go-review.googlesource.com/c/go/+/37963/7/src/strconv/itoa.go … Declaring big static arrays like these has marginal cost (larger binaries?), so I wonder how the devs decided that 100 was the appropriate size.
Show this threadThanks. Twitter will use this to make your timeline better. UndoUndo
-
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.