slightly optimize ArrayList.contains()