Handle the case const __shared_ptr.

And minor performance tweak.