} else if (docIdSet.isCacheable() && (docIdSet instanceof DocSet)) {
return (DocSet) docIdSet;
} else if (docIdSet instanceof OpenBitSet) {
return new OpenBitDocSet((OpenBitSet) docIdSet);
} else {
final DocIdSetIterator it = docIdSet.iterator();
// null is allowed to be returned by iterator(),
// in this case we wrap with the empty set,
// which is cacheable.
return (it == null) ? DocSet.EMPTY_DOC_SET : new OpenBitDocSet(it, reader.maxDoc());
}