avoid string eval in as_base64

There is a string eval repeated in as_base64, which slows down the serialization unnecessarily. Is is only required to do the check once.