Re: [go-nuts] Go string and UTF-8

2019-08-20 Thread Jan Mercl
On Tue, Aug 20, 2019 at 3:17 PM Pierre Durand wrote: > > Well, in my case I don't want to convert the []byte to hexadecimal string, > because it uses 2x more memory. > The code contains a huge map where the key is an MD5 hash. md5 hash is an array type and can be used as a map key directly:

Re: [go-nuts] Go string and UTF-8

2019-08-20 Thread Pierre Durand
Well, in my case I don't want to convert the []byte to hexadecimal string, because it uses 2x more memory. The code contains a huge map where the key is an MD5 hash. Please note that I'm not personally working on this. I was reviewing the code written by a coworker, and I noticed that there was

Re: [go-nuts] Go string and UTF-8

2019-08-20 Thread Sam Whited
On August 20, 2019 11:50:54 AM UTC, Rob Pike wrote: >Printf can print hexadecimal just fine. Never understood the point of >encoding/hex. I always thought that the C style format strings were unreadable and the hex package methods were much clearer, personally. —Sam -- You received this

Re: [go-nuts] Go string and UTF-8

2019-08-20 Thread Rob Pike
Printf can print hexadecimal just fine. Never understood the point of encoding/hex. Meanwhile, for questions about strings, see blog.golang.org/strings. -rob On Tue, Aug 20, 2019 at 9:00 PM Sam Whited wrote: > I personally wouldn't do this. If you're going to incur the overhead of a > heap

Re: [go-nuts] Go string and UTF-8

2019-08-20 Thread Sam Whited
I personally wouldn't do this. If you're going to incur the overhead of a heap allocation, might as well incur a bit more and encode the hash, eg. using hex.EncodeToString [1], just so that you don't forget and try to print or decode the string as utf8 later. —Sam [1]:

[go-nuts] Go string and UTF-8

2019-08-20 Thread Pierre Durand
I know that by convention Go string contain UTF-8 encoded text. Is it recommended/a good practice to store invalid bytes in a string ? The use case: - compute a hash => get a []byte - convert the []byte to string (this string is not UTF-8 valid) - use the string as a map key In my case, the