jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alexparvule...@apache.org
Subject svn commit: r1445602 - in /jackrabbit/branches/2.4: ./ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SharedFieldCache.java
Date Wed, 13 Feb 2013 13:51:26 GMT
Author: alexparvulescu
Date: Wed Feb 13 13:51:26 2013
New Revision: 1445602

URL: http://svn.apache.org/r1445602
Log:
JCR-3450 Reduce memory usage of SharedFieldCache.ValueIndex - backport to 2.4

Modified:
    jackrabbit/branches/2.4/   (props changed)
    jackrabbit/branches/2.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SharedFieldCache.java

Propchange: jackrabbit/branches/2.4/
------------------------------------------------------------------------------
  Merged /jackrabbit/trunk:r1400843

Modified: jackrabbit/branches/2.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SharedFieldCache.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SharedFieldCache.java?rev=1445602&r1=1445601&r2=1445602&view=diff
==============================================================================
--- jackrabbit/branches/2.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SharedFieldCache.java
(original)
+++ jackrabbit/branches/2.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SharedFieldCache.java
Wed Feb 13 13:51:26 2013
@@ -228,7 +228,9 @@ public class SharedFieldCache {
         ValueIndex ret = lookup(reader, field, prefix);
         if (ret == null) {
             final int maxDocs = reader.maxDoc();
-            ComparableArray[] retArray = new ComparableArray[maxDocs];
+            Comparable<?>[] retArray = new Comparable<?>[maxDocs];
+            Map<Integer, Integer> positions = new HashMap<Integer, Integer>();
+            boolean usingSimpleComparable = true;
             int setValues = 0;
             if (maxDocs > 0) {
                 IndexFormatVersion version = IndexFormatVersion.getVersion(reader);
@@ -268,11 +270,34 @@ public class SharedFieldCache {
                             setValues++;
                             Comparable<?> v = getValue(value, type);
                             int doc = termDocs.doc();
-                            ComparableArray ca = retArray[doc];
+                            Comparable<?> ca = retArray[doc];
                             if (ca == null) {
-                                retArray[doc] = new ComparableArray(v, termPosition);
+                                if (usingSimpleComparable) {
+                                    // put simple value on the queue
+                                    positions.put(doc, termPosition);
+                                    retArray[doc] = v;
+                                } else {
+                                    retArray[doc] = new ComparableArray(v,
+                                            termPosition);
+                                }
                             } else {
-                                retArray[doc] = ca.insert(v, termPosition);
+                                if (ca instanceof ComparableArray) {
+                                    ((ComparableArray) ca).insert(v,
+                                            termPosition);
+                                } else {
+                                    // transform all of the existing values from
+                                    // Comparable to ComparableArray
+                                    for (int pos : positions.keySet()) {
+                                        retArray[pos] = new ComparableArray(
+                                                retArray[pos],
+                                                positions.get(pos));
+                                    }
+                                    positions = null;
+                                    usingSimpleComparable = false;
+                                    ComparableArray caNew = (ComparableArray) retArray[doc];
+                                    retArray[doc] = caNew.insert(v,
+                                            termPosition);
+                                }
                             }
                         }
                     } while (termEnum.next());



Mime
View raw message