src: add IsEmpty() check to HasInstance()

The check has virtually zero overhead and it simplifies the call sites
because they were calling IsEmpty() anwyay.