Closed jason-o-matic closed 11 years ago
Adding type coercion would be a performance regression, sorry. The real issue might be, why do the gets appear to work at all?
In my personal opinion this kind of programming style leads to bugs. How does the gem know your to_s is unique or even deterministic?
I wouldn't think the gem would care if my to_str was unique or deterministic. If it wasn't I would have bugs, and bugs would be expected until I fixed my code. Essentially, whatever object I pass in would have to act enough like a string to work.
I was guessing that since the gets worked that there was some additional checking happening on get_multi that could be removed, but maybe that's not the case?
Where would the performance regression come from? Couldn't you treat the incoming object like a string without actually checking that it is a string?
Perhaps, but assuming its a string, rescuing the exception, and recovering would very expensive. It would lead to unpredictable performance in practice. A slight change from a string to an object could hose your efficiency.
I need to investigate why non-strings are accepted at all, really.
Do you really need to rescue the exception? I would expect it to blow up if I wasn't passing in something that passed as a string.
Ok, you are right, and I am wrong. Ruby convention demands that I honor to_str and a fast macro is provided for the purpose in the C API. It won't regress performance.
I've packaged up a bunch of logic around producing cache keys into my own key object, but right now I need to throw
.to_s
on these objects in some cases.It seems like all of the methods should take any object that responds to
to_str
.Here's my simplified example of what I'm trying to do.