go-reflect icon indicating copy to clipboard operation
go-reflect copied to clipboard

Fix caching in benchmark Marshaler function

Open zolstein opened this issue 2 years ago • 0 comments

Update the Marshal function to call TypeID on the input value rather than on the type object to generate the cache key.

The TypeID function internally calls TypeOf on the input and returns the pointer to the resulting object. Calling TypeID on the type object always returns the TypeID of "Type". This causes the Marshal function to generate an encoder for the type on the first call, then reuse that same encoder for all subsequent calls regardless of the input type. Changing this to call TypeID on the input object results in the correct behavior.

Also adds a space between elements to make the formatting clearer.

zolstein avatar Jul 13 '22 07:07 zolstein