Optimize the creation of a StableRef

* Thanks @sjrd!