From c5c363e54082f3497b4bab5f2d46326d386a3a55 Mon Sep 17 00:00:00 2001 From: Michael McCandless Date: Wed, 9 Sep 2009 11:51:41 +0000 Subject: [PATCH] LUCENE-1899: fix slow realloc performance if you set bits in order in a new OpenBitSet git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@812904 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES.txt | 4 ++++ src/java/org/apache/lucene/util/OpenBitSet.java | 5 +---- 2 files changed, 5 insertions(+), 4 deletions(-) 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); } }