6 ms·
It's cute but if you used this in an innerloop (like a game, simulation or graphics code where 'clamp' is used often), it'll generate a ton of garbage as well
by seanwilson 6y ago
It's cute but if you used this in an innerloop (like a game, simulation or graphics code where 'clamp' is used often), it'll generate a ton of garbage as well as potential slowdown for no good reason.
- tobr 6y agoThis should be completely obvious, but largely irrelevant to the topic at hand. The linked tweet talks about how difficult it is to remember the order of the terms when you implement clamp a certain way; I just wanted to point out that with a different solution, the order surprisingly doesn’t matter at all.
- seanwilson 6y agoI don't think it's obvious though - many people have never optimised for garbage collection so I thought it was worth pointing out. I still found your approach interesting and it's rare there's a perfect approach so don't take it to heart.