[GridFunctionSpace] Avoid unnecessary shared_ptr attachment and detachment in GFS::ordering()

Attaching / detaching a shared_ptr is an expensive operation, so only do it if it's
really necessary.