Re: [go-nuts] Safeness of using reflect.Type as a map key instead of reflect.Type.Name() ?

2018-08-18 Thread roger peppe
Yes, it's conventional to use reflect.Type as a map key. In fact, you
should do that because not all types have different names, even if
they're in the same package.

For example: https://play.golang.org/p/Xqc8hkKPu4_v

On 18 August 2018 at 10:40, Christophe Meessen
 wrote:
> I need to index data by type and I have two options:
> - use a string as key and index the string returned by reflect.Type.Name()
> - use reflect.Type as key
>
> I have the impression that indexing by reflect.Type would be slightly more
> speed and space efficient, but I'm unsure if the relation between
> reflect.Type and reflect.Type.Name() is bijective.
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Safeness of using reflect.Type as a map key instead of reflect.Type.Name() ?

2018-08-18 Thread Sebastien Binet
Bonjour Christophe,

Yes, it is safe to use reflect.Type as a key.
Even if that type was loaded from another shared library through 'plugin'.
At least that's how it is supposed to work :)

-s


sent from my droid

On Sat, Aug 18, 2018, 11:40 Christophe Meessen 
wrote:

> I need to index data by type and I have two options:
> - use a string as key and index the string returned by reflect.Type.Name()
> - use reflect.Type as key
>
> I have the impression that indexing by reflect.Type would be slightly more
> speed and space efficient, but I'm unsure if the relation between
> reflect.Type and reflect.Type.Name() is bijective.
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Safeness of using reflect.Type as a map key instead of reflect.Type.Name() ?

2018-08-18 Thread Christophe Meessen
I need to index data by type and I have two options:
- use a string as key and index the string returned by reflect.Type.Name()
- use reflect.Type as key

I have the impression that indexing by reflect.Type would be slightly more 
speed and space efficient, but I'm unsure if the relation between 
reflect.Type and reflect.Type.Name() is bijective. 


-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.