Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

LUCENE-1899: fix slow realloc performance if you set bits in order in a new OpenBitSet

Michael McCandlessc5c363e54082
diff --git a/CHANGES.txt b/CHANGES.txt
index 818ea1844fd..fe1bbb10741 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -549,6 +549,10 @@ Bug fixes
Because of this IndexReader.isLocked() and IndexWriter.isLocked() did
not work correctly. (Uwe Schindler)
+ * LUCENE-1899: Fix O(N^2) CPU cost when setting docIDs in order in an
+ OpenBitSet, due to an inefficiency in how the underlying storage is
+ reallocated. (Nadav Har'El via Mike McCandless)
+
New features
* LUCENE-1411: Added expert API to open an IndexWriter on a prior
diff --git a/src/java/org/apache/lucene/util/OpenBitSet.java b/src/java/org/apache/lucene/util/OpenBitSet.java
index f3a3f5fad1e..1fc10122c01 100644
--- a/src/java/org/apache/lucene/util/OpenBitSet.java
+++ b/src/java/org/apache/lucene/util/OpenBitSet.java
@@ -483,7 +483,6 @@ public class OpenBitSet extends DocIdSet implements Cloneable, Serializable {
*/
public void flip(long startIndex, long endIndex) {
if (endIndex <= startIndex) return;
- int oldlen = wlen;
int startWord = (int)(startIndex>>6);
// since endIndex is one past the end, this is index of the last
@@ -742,9 +741,7 @@ public class OpenBitSet extends DocIdSet implements Cloneable, Serializable {
*/
public void ensureCapacityWords(int numWords) {
if (bits.length < numWords) {
- long[] newBits = new long[numWords];
- System.arraycopy(bits,0,newBits,0,wlen);
- bits = newBits;
+ bits = ArrayUtil.grow(bits, numWords);
}
}