Apache Lucene open-source search software
LUCENE-3661: removable MutableBits.clone()
Robert Muirb44abb2aaf4d
diff --git a/lucene/src/java/org/apache/lucene/codecs/LiveDocsFormat.java b/lucene/src/java/org/apache/lucene/codecs/LiveDocsFormat.javaindex 3bbb1142697..dffea6c4ffd 100644--- a/lucene/src/java/org/apache/lucene/codecs/LiveDocsFormat.java+++ b/lucene/src/java/org/apache/lucene/codecs/LiveDocsFormat.java@@ -28,6 +28,7 @@ import org.apache.lucene.util.MutableBits;public abstract class LiveDocsFormat {public abstract MutableBits newLiveDocs(int size) throws IOException;+ public abstract MutableBits newLiveDocs(Bits existing) throws IOException;public abstract Bits readLiveDocs(Directory dir, SegmentInfo info, IOContext context) throws IOException;public abstract void writeLiveDocs(MutableBits bits, Directory dir, SegmentInfo info, IOContext context) throws IOException;public abstract void separateFiles(Directory dir, SegmentInfo info, Set<String> files) throws IOException;diff --git a/lucene/src/java/org/apache/lucene/codecs/lucene40/Lucene40LiveDocsFormat.java b/lucene/src/java/org/apache/lucene/codecs/lucene40/Lucene40LiveDocsFormat.javaindex 7ff98b3c9a0..16a6dc3d220 100644--- a/lucene/src/java/org/apache/lucene/codecs/lucene40/Lucene40LiveDocsFormat.java+++ b/lucene/src/java/org/apache/lucene/codecs/lucene40/Lucene40LiveDocsFormat.java@@ -23,6 +23,12 @@ public class Lucene40LiveDocsFormat extends LiveDocsFormat {return bitVector;}+ @Override+ public MutableBits newLiveDocs(Bits existing) throws IOException {+ final BitVector liveDocs = (BitVector) existing;+ return liveDocs.clone();+ }+@Overridepublic Bits readLiveDocs(Directory dir, SegmentInfo info, IOContext context) throws IOException {String filename = IndexFileNames.fileNameFromGeneration(info.name, DELETES_EXTENSION, info.getDelGen());@@ -34,7 +40,6 @@ public class Lucene40LiveDocsFormat extends LiveDocsFormat {@Overridepublic void writeLiveDocs(MutableBits bits, Directory dir, SegmentInfo info, IOContext context) throws IOException {- // nocommit: this api is ugly...String filename = IndexFileNames.fileNameFromGeneration(info.name, DELETES_EXTENSION, info.getDelGen());final BitVector liveDocs = (BitVector) bits;assert liveDocs.count() == info.docCount - info.getDelCount();diff --git a/lucene/src/java/org/apache/lucene/codecs/simpletext/SimpleTextLiveDocsFormat.java b/lucene/src/java/org/apache/lucene/codecs/simpletext/SimpleTextLiveDocsFormat.javaindex 66695d9eb83..f2ae9514974 100644--- a/lucene/src/java/org/apache/lucene/codecs/simpletext/SimpleTextLiveDocsFormat.java+++ b/lucene/src/java/org/apache/lucene/codecs/simpletext/SimpleTextLiveDocsFormat.java@@ -56,6 +56,12 @@ public class SimpleTextLiveDocsFormat extends LiveDocsFormat {return new SimpleTextBits(size);}+ @Override+ public MutableBits newLiveDocs(Bits existing) throws IOException {+ final SimpleTextBits bits = (SimpleTextBits) existing;+ return bits.clone();+ }+@Overridepublic Bits readLiveDocs(Directory dir, SegmentInfo info, IOContext context) throws IOException {assert info.hasDeletions();diff --git a/lucene/src/java/org/apache/lucene/index/IndexWriter.java b/lucene/src/java/org/apache/lucene/index/IndexWriter.javaindex 03debc878f1..fe37827696f 100644--- a/lucene/src/java/org/apache/lucene/index/IndexWriter.java+++ b/lucene/src/java/org/apache/lucene/index/IndexWriter.java@@ -33,6 +33,7 @@ import java.util.concurrent.atomic.AtomicInteger;import org.apache.lucene.analysis.Analyzer;import org.apache.lucene.codecs.Codec;+import org.apache.lucene.codecs.LiveDocsFormat;import org.apache.lucene.index.DocumentsWriterPerThread.FlushedSegment;import org.apache.lucene.index.FieldInfos.FieldNumberBiMap;import org.apache.lucene.index.IndexWriterConfig.OpenMode;@@ -475,7 +476,6 @@ public class IndexWriter implements Closeable, TwoPhaseCommit {if (reader == null) {reader = new SegmentReader(info, config.getReaderTermsIndexDivisor(), context);if (liveDocs == null) {- // nocommit: nuke castliveDocs = (MutableBits) reader.getLiveDocs();}//System.out.println("ADD seg=" + rld.info + " isMerge=" + isMerge + " " + readerMap.size() + " in pool");@@ -565,11 +565,12 @@ public class IndexWriter implements Closeable, TwoPhaseCommit {// SegmentReader sharing the current liveDocs// instance; must now make a private clone so we can// change it:+ LiveDocsFormat liveDocsFormat = info.getCodec().liveDocsFormat();if (liveDocs == null) {//System.out.println("create BV seg=" + info);- liveDocs = info.getCodec().liveDocsFormat().newLiveDocs(info.docCount);+ liveDocs = liveDocsFormat.newLiveDocs(info.docCount);} else {- liveDocs = liveDocs.clone();+ liveDocs = liveDocsFormat.newLiveDocs(liveDocs);}shared = false;} else {diff --git a/lucene/src/java/org/apache/lucene/util/MutableBits.java b/lucene/src/java/org/apache/lucene/util/MutableBits.javaindex 6283be7cc9c..66a69400b6b 100644--- a/lucene/src/java/org/apache/lucene/util/MutableBits.java+++ b/lucene/src/java/org/apache/lucene/util/MutableBits.java@@ -17,7 +17,6 @@ package org.apache.lucene.util;* limitations under the License.*/-public interface MutableBits extends Bits, Cloneable {+public interface MutableBits extends Bits {public void clear(int bit);- public MutableBits clone();}