return DocIdSet.EMPTY_DOCIDSET;
} else if (docIdSet.isCacheable()) {
return docIdSet;
} else {
DocIdSetIterator it = docIdSet.iterator();
IntList docIds = new ArrayIntList();
// null is allowed to be returned by iterator(),
// in this case we wrap with the empty set,
// which is cacheable.
if (it == null) {
return DocIdSet.EMPTY_DOCIDSET;
} else {
while (it.nextDoc() != DocIdSetIterator.NO_MORE_DOCS) {
docIds.add(it.docID());
}
return new IntListDocIdSet(docIds);
}
}
}