gh-37563: trying a change in unique_representation
namely break the loop over `mro` once found what we want
I am not sure at all that this keeps the expected properties, but this
is more efficient..
### :memo: Checklist
- [x] The title is concise and informative.
- [x] The description explains in detail what this PR is about.
URL: https://github.com/sagemath/sage/pull/37563
Reported by: Frédéric Chapoton
Reviewer(s): Travis Scrimshaw