Improve FiniteSet._contains

fixes #8197
fixes #8209