Hacker News new | ask | show | jobs
by codedokode 296 days ago
But it is expensive, because it does run-time checks? Or they are optimized out?
1 comments

RefCell does do runtime checks, but the cost is checking the counter, a conditional branch, then incrementing/decrementing the counter twice.

Because the counter is non-atomic and non-volatile the optimiser can sometimes optimise out the actual modification of the counter. It's not free, but it's not also not a huge expense.