Backport some enum optimizations from Qt 5

(backport of 108b9bbe2ff2f5f31525408a08d248499d95a49f in qtquick1)

Saving the int when we check the enum is valid allows us to make it a
literal assignment instead of a binding, which is much faster on object
creation.

Change-Id: Ieb174289438a17574c4716df372b04d4dee6d0db
Reviewed-by: Christopher Adams <chris.adams@jollamobile.com>