Fastest way to check if a WeakRc points at a real object?

I have a Weak<T>. I want to know if it points at a real object or a null. (i.e. get a bool).

The current options seem to be:

  1. strong_count ( rc.rs - source ) > 0

  2. upgrade ( rc.rs - source ) != None

As it turns out, need neither a ptr nor a count. I just want to know if it's null or not. What is the cheapest way to do this (and what is the cost of the cheapest way).

There won't be anything faster than strong_count > 0, since that is what any method would have to do under the hood. I expect the upgrade option would also optimize to this, but haven't done any tests.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.