|
17 | 17 | package org.apache.lucene.codecs.lucene90; |
18 | 18 |
|
19 | 19 | import java.io.IOException; |
| 20 | +import java.util.ArrayList; |
| 21 | +import java.util.Comparator; |
| 22 | +import java.util.List; |
| 23 | + |
20 | 24 | import org.apache.lucene.codecs.CodecUtil; |
21 | 25 | import org.apache.lucene.codecs.CompoundDirectory; |
22 | 26 | import org.apache.lucene.codecs.CompoundFormat; |
@@ -105,29 +109,18 @@ public void write(Directory dir, SegmentInfo si, IOContext context) throws IOExc |
105 | 109 |
|
106 | 110 | private record SizedFile(String name, long length) {} |
107 | 111 |
|
108 | | - private static class SizedFileQueue extends PriorityQueue<SizedFile> { |
109 | | - SizedFileQueue(int maxSize) { |
110 | | - super(maxSize); |
111 | | - } |
112 | | - |
113 | | - @Override |
114 | | - protected boolean lessThan(SizedFile sf1, SizedFile sf2) { |
115 | | - return sf1.length < sf2.length; |
116 | | - } |
117 | | - } |
118 | | - |
119 | 112 | private void writeCompoundFile( |
120 | 113 | IndexOutput entries, IndexOutput data, Directory dir, SegmentInfo si) throws IOException { |
121 | 114 | // write number of files |
122 | 115 | int numFiles = si.files().size(); |
123 | 116 | entries.writeVInt(numFiles); |
124 | 117 | // first put files in ascending size order so small files fit more likely into one page |
125 | | - SizedFileQueue pq = new SizedFileQueue(numFiles); |
| 118 | + List<SizedFile> files = new ArrayList<>(numFiles); |
126 | 119 | for (String filename : si.files()) { |
127 | | - pq.add(new SizedFile(filename, dir.fileLength(filename))); |
| 120 | + files.add(new SizedFile(filename, dir.fileLength(filename))); |
128 | 121 | } |
129 | | - while (pq.size() > 0) { |
130 | | - SizedFile sizedFile = pq.pop(); |
| 122 | + files.sort(Comparator.comparingLong(SizedFile::length)); |
| 123 | + for (SizedFile sizedFile : files) { |
131 | 124 | String file = sizedFile.name; |
132 | 125 | // align file start offset |
133 | 126 | long startOffset = data.alignFilePointer(Long.BYTES); |
|
0 commit comments