[hg] main-silver: #225021:Long time spent in the LuceneIndex._st...

  • From: Tomas Zezula < >
  • To:
  • Subject: [hg] main-silver: #225021:Long time spent in the LuceneIndex._st...
  • Date: Thu, 17 Jan 2013 10:38:14 -0800

changeset 467a8519ac68 in main-silver ((none))
details: http://hg.netbeans.org/main-silver/rev/467a8519ac68
description:
        #225021:Long time spent in the LuceneIndex._store() by method 
removing the used data.

diffstat:

 parsing.lucene/src/org/netbeans/modules/parsing/lucene/LuceneIndex.java |  
33 +++++++++-
 1 files changed, 32 insertions(+), 1 deletions(-)

diffs (71 lines):

diff --git 
a/parsing.lucene/src/org/netbeans/modules/parsing/lucene/LuceneIndex.java 
b/parsing.lucene/src/org/netbeans/modules/parsing/lucene/LuceneIndex.java
--- a/parsing.lucene/src/org/netbeans/modules/parsing/lucene/LuceneIndex.java
+++ b/parsing.lucene/src/org/netbeans/modules/parsing/lucene/LuceneIndex.java
@@ -51,6 +51,7 @@
 import java.lang.ref.SoftReference;
 import java.net.MalformedURLException;
 import java.net.URL;
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.BitSet;
 import java.util.Collection;
@@ -59,6 +60,7 @@
 import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
+import java.util.ListIterator;
 import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.ExecutionException;
@@ -441,7 +443,7 @@
                         Version.LUCENE_35,
                         dirCache.getAnalyzer()));
             }
-            for (Iterator<T> it = data.iterator(); it.hasNext();) {
+            for (Iterator<T> it = fastRemoveIterable(data).iterator(); 
it.hasNext();) {
                 T entry = it.next();
                 it.remove();
                 final Document doc = docConvertor.convert(entry);
@@ -457,6 +459,7 @@
                             dirCache.getAnalyzer()));
                 }
             }
+            data.clear();
             if (memDir != null) {
                 activeOut.close();
                 out.addIndexes(memDir);
@@ -539,6 +542,34 @@
         return DEFAULT_CACHE_POLICY;
     }
     
+    private static <T> Iterable<T> fastRemoveIterable(final Collection<T> c) 
{
+        return c instanceof ArrayList ?
+                new Iterable<T>() {
+                    @Override
+                    public Iterator<T> iterator() {
+                        return new Iterator<T>() {
+                            private final ListIterator<T> delegate = 
((List)c).listIterator();
+
+                            @Override
+                            public boolean hasNext() {
+                                return delegate.hasNext();
+                            }
+
+                            @Override
+                            public T next() {
+                                return delegate.next();
+                            }
+
+                            @Override
+                            public void remove() {
+                                delegate.set(null);
+                            }
+                        };
+                    }
+                } :
+                c;
+    }
+    
 
     //<editor-fold defaultstate="collapsed" desc="Private classes 
(NoNormsReader, TermComparator, CachePolicy)">
         

[hg] main-silver: #225021:Long time spent in the LuceneIndex._st...

Tomas Zezula 01/17/2013

Project Features

About this Project

Editor was started in November 2009, is owned by Martin Ryzl, and has 147 members.
By use of this website, you agree to the NetBeans Policies and Terms of Use (revision 20140418.2d69abc). © 2013, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo
 
 
Close
loading
Please Confirm
Close