setVariable and readVariable currently construct a name string looking like this:
{http://www.example.com}foo
They use this as the key into a hash map to set/get the variable value.
At runtime the XPath processor has a QName object.
We do this expensive conversion of this QName into the above string form before reaching into the hash map.
There is no reason for this. The key to the hash map should just be the QName object itself. setVariable should construct this QName object statically.
Comparison of QNames has to be real equality. Unless QNames are interned I am pretty sure we can't get away with object identity (aka compare the pointers).
But even if we have to compare the parts of a QName that's very preferable to constructing an expanded name string first, and then comparing it.