You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by mi...@apache.org on 2012/07/04 19:48:02 UTC

svn commit: r1357349 - in /lucene/dev/branches/pforcodec_3892/lucene/core/src/java/org/apache/lucene/codecs/pfor: ForFactory.java ForPostingsFormat.java PForFactory.java PForPostingsFormat.java

Author: mikemccand
Date: Wed Jul  4 17:48:02 2012
New Revision: 1357349

URL: http://svn.apache.org/viewvc?rev=1357349&view=rev
Log:
LUCENE-3892: small cleanups to For/PFor postings formats

Modified:
    lucene/dev/branches/pforcodec_3892/lucene/core/src/java/org/apache/lucene/codecs/pfor/ForFactory.java
    lucene/dev/branches/pforcodec_3892/lucene/core/src/java/org/apache/lucene/codecs/pfor/ForPostingsFormat.java
    lucene/dev/branches/pforcodec_3892/lucene/core/src/java/org/apache/lucene/codecs/pfor/PForFactory.java
    lucene/dev/branches/pforcodec_3892/lucene/core/src/java/org/apache/lucene/codecs/pfor/PForPostingsFormat.java

Modified: lucene/dev/branches/pforcodec_3892/lucene/core/src/java/org/apache/lucene/codecs/pfor/ForFactory.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/pforcodec_3892/lucene/core/src/java/org/apache/lucene/codecs/pfor/ForFactory.java?rev=1357349&r1=1357348&r2=1357349&view=diff
==============================================================================
--- lucene/dev/branches/pforcodec_3892/lucene/core/src/java/org/apache/lucene/codecs/pfor/ForFactory.java (original)
+++ lucene/dev/branches/pforcodec_3892/lucene/core/src/java/org/apache/lucene/codecs/pfor/ForFactory.java Wed Jul  4 17:48:02 2012
@@ -40,29 +40,17 @@ public final class ForFactory extends In
   private final int blockSize;
 
   public ForFactory() {
-    this.blockSize=ForPostingsFormat.DEFAULT_BLOCK_SIZE;
+    this.blockSize = ForPostingsFormat.DEFAULT_BLOCK_SIZE;
   }
 
   @Override
   public IntIndexOutput createOutput(Directory dir, String fileName, IOContext context)  throws IOException {
-    IndexOutput out = dir.createOutput(fileName, context);
-    boolean success = false;
-    try {
-      FixedIntBlockIndexOutput ret = new  ForIndexOutput(out, blockSize);
-      success = true;
-      return ret;
-    } finally {
-      if (!success) {
-        // TODO: why handle exception like this? 
-        // and why not use similar codes for read part?
-        IOUtils.closeWhileHandlingException(out);
-      }
-    }
+    return new ForIndexOutput(dir.createOutput(fileName, context), blockSize);
   }
+
   @Override
   public IntIndexInput openInput(Directory dir, String fileName, IOContext context) throws IOException {
-    FixedIntBlockIndexInput ret = new ForIndexInput(dir.openInput(fileName, context));
-    return ret;
+    return new ForIndexInput(dir.openInput(fileName, context));
   }
 
   // wrap input and output with buffer support
