lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From yo...@apache.org
Subject svn commit: r950207 - in /lucene/dev/trunk/solr/src/java/org/apache/solr/response: TextResponseWriter.java XMLWriter.java
Date Tue, 01 Jun 2010 19:06:17 GMT
Author: yonik
Date: Tue Jun  1 19:06:17 2010
New Revision: 950207

URL: http://svn.apache.org/viewvc?rev=950207&view=rev
Log:
SOLR-1933: 2 space indenting for responses

Modified:
    lucene/dev/trunk/solr/src/java/org/apache/solr/response/TextResponseWriter.java
    lucene/dev/trunk/solr/src/java/org/apache/solr/response/XMLWriter.java

Modified: lucene/dev/trunk/solr/src/java/org/apache/solr/response/TextResponseWriter.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/java/org/apache/solr/response/TextResponseWriter.java?rev=950207&r1=950206&r2=950207&view=diff
==============================================================================
--- lucene/dev/trunk/solr/src/java/org/apache/solr/response/TextResponseWriter.java (original)
+++ lucene/dev/trunk/solr/src/java/org/apache/solr/response/TextResponseWriter.java Tue Jun
 1 19:06:17 2010
@@ -71,28 +71,16 @@ public abstract class TextResponseWriter
   /** returns the Writer that the response is being written to */
   public Writer getWriter() { return writer; }
 
-  // use a combination of tabs and spaces to minimize the size of an indented response.
-  private static final String[] indentArr = new String[] {
-    "\n",
-    "\n ",
-    "\n  ",
-    "\n\t",
-    "\n\t ",
-    "\n\t  ",  // could skip this one (the only 3 char seq)
-    "\n\t\t",
-    "\n\t\t "};
 
   public void indent() throws IOException {
      if (doIndent) indent(level);
   }
 
   public void indent(int lev) throws IOException {
-    int arrsz = indentArr.length-1;
-    // power-of-two intent array (gratuitous optimization :-)
-    String istr = indentArr[lev & (indentArr.length-1)];
-    writer.write(istr);
+    writer.write(XMLWriter.indentChars, 0, Math.min((lev<<1)+1, XMLWriter.indentChars.length));
   }
 
+
   //
   // Functions to manipulate the current logical nesting level.
   // Any indentation will be partially based on level.

Modified: lucene/dev/trunk/solr/src/java/org/apache/solr/response/XMLWriter.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/java/org/apache/solr/response/XMLWriter.java?rev=950207&r1=950206&r2=950207&view=diff
==============================================================================
--- lucene/dev/trunk/solr/src/java/org/apache/solr/response/XMLWriter.java (original)
+++ lucene/dev/trunk/solr/src/java/org/apache/solr/response/XMLWriter.java Tue Jun  1 19:06:17
2010
@@ -283,24 +283,20 @@ final public class XMLWriter {
     }
   }
 
-  private static final String[] indentArr = new String[] {
-    "\n",
-    "\n ",
-    "\n  ",
-    "\n\t",
-    "\n\t ",
-    "\n\t  ",  // could skip this one (the only 3 char seq)
-    "\n\t\t" };
+
+  // indent up to 40 spaces
+  static final char[] indentChars = new char[81];
+  static {
+    Arrays.fill(indentChars,' ');
+    indentChars[0] = '\n';  // start with a newline
+  }
 
   public void indent() throws IOException {
      indent(level);
   }
 
   public void indent(int lev) throws IOException {
-    int arrsz = indentArr.length-1;
-    // another option would be lev % arrsz (wrap around)
-    String istr = indentArr[ lev > arrsz ? arrsz : lev ];
-    writer.write(istr);
+    writer.write(indentChars, 0, Math.min((lev<<1)+1, indentChars.length));
   }
 
   private static final Comparator fieldnameComparator = new Comparator() {



Mime
View raw message