diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt index 144a7a18403..5f69675962e 100644 --- a/lucene/CHANGES.txt +++ b/lucene/CHANGES.txt @@ -183,6 +183,9 @@ Optimizations * LUCENE-6878: Speed up TopDocs.merge. (Daniel Jelinski via Adrien Grand) +* LUCENE-6885: StandardDirectoryReader (initialCapacity) tweaks + (Christine Poerschke) + Bug Fixes * LUCENE-6817: ComplexPhraseQueryParser.ComplexPhraseQuery does not display diff --git a/lucene/core/src/java/org/apache/lucene/index/StandardDirectoryReader.java b/lucene/core/src/java/org/apache/lucene/index/StandardDirectoryReader.java index 373dad3f227..8d51532aa22 100644 --- a/lucene/core/src/java/org/apache/lucene/index/StandardDirectoryReader.java +++ b/lucene/core/src/java/org/apache/lucene/index/StandardDirectoryReader.java @@ -80,7 +80,7 @@ final class StandardDirectoryReader extends DirectoryReader { // no need to process segments in reverse order final int numSegments = infos.size(); - List readers = new ArrayList<>(); + final List readers = new ArrayList<>(numSegments); final Directory dir = writer.getDirectory(); final SegmentInfos segmentInfos = infos.clone(); @@ -136,7 +136,7 @@ final class StandardDirectoryReader extends DirectoryReader { // we put the old SegmentReaders in a map, that allows us // to lookup a reader using its segment name - final Map segmentReaders = new HashMap<>(); + final Map segmentReaders = (oldReaders == null ? Collections.emptyMap() : new HashMap<>(oldReaders.size())); if (oldReaders != null) { // create a Map SegmentName->SegmentReader