@@ -102,13 +90,15 @@ public final class ForFactory extends In
   }
 
   private class ForIndexOutput extends FixedIntBlockIndexOutput {
-      private byte[] encoded;
-      private IntBuffer encodedBuffer;
+    private final byte[] encoded;
+    private final IntBuffer encodedBuffer;
+
     ForIndexOutput(IndexOutput out, int blockSize) throws IOException {
       super(out,blockSize);
       this.encoded = new byte[blockSize*8+4];
       this.encodedBuffer=ByteBuffer.wrap(encoded).asIntBuffer();
     }
+
     @Override
     protected void flushBlock() throws IOException {
       final int numBytes = ForUtil.compress(buffer,buffer.length,encodedBuffer);

Modified: lucene/dev/branches/pforcodec_3892/lucene/core/src/java/org/apache/lucene/codecs/pfor/ForPostingsFormat.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/pforcodec_3892/lucene/core/src/java/org/apache/lucene/codecs/pfor/ForPostingsFormat.java?rev=1357349&r1=1357348&r2=1357349&view=diff
==============================================================================
--- lucene/dev/branches/pforcodec_3892/lucene/core/src/java/org/apache/lucene/codecs/pfor/ForPostingsFormat.java (original)
+++ lucene/dev/branches/pforcodec_3892/lucene/core/src/java/org/apache/lucene/codecs/pfor/ForPostingsFormat.java Wed Jul  4 17:48:02 2012
@@ -46,8 +46,7 @@ public final class ForPostingsFormat ext
   private final int blockSize;
   private final int minBlockSize;
   private final int maxBlockSize;
-  protected final static int DEFAULT_BLOCK_SIZE = 128;
-  protected final static int DEFAULT_TERM_CACHED_SIZE = 1024;
+  public final static int DEFAULT_BLOCK_SIZE = 128;
 
   public ForPostingsFormat() {
     super("For");
@@ -55,6 +54,7 @@ public final class ForPostingsFormat ext
     this.minBlockSize = BlockTreeTermsWriter.DEFAULT_MIN_BLOCK_SIZE;
     this.maxBlockSize = BlockTreeTermsWriter.DEFAULT_MAX_BLOCK_SIZE;
   }
+
   public ForPostingsFormat(int minBlockSize, int maxBlockSize) {
     super("For");
     this.blockSize = DEFAULT_BLOCK_SIZE;

Modified: lucene/dev/branches/pforcodec_3892/lucene/core/src/java/org/apache/lucene/codecs/pfor/PForFactory.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/pforcodec_3892/lucene/core/src/java/org/apache/lucene/codecs/pfor/PForFactory.java?rev=1357349&r1=1357348&r2=1357349&view=diff
==============================================================================
--- lucene/dev/branches/pforcodec_3892/lucene/core/src/java/org/apache/lucene/codecs/pfor/PForFactory.java (original)
+++ lucene/dev/branches/pforcodec_3892/lucene/core/src/java/org/apache/lucene/codecs/pfor/PForFactory.java Wed Jul  4 17:48:02 2012
@@ -45,24 +45,12 @@ public final class PForFactory extends I
 
   @Override
   public IntIndexOutput createOutput(Directory dir, String fileName, IOContext context)  throws IOException {
-    IndexOutput out = dir.createOutput(fileName, context);
-    boolean success = false;
-    try {
-      FixedIntBlockIndexOutput ret = new  PForIndexOutput(out, blockSize);
-      success = true;
-      return ret;
-    } finally {
-      if (!success) {
-        // TODO: why handle exception like this? 
-        // and why not use similar codes for read part?
-        IOUtils.closeWhileHandlingException(out);
-      }
-    }
+    return new PForIndexOutput(dir.createOutput(fileName, context), blockSize);
   }
+
   @Override
   public IntIndexInput openInput(Directory dir, String fileName, IOContext context) throws IOException {
-    FixedIntBlockIndexInput ret = new PForIndexInput(dir.openInput(fileName, context));
-    return ret;
+    return new PForIndexInput(dir.openInput(fileName, context));
   }
 
   // wrap input and output with buffer support
@@ -102,13 +90,15 @@ public final class PForFactory extends I
   }
 
   private class PForIndexOutput extends FixedIntBlockIndexOutput {
-      private byte[] encoded;
-      private IntBuffer encodedBuffer;
+    private final byte[] encoded;
+    private final IntBuffer encodedBuffer;
+
     PForIndexOutput(IndexOutput out, int blockSize) throws IOException {
       super(out,blockSize);
       this.encoded = new byte[blockSize*8+4];
       this.encodedBuffer=ByteBuffer.wrap(encoded).asIntBuffer();
     }
+
     @Override
     protected void flushBlock() throws IOException {
       final int numBytes = PForUtil.compress(buffer,buffer.length,encodedBuffer);

Modified: lucene/dev/branches/pforcodec_3892/lucene/core/src/java/org/apache/lucene/codecs/pfor/PForPostingsFormat.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/pforcodec_3892/lucene/core/src/java/org/apache/lucene/codecs/pfor/PForPostingsFormat.java?rev=1357349&r1=1357348&r2=1357349&view=diff
==============================================================================
--- lucene/dev/branches/pforcodec_3892/lucene/core/src/java/org/apache/lucene/codecs/pfor/PForPostingsFormat.java (original)
+++ lucene/dev/branches/pforcodec_3892/lucene/core/src/java/org/apache/lucene/codecs/pfor/PForPostingsFormat.java Wed Jul  4 17:48:02 2012
@@ -46,8 +46,7 @@ public final class PForPostingsFormat ex
   private final int blockSize;
   private final int minBlockSize;
   private final int maxBlockSize;
-  protected final static int DEFAULT_BLOCK_SIZE = 128;
-  protected final static int DEFAULT_TERM_CACHED_SIZE = 1024;
+  public final static int DEFAULT_BLOCK_SIZE = 128;
 
   public PForPostingsFormat() {
     super("PFor");