From 81d22a27bacf7ff6baca79777ebc12253a170399 Mon Sep 17 00:00:00 2001 From: Michael McCandless Date: Wed, 31 Aug 2011 11:59:30 +0000 Subject: [PATCH] LUCENE-3409: don't use Iterator.remove git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1163589 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/lucene/index/IndexWriter.java | 23 ++++++------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/lucene/src/java/org/apache/lucene/index/IndexWriter.java b/lucene/src/java/org/apache/lucene/index/IndexWriter.java index a19c7c44233..4e3c16afd1e 100644 --- a/lucene/src/java/org/apache/lucene/index/IndexWriter.java +++ b/lucene/src/java/org/apache/lucene/index/IndexWriter.java @@ -27,7 +27,6 @@ import java.util.Comparator; import java.util.Date; import java.util.HashMap; import java.util.HashSet; -import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -601,20 +600,15 @@ public class IndexWriter implements Closeable, TwoPhaseCommit { } public synchronized void dropAll() throws IOException { - Iterator> iter = readerMap.entrySet().iterator(); - while (iter.hasNext()) { - - final Map.Entry ent = iter.next(); - - SegmentReader sr = ent.getValue(); - sr.hasChanges = false; - iter.remove(); + for(SegmentReader reader : readerMap.values()) { + reader.hasChanges = false; // NOTE: it is allowed that this decRef does not // actually close the SR; this can happen when a // near real-time reader using this SR is still open - sr.decRef(); + reader.decRef(); } + readerMap.clear(); } public synchronized void drop(SegmentInfo info, IOContext.Context context) throws IOException { @@ -633,10 +627,7 @@ public class IndexWriter implements Closeable, TwoPhaseCommit { // sync'd on IW: assert Thread.holdsLock(IndexWriter.this); - Iterator> iter = readerMap.entrySet().iterator(); - while (iter.hasNext()) { - - Map.Entry ent = iter.next(); + for(Map.Entry ent : readerMap.entrySet()) { SegmentReader sr = ent.getValue(); if (sr.hasChanges) { @@ -649,14 +640,14 @@ public class IndexWriter implements Closeable, TwoPhaseCommit { deleter.checkpoint(segmentInfos, false); } - iter.remove(); - // NOTE: it is allowed that this decRef does not // actually close the SR; this can happen when a // near real-time reader is kept open after the // IndexWriter instance is closed sr.decRef(); } + + readerMap.clear(); } /**