jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r691313 - in /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core: nodetype/NodeTypeDefDiff.java query/lucene/MoreLikeThis.java query/lucene/MultiIndex.java
Date Tue, 02 Sep 2008 16:40:31 GMT
Author: jukka
Date: Tue Sep  2 09:40:30 2008
New Revision: 691313

URL: http://svn.apache.org/viewvc?rev=691313&view=rev
Log:
JCR-1445: [PATCH] Use entrySet iterators to avoid map look ups in loops

Applied patch by Dave Brosius.

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeDefDiff.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MoreLikeThis.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MultiIndex.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeDefDiff.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeDefDiff.java?rev=691313&r1=691312&r2=691313&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeDefDiff.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeDefDiff.java
Tue Sep  2 09:40:30 2008
@@ -16,13 +16,15 @@
  */
 package org.apache.jackrabbit.core.nodetype;
 
-import javax.jcr.PropertyType;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
+
+import javax.jcr.PropertyType;
 
 /**
  * A <code>NodeTypeDefDiff</code> represents the result of the comparison of
@@ -247,10 +249,11 @@
          * walk through defs1 and process all entries found in
          * both defs1 & defs2 and those found only in defs1
          */
-        Iterator iter = defs1.keySet().iterator();
+        Iterator iter = defs1.entrySet().iterator();
         while (iter.hasNext()) {
-            PropDefId id = (PropDefId) iter.next();
-            PropDef def1 = (PropDef) defs1.get(id);
+            Map.Entry entry = (Map.Entry) iter.next();
+            PropDefId id = (PropDefId) entry.getKey();
+            PropDef def1 = (PropDef) entry.getValue();
             PropDef def2 = (PropDef) defs2.get(id);
             PropDefDiff diff = new PropDefDiff(def1, def2);
             if (diff.getType() > maxType) {
@@ -264,10 +267,11 @@
          * defs2 by now only contains entries found in defs2 only;
          * walk through defs2 and process all remaining entries
          */
-        iter = defs2.keySet().iterator();
+        iter = defs2.entrySet().iterator();
         while (iter.hasNext()) {
-            PropDefId id = (PropDefId) iter.next();
-            PropDef def = (PropDef) defs2.get(id);
+            Map.Entry entry = (Map.Entry) iter.next();
+            PropDefId id = (PropDefId) entry.getKey();
+            PropDef def = (PropDef) entry.getValue();
             PropDefDiff diff = new PropDefDiff(null, def);
             if (diff.getType() > maxType) {
                 maxType = diff.getType();
@@ -304,10 +308,11 @@
          * walk through defs1 and process all entries found in
          * both defs1 & defs2 and those found only in defs1
          */
-        Iterator iter = defs1.keySet().iterator();
+        Iterator iter = defs1.entrySet().iterator();
         while (iter.hasNext()) {
-            NodeDefId id = (NodeDefId) iter.next();
-            NodeDef def1 = (NodeDef) defs1.get(id);
+            Map.Entry entry = (Map.Entry) iter.next();
+            NodeDefId id = (NodeDefId) entry.getKey();
+            NodeDef def1 = (NodeDef) entry.getValue();
             NodeDef def2 = (NodeDef) defs2.get(id);
             ChildNodeDefDiff diff = new ChildNodeDefDiff(def1, def2);
             if (diff.getType() > maxType) {
@@ -321,10 +326,11 @@
          * defs2 by now only contains entries found in defs2 only;
          * walk through defs2 and process all remaining entries
          */
-        iter = defs2.keySet().iterator();
+        iter = defs2.entrySet().iterator();
         while (iter.hasNext()) {
-            NodeDefId id = (NodeDefId) iter.next();
-            NodeDef def = (NodeDef) defs2.get(id);
+            Map.Entry entry = (Map.Entry) iter.next();
+            NodeDefId id = (NodeDefId) entry.getKey();
+            NodeDef def = (NodeDef) entry.getValue();
             ChildNodeDefDiff diff = new ChildNodeDefDiff(null, def);
             if (diff.getType() > maxType) {
                 maxType = diff.getType();

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MoreLikeThis.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MoreLikeThis.java?rev=691313&r1=691312&r2=691313&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MoreLikeThis.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MoreLikeThis.java
Tue Sep  2 09:40:30 2008
@@ -595,11 +595,12 @@
         int numDocs = ir.numDocs();
         FreqQ res = new FreqQ(words.size()); // will order words by score
 
-        Iterator it = words.keySet().iterator();
+        Iterator it = words.entrySet().iterator();
         while (it.hasNext()) { // for every word
-            String word = (String) it.next();
+            Map.Entry entry = (Map.Entry) it.next();
+            String word = (String) entry.getKey();
 
-            int tf = ((Int) words.get(word)).x; // term freq in the source doc
+            int tf = ((Int) entry.getValue()).x; // term freq in the source doc
             if (minTermFreq > 0 && tf < minTermFreq) {
                 continue; // filter out words that don't occur enough times in the source
             }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MultiIndex.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MultiIndex.java?rev=691313&r1=691312&r2=691313&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MultiIndex.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MultiIndex.java
Tue Sep  2 09:40:30 2008
@@ -539,14 +539,15 @@
             }
         } catch (IOException e) {
             // close readers obtained so far
-            for (Iterator it = indexReaders.keySet().iterator(); it.hasNext();) {
-                ReadOnlyIndexReader reader = (ReadOnlyIndexReader) it.next();
+            for (Iterator it = indexReaders.entrySet().iterator(); it.hasNext();) {
+                Map.Entry entry = (Map.Entry) it.next();
+                ReadOnlyIndexReader reader = (ReadOnlyIndexReader) entry.getKey();
                 try {
                     reader.close();
                 } catch (IOException ex) {
                     log.warn("Exception closing index reader: " + ex);
                 }
-                ((PersistentIndex) indexReaders.get(reader)).resetListener();
+                ((PersistentIndex) entry.getValue()).resetListener();
             }
             throw e;
         }



Mime
View raw message