You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by jp...@apache.org on 2014/08/13 11:36:59 UTC

svn commit: r1617695 [8/9] - in /lucene/dev/branches/branch_4x: ./ lucene/ lucene/analysis/ lucene/analysis/common/src/java/org/apache/lucene/analysis/charfilter/ lucene/analysis/common/src/java/org/apache/lucene/analysis/hunspell/ lucene/analysis/comm...

Modified: lucene/dev/branches/branch_4x/lucene/suggest/src/test/org/apache/lucene/search/suggest/analyzing/FuzzySuggesterTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/suggest/src/test/org/apache/lucene/search/suggest/analyzing/FuzzySuggesterTest.java?rev=1617695&r1=1617694&r2=1617695&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/suggest/src/test/org/apache/lucene/search/suggest/analyzing/FuzzySuggesterTest.java (original)
+++ lucene/dev/branches/branch_4x/lucene/suggest/src/test/org/apache/lucene/search/suggest/analyzing/FuzzySuggesterTest.java Wed Aug 13 09:36:54 2014
@@ -44,6 +44,7 @@ import org.apache.lucene.search.suggest.
 import org.apache.lucene.search.suggest.InputArrayIterator;
 import org.apache.lucene.search.suggest.Lookup.LookupResult;
 import org.apache.lucene.util.BytesRef;
+import org.apache.lucene.util.BytesRefBuilder;
 import org.apache.lucene.util.IntsRef;
 import org.apache.lucene.util.LuceneTestCase;
 import org.apache.lucene.util.TestUtil;
@@ -755,10 +756,10 @@ public class FuzzySuggesterTest extends 
       assertTrue(automaton.isDeterministic());
 
       // TODO: could be faster... but its slowCompletor for a reason
-      BytesRef spare = new BytesRef();
+      BytesRefBuilder spare = new BytesRefBuilder();
       for (TermFreqPayload2 e : slowCompletor) {
         spare.copyChars(e.analyzedForm);
-        Set<IntsRef> finiteStrings = suggester.toFiniteStrings(spare, tokenStreamToAutomaton);
+        Set<IntsRef> finiteStrings = suggester.toFiniteStrings(spare.get(), tokenStreamToAutomaton);
         for (IntsRef intsRef : finiteStrings) {
           int p = 0;
           BytesRef ref = Util.toBytesRef(intsRef, spare);

Modified: lucene/dev/branches/branch_4x/lucene/suggest/src/test/org/apache/lucene/search/suggest/fst/LargeInputFST.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/suggest/src/test/org/apache/lucene/search/suggest/fst/LargeInputFST.java?rev=1617695&r1=1617694&r2=1617695&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/suggest/src/test/org/apache/lucene/search/suggest/fst/LargeInputFST.java (original)
+++ lucene/dev/branches/branch_4x/lucene/suggest/src/test/org/apache/lucene/search/suggest/fst/LargeInputFST.java Wed Aug 13 09:36:54 2014
@@ -26,6 +26,7 @@ import java.io.InputStreamReader;
 import java.nio.charset.StandardCharsets;
 
 import org.apache.lucene.util.BytesRef;
+import org.apache.lucene.util.BytesRefBuilder;
 import org.apache.lucene.util.OfflineSorter;
 
 /**
@@ -46,12 +47,12 @@ public class LargeInputFST {
         new InputStreamReader(
             new FileInputStream(input), StandardCharsets.UTF_8));
     
-    BytesRef scratch = new BytesRef();
+    BytesRefBuilder scratch = new BytesRefBuilder();
     String line;
     int count = 0;
     while ((line = reader.readLine()) != null) {
       scratch.copyChars(line);
-      builder.add(scratch, count % buckets);
+      builder.add(scratch.get(), count % buckets);
       if ((count++ % 100000) == 0) {
         System.err.println("Line: " + count);
       }

Modified: lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/analysis/CannedBinaryTokenStream.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/analysis/CannedBinaryTokenStream.java?rev=1617695&r1=1617694&r2=1617695&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/analysis/CannedBinaryTokenStream.java (original)
+++ lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/analysis/CannedBinaryTokenStream.java Wed Aug 13 09:36:54 2014
@@ -23,6 +23,7 @@ import org.apache.lucene.analysis.tokena
 import org.apache.lucene.analysis.tokenattributes.TermToBytesRefAttribute;
 import org.apache.lucene.util.AttributeImpl;
 import org.apache.lucene.util.BytesRef;
+import org.apache.lucene.util.BytesRefBuilder;
 
 /**
  * TokenStream from a canned list of binary (BytesRef-based)
@@ -69,16 +70,16 @@ public final class CannedBinaryTokenStre
 
   /** Implementation for {@link BinaryTermAttribute}. */
   public final static class BinaryTermAttributeImpl extends AttributeImpl implements BinaryTermAttribute, TermToBytesRefAttribute {
-    private final BytesRef bytes = new BytesRef();
+    private final BytesRefBuilder bytes = new BytesRefBuilder();
 
     @Override
     public void fillBytesRef() {
-      // no-op: we already filled externally during owner's incrementToken
+      bytes.get(); // sets the length on the bytesref
     }
       
     @Override
     public BytesRef getBytesRef() {
-      return bytes;
+      return bytes.get();
     }
 
     @Override

Modified: lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/codecs/lucene3x/PreFlexRWTermVectorsWriter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/codecs/lucene3x/PreFlexRWTermVectorsWriter.java?rev=1617695&r1=1617694&r2=1617695&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/codecs/lucene3x/PreFlexRWTermVectorsWriter.java (original)
+++ lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/codecs/lucene3x/PreFlexRWTermVectorsWriter.java Wed Aug 13 09:36:54 2014
@@ -30,6 +30,7 @@ import org.apache.lucene.store.IOContext
 import org.apache.lucene.store.IndexOutput;
 import org.apache.lucene.util.ArrayUtil;
 import org.apache.lucene.util.BytesRef;
+import org.apache.lucene.util.BytesRefBuilder;
 import org.apache.lucene.util.IOUtils;
 import org.apache.lucene.util.StringHelper;
 
@@ -83,7 +84,7 @@ final class PreFlexRWTermVectorsWriter e
     }
     this.positions = positions;
     this.offsets = offsets;
-    lastTerm.length = 0;
+    lastTerm.clear();
     fps[fieldCount++] = tvf.getFilePointer();
     tvd.writeVInt(info.number);
     tvf.writeVInt(numTerms);
@@ -104,7 +105,7 @@ final class PreFlexRWTermVectorsWriter e
     }
   }
   
-  private final BytesRef lastTerm = new BytesRef(10);
+  private final BytesRefBuilder lastTerm = new BytesRefBuilder();
 
   // NOTE: we override addProx, so we don't need to buffer when indexing.
   // we also don't buffer during bulk merges.
@@ -117,7 +118,7 @@ final class PreFlexRWTermVectorsWriter e
 
   @Override
   public void startTerm(BytesRef term, int freq) throws IOException {
-    final int prefix = StringHelper.bytesDifference(lastTerm, term);
+    final int prefix = StringHelper.bytesDifference(lastTerm.get(), term);
     final int suffix = term.length - prefix;
     tvf.writeVInt(prefix);
     tvf.writeVInt(suffix);

Modified: lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/codecs/lucene3x/TermInfosWriter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/codecs/lucene3x/TermInfosWriter.java?rev=1617695&r1=1617694&r2=1617695&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/codecs/lucene3x/TermInfosWriter.java (original)
+++ lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/codecs/lucene3x/TermInfosWriter.java Wed Aug 13 09:36:54 2014
@@ -29,7 +29,9 @@ import org.apache.lucene.store.Directory
 import org.apache.lucene.store.IOContext;
 import org.apache.lucene.store.IndexOutput;
 import org.apache.lucene.util.BytesRef;
+import org.apache.lucene.util.BytesRefBuilder;
 import org.apache.lucene.util.CharsRef;
+import org.apache.lucene.util.CharsRefBuilder;
 import org.apache.lucene.util.IOUtils;
 import org.apache.lucene.util.UnicodeUtil;
 
@@ -81,7 +83,7 @@ final class TermInfosWriter implements C
 
   private long lastIndexPointer;
   private boolean isIndex;
-  private final BytesRef lastTerm = new BytesRef();
+  private final BytesRefBuilder lastTerm = new BytesRefBuilder();
   private int lastFieldNumber = -1;
 
   private TermInfosWriter other;
@@ -146,14 +148,14 @@ final class TermInfosWriter implements C
   }
 
   // Currently used only by assert statements
-  CharsRef utf16Result1;
-  CharsRef utf16Result2;
-  private final BytesRef scratchBytes = new BytesRef();
+  CharsRefBuilder utf16Result1;
+  CharsRefBuilder utf16Result2;
+  private final BytesRefBuilder scratchBytes = new BytesRefBuilder();
 
   // Currently used only by assert statements
   private boolean initUTF16Results() {
-    utf16Result1 = new CharsRef(10);
-    utf16Result2 = new CharsRef(10);
+    utf16Result1 = new CharsRefBuilder();
+    utf16Result2 = new CharsRefBuilder();
     return true;
   }
   
@@ -180,30 +182,28 @@ final class TermInfosWriter implements C
     }
 
     scratchBytes.copyBytes(term);
-    assert lastTerm.offset == 0;
-    UnicodeUtil.UTF8toUTF16(lastTerm.bytes, 0, lastTerm.length, utf16Result1);
+    utf16Result1.copyUTF8Bytes(lastTerm.get());
 
-    assert scratchBytes.offset == 0;
-    UnicodeUtil.UTF8toUTF16(scratchBytes.bytes, 0, scratchBytes.length, utf16Result2);
+    utf16Result2.copyUTF8Bytes(scratchBytes.get());
 
     final int len;
-    if (utf16Result1.length < utf16Result2.length)
-      len = utf16Result1.length;
+    if (utf16Result1.length() < utf16Result2.length())
+      len = utf16Result1.length();
     else
-      len = utf16Result2.length;
+      len = utf16Result2.length();
 
     for(int i=0;i<len;i++) {
-      final char ch1 = utf16Result1.chars[i];
-      final char ch2 = utf16Result2.chars[i];
+      final char ch1 = utf16Result1.charAt(i);
+      final char ch2 = utf16Result2.charAt(i);
       if (ch1 != ch2)
         return ch1-ch2;
     }
-    if (utf16Result1.length == 0 && lastFieldNumber == -1) {
+    if (utf16Result1.length() == 0 && lastFieldNumber == -1) {
       // If there is a field named "" (empty string) with a term text of "" (empty string) then we
       // will get 0 on this comparison, yet, it's "OK". 
       return -1;
     }
-    return utf16Result1.length - utf16Result2.length;
+    return utf16Result1.length() - utf16Result2.length();
   }
 
   /** Adds a new <<fieldNumber, termBytes>, TermInfo> pair to the set.
@@ -213,16 +213,16 @@ final class TermInfosWriter implements C
     throws IOException {
 
     assert compareToLastTerm(fieldNumber, term) < 0 ||
-      (isIndex && term.length == 0 && lastTerm.length == 0) :
+      (isIndex && term.length == 0 && lastTerm.length() == 0) :
       "Terms are out of order: field=" + fieldName(fieldInfos, fieldNumber) + " (number " + fieldNumber + ")" +
         " lastField=" + fieldName(fieldInfos, lastFieldNumber) + " (number " + lastFieldNumber + ")" +
-        " text=" + term.utf8ToString() + " lastText=" + lastTerm.utf8ToString();
+        " text=" + term.utf8ToString() + " lastText=" + lastTerm.get().utf8ToString();
 
     assert ti.freqPointer >= lastTi.freqPointer: "freqPointer out of order (" + ti.freqPointer + " < " + lastTi.freqPointer + ")";
     assert ti.proxPointer >= lastTi.proxPointer: "proxPointer out of order (" + ti.proxPointer + " < " + lastTi.proxPointer + ")";
 
     if (!isIndex && size % indexInterval == 0) {
-      other.add(lastFieldNumber, lastTerm, lastTi);                      // add an index term
+      other.add(lastFieldNumber, lastTerm.get(), lastTi);                      // add an index term
     }
     writeTerm(fieldNumber, term);                        // write term
 
@@ -252,9 +252,9 @@ final class TermInfosWriter implements C
     // TODO: UTF16toUTF8 could tell us this prefix
     // Compute prefix in common with last term:
     int start = 0;
-    final int limit = term.length < lastTerm.length ? term.length : lastTerm.length;
+    final int limit = term.length < lastTerm.length() ? term.length : lastTerm.length();
     while(start < limit) {
-      if (term.bytes[start+term.offset] != lastTerm.bytes[start+lastTerm.offset])
+      if (term.bytes[start+term.offset] != lastTerm.byteAt(start))
         break;
       start++;
     }

Modified: lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/codecs/lucene42/Lucene42DocValuesConsumer.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/codecs/lucene42/Lucene42DocValuesConsumer.java?rev=1617695&r1=1617694&r2=1617695&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/codecs/lucene42/Lucene42DocValuesConsumer.java (original)
+++ lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/codecs/lucene42/Lucene42DocValuesConsumer.java Wed Aug 13 09:36:54 2014
@@ -35,6 +35,7 @@ import org.apache.lucene.util.ArrayUtil;
 import org.apache.lucene.util.BytesRef;
 import org.apache.lucene.util.IOUtils;
 import org.apache.lucene.util.IntsRef;
+import org.apache.lucene.util.IntsRefBuilder;
 import org.apache.lucene.util.MathUtil;
 import org.apache.lucene.util.fst.Builder;
 import org.apache.lucene.util.fst.FST.INPUT_TYPE;
@@ -254,7 +255,7 @@ class Lucene42DocValuesConsumer extends 
     meta.writeLong(data.getFilePointer());
     PositiveIntOutputs outputs = PositiveIntOutputs.getSingleton();
     Builder<Long> builder = new Builder<>(INPUT_TYPE.BYTE1, outputs);
-    IntsRef scratch = new IntsRef();
+    IntsRefBuilder scratch = new IntsRefBuilder();
     long ord = 0;
     for (BytesRef v : values) {
       builder.add(Util.toIntsRef(v, scratch), ord);

Modified: lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/util/TestUtil.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/util/TestUtil.java?rev=1617695&r1=1617694&r2=1617695&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/util/TestUtil.java (original)
+++ lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/util/TestUtil.java Wed Aug 13 09:36:54 2014
@@ -902,9 +902,9 @@ public final class TestUtil {
   public static CharSequence bytesToCharSequence(BytesRef ref, Random random) {
     switch(random.nextInt(5)) {
     case 4:
-      CharsRef chars = new CharsRef(ref.length);
-      UnicodeUtil.UTF8toUTF16(ref.bytes, ref.offset, ref.length, chars);
-      return chars;
+      final char[] chars = new char[ref.length];
+      final int len = UnicodeUtil.UTF8toUTF16(ref.bytes, ref.offset, ref.length, chars);
+      return new CharsRef(chars, 0, len);
     case 3:
       return CharBuffer.wrap(ref.utf8ToString());
     default:

Modified: lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/util/automaton/AutomatonTestUtil.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/util/automaton/AutomatonTestUtil.java?rev=1617695&r1=1617694&r2=1617695&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/util/automaton/AutomatonTestUtil.java (original)
+++ lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/util/automaton/AutomatonTestUtil.java Wed Aug 13 09:36:54 2014
@@ -28,6 +28,7 @@ import java.util.Set;
 
 import org.apache.lucene.util.ArrayUtil;
 import org.apache.lucene.util.IntsRef;
+import org.apache.lucene.util.IntsRefBuilder;
 import org.apache.lucene.util.TestUtil;
 import org.apache.lucene.util.UnicodeUtil;
 
@@ -401,7 +402,7 @@ public class AutomatonTestUtil {
    */
   public static Set<IntsRef> getFiniteStringsRecursive(Automaton a, int limit) {
     HashSet<IntsRef> strings = new HashSet<>();
-    if (!getFiniteStrings(a, 0, new HashSet<Integer>(), strings, new IntsRef(), limit)) {
+    if (!getFiniteStrings(a, 0, new HashSet<Integer>(), strings, new IntsRefBuilder(), limit)) {
       return strings;
     }
     return strings;
@@ -413,7 +414,7 @@ public class AutomatonTestUtil {
    * <code>limit</code>&lt;0 means "infinite".
    */
   private static boolean getFiniteStrings(Automaton a, int s, HashSet<Integer> pathstates, 
-      HashSet<IntsRef> strings, IntsRef path, int limit) {
+      HashSet<IntsRef> strings, IntsRefBuilder path, int limit) {
     pathstates.add(s);
     Transition t = new Transition();
     int count = a.initTransition(s, t);
@@ -423,11 +424,9 @@ public class AutomatonTestUtil {
         return false;
       }
       for (int n = t.min; n <= t.max; n++) {
-        path.grow(path.length+1);
-        path.ints[path.length] = n;
-        path.length++;
+        path.append(n);
         if (a.isAccept(t.dest)) {
-          strings.add(IntsRef.deepCopyOf(path));
+          strings.add(path.toIntsRef());
           if (limit >= 0 && strings.size() > limit) {
             return false;
           }
@@ -435,7 +434,7 @@ public class AutomatonTestUtil {
         if (!getFiniteStrings(a, t.dest, pathstates, strings, path, limit)) {
           return false;
         }
-        path.length--;
+        path.setLength(path.length() - 1);
       }
     }
     pathstates.remove(s);

Modified: lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/util/fst/FSTTester.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/util/fst/FSTTester.java?rev=1617695&r1=1617694&r2=1617695&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/util/fst/FSTTester.java (original)
+++ lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/util/fst/FSTTester.java Wed Aug 13 09:36:54 2014
@@ -38,6 +38,7 @@ import org.apache.lucene.store.IndexInpu
 import org.apache.lucene.store.IndexOutput;
 import org.apache.lucene.util.BytesRef;
 import org.apache.lucene.util.IntsRef;
+import org.apache.lucene.util.IntsRefBuilder;
 import org.apache.lucene.util.LuceneTestCase;
 import org.apache.lucene.util.TestUtil;
 import org.apache.lucene.util.UnicodeUtil;
@@ -122,10 +123,10 @@ public class FSTTester<T> {
   }
 
   static IntsRef toIntsRef(String s, int inputMode) {
-    return toIntsRef(s, inputMode, new IntsRef(10));
+    return toIntsRef(s, inputMode, new IntsRefBuilder());
   }
 
-  static IntsRef toIntsRef(String s, int inputMode, IntsRef ir) {
+  static IntsRef toIntsRef(String s, int inputMode, IntsRefBuilder ir) {
     if (inputMode == 0) {
       // utf8
       return toIntsRef(new BytesRef(s), ir);
@@ -135,32 +136,28 @@ public class FSTTester<T> {
     }
   }
 
-  static IntsRef toIntsRefUTF32(String s, IntsRef ir) {
+  static IntsRef toIntsRefUTF32(String s, IntsRefBuilder ir) {
     final int charLength = s.length();
     int charIdx = 0;
     int intIdx = 0;
+    ir.clear();
     while(charIdx < charLength) {
-      if (intIdx == ir.ints.length) {
-        ir.grow(intIdx+1);
-      }
+      ir.grow(intIdx+1);
       final int utf32 = s.codePointAt(charIdx);
-      ir.ints[intIdx] = utf32;
+      ir.append(utf32);
       charIdx += Character.charCount(utf32);
       intIdx++;
     }
-    ir.length = intIdx;
-    return ir;
+    return ir.get();
   }
 
-  static IntsRef toIntsRef(BytesRef br, IntsRef ir) {
-    if (br.length > ir.ints.length) {
-      ir.grow(br.length);
-    }
+  static IntsRef toIntsRef(BytesRef br, IntsRefBuilder ir) {
+    ir.grow(br.length);
+    ir.clear();
     for(int i=0;i<br.length;i++) {
-      ir.ints[i] = br.bytes[br.offset+i]&0xFF;
+      ir.append(br.bytes[br.offset+i]&0xFF);
     }
-    ir.length = br.length;
-    return ir;
+    return ir.get();
   }
 
   /** Holds one input/output pair. */
@@ -234,12 +231,11 @@ public class FSTTester<T> {
     return output;
   }
 
-  private T randomAcceptedWord(FST<T> fst, IntsRef in) throws IOException {
+  private T randomAcceptedWord(FST<T> fst, IntsRefBuilder in) throws IOException {
     FST.Arc<T> arc = fst.getFirstArc(new FST.Arc<T>());
 
     final List<FST.Arc<T>> arcs = new ArrayList<>();
-    in.length = 0;
-    in.offset = 0;
+    in.clear();
     final T NO_OUTPUT = fst.outputs.getNoOutput();
     T output = NO_OUTPUT;
     final FST.BytesReader fstReader = fst.getBytesReader();
@@ -265,10 +261,7 @@ public class FSTTester<T> {
         break;
       }
 
-      if (in.ints.length == in.length) {
-        in.grow(1+in.length);
-      }
-      in.ints[in.length++] = arc.label;
+      in.append(arc.label);
     }
 
     return output;
@@ -444,19 +437,19 @@ public class FSTTester<T> {
     if (LuceneTestCase.VERBOSE) {
       System.out.println("TEST: verify random accepted terms");
     }
-    final IntsRef scratch = new IntsRef(10);
+    final IntsRefBuilder scratch = new IntsRefBuilder();
     int num = LuceneTestCase.atLeast(random, 500);
     for(int iter=0;iter<num;iter++) {
       T output = randomAcceptedWord(fst, scratch);
-      assertTrue("accepted word " + inputToString(inputMode, scratch) + " is not valid", termsMap.containsKey(scratch));
-      assertTrue(outputsEqual(termsMap.get(scratch), output));
+      assertTrue("accepted word " + inputToString(inputMode, scratch.get()) + " is not valid", termsMap.containsKey(scratch.get()));
+      assertTrue(outputsEqual(termsMap.get(scratch.get()), output));
 
       if (doReverseLookup) {
         //System.out.println("lookup output=" + output + " outs=" + fst.outputs);
         IntsRef input = Util.getByOutput(fstLong, (Long) output);
         assertNotNull(input);
         //System.out.println("  got " + Util.toBytesRef(input, new BytesRef()).utf8ToString());
-        assertEquals(scratch, input);
+        assertEquals(scratch.get(), input);
       }
     }
     
@@ -683,17 +676,17 @@ public class FSTTester<T> {
 
     // build all prefixes
     final Map<IntsRef,CountMinOutput<T>> prefixes = new HashMap<>();
-    final IntsRef scratch = new IntsRef(10);
+    final IntsRefBuilder scratch = new IntsRefBuilder();
     for(InputOutput<T> pair: pairs) {
       scratch.copyInts(pair.input);
       for(int idx=0;idx<=pair.input.length;idx++) {
-        scratch.length = idx;
-        CountMinOutput<T> cmo = prefixes.get(scratch);
+        scratch.setLength(idx);
+        CountMinOutput<T> cmo = prefixes.get(scratch.get());
         if (cmo == null) {
           cmo = new CountMinOutput<>();
           cmo.count = 1;
           cmo.output = pair.output;
-          prefixes.put(IntsRef.deepCopyOf(scratch), cmo);
+          prefixes.put(scratch.toIntsRef(), cmo);
         } else {
           cmo.count++;
           T output1 = cmo.output;
@@ -735,9 +728,9 @@ public class FSTTester<T> {
           keep = true;
         } else if (prefix.length > 0) {
           // consult our parent
-          scratch.length = prefix.length-1;
-          System.arraycopy(prefix.ints, prefix.offset, scratch.ints, 0, scratch.length);
-          final CountMinOutput<T> cmo2 = prefixes.get(scratch);
+          scratch.setLength(prefix.length-1);
+          System.arraycopy(prefix.ints, prefix.offset, scratch.ints(), 0, scratch.length());
+          final CountMinOutput<T> cmo2 = prefixes.get(scratch.get());
           //System.out.println("    parent count = " + (cmo2 == null ? -1 : cmo2.count));
           keep = cmo2 != null && ((prune2 > 1 && cmo2.count >= prune2) || (prune2 == 1 && (cmo2.count >= 2 || prefix.length <= 1)));
         } else if (cmo.count >= prune2) {
@@ -754,14 +747,14 @@ public class FSTTester<T> {
         // clear isLeaf for all ancestors
         //System.out.println("    keep");
         scratch.copyInts(prefix);
-        scratch.length--;
-        while(scratch.length >= 0) {
-          final CountMinOutput<T> cmo2 = prefixes.get(scratch);
+        scratch.setLength(scratch.length() - 1);
+        while(scratch.length() >= 0) {
+          final CountMinOutput<T> cmo2 = prefixes.get(scratch.get());
           if (cmo2 != null) {
             //System.out.println("    clear isLeaf " + inputToString(inputMode, scratch));
             cmo2.isLeaf = false;
           }
-          scratch.length--;
+          scratch.setLength(scratch.length() - 1);
         }
       }
     }

Modified: lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/handler/AnalysisRequestHandlerBase.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/handler/AnalysisRequestHandlerBase.java?rev=1617695&r1=1617694&r2=1617695&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/handler/AnalysisRequestHandlerBase.java (original)
+++ lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/handler/AnalysisRequestHandlerBase.java Wed Aug 13 09:36:54 2014
@@ -30,6 +30,7 @@ import org.apache.lucene.util.AttributeS
 import org.apache.lucene.util.AttributeReflector;
 import org.apache.lucene.util.CharsRef;
 import org.apache.lucene.util.ArrayUtil;
+import org.apache.lucene.util.CharsRefBuilder;
 import org.apache.lucene.util.IOUtils;
 import org.apache.solr.analysis.TokenizerChain;
 import org.apache.solr.common.util.NamedList;
@@ -43,6 +44,7 @@ import java.io.IOException;
 import java.io.Reader;
 import java.io.StringReader;
 import java.util.*;
+
 import org.apache.commons.lang.ArrayUtils;
 
 /**
@@ -247,7 +249,7 @@ public abstract class AnalysisRequestHan
       final TermToBytesRefAttribute termAtt = token.getAttribute(TermToBytesRefAttribute.class);
       BytesRef rawBytes = termAtt.getBytesRef();
       termAtt.fillBytesRef();
-      final String text = fieldType.indexedToReadable(rawBytes, new CharsRef(rawBytes.length)).toString();
+      final String text = fieldType.indexedToReadable(rawBytes, new CharsRefBuilder()).toString();
       tokenNamedList.add("text", text);
       
       if (token.hasAttribute(CharTermAttribute.class)) {

Modified: lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/handler/admin/LukeRequestHandler.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/handler/admin/LukeRequestHandler.java?rev=1617695&r1=1617694&r2=1617695&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/handler/admin/LukeRequestHandler.java (original)
+++ lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/handler/admin/LukeRequestHandler.java Wed Aug 13 09:36:54 2014
@@ -35,6 +35,7 @@ import org.apache.lucene.search.similari
 import org.apache.lucene.store.Directory;
 import org.apache.lucene.util.BytesRef;
 import org.apache.lucene.util.CharsRef;
+import org.apache.lucene.util.CharsRefBuilder;
 import org.apache.lucene.util.PriorityQueue;
 import org.apache.lucene.util.UnicodeUtil;
 import org.apache.solr.analysis.TokenizerChain;
@@ -250,7 +251,7 @@ public class LukeRequestHandler extends 
   private static SimpleOrderedMap<Object> getDocumentFieldsInfo( Document doc, int docId, IndexReader reader,
                                                                  IndexSchema schema ) throws IOException
   {
-    final CharsRef spare = new CharsRef();
+    final CharsRefBuilder spare = new CharsRefBuilder();
     SimpleOrderedMap<Object> finfo = new SimpleOrderedMap<>();
     for( Object o : doc.getFields() ) {
       Field field = (Field)o;
@@ -287,7 +288,7 @@ public class LukeRequestHandler extends 
             BytesRef text;
             while((text = termsEnum.next()) != null) {
               final int freq = (int) termsEnum.totalTermFreq();
-              UnicodeUtil.UTF8toUTF16(text, spare);
+              spare.copyUTF8Bytes(text);
               tfv.add(spare.toString(), freq);
             }
             f.add( "termVector", tfv );
@@ -595,7 +596,7 @@ public class LukeRequestHandler extends 
 
     TopTermQueue tiq = new TopTermQueue(numTerms + 1);  // Something to collect the top N terms in.
 
-    final CharsRef spare = new CharsRef();
+    final CharsRefBuilder spare = new CharsRefBuilder();
 
     Fields fields = MultiFields.getFields(req.getSearcher().getIndexReader());
 
@@ -616,7 +617,7 @@ public class LukeRequestHandler extends 
       int slot = 32 - Integer.numberOfLeadingZeros(Math.max(0, freq - 1));
       buckets[slot] = buckets[slot] + 1;
       if (numTerms > 0 && freq > tiq.minFreq) {
-        UnicodeUtil.UTF8toUTF16(text, spare);
+        spare.copyUTF8Bytes(text);
         String t = spare.toString();
 
         tiq.add(new TopTermQueue.TermInfo(new Term(field, t), termsEnum.docFreq()));

Modified: lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/handler/component/ExpandComponent.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/handler/component/ExpandComponent.java?rev=1617695&r1=1617694&r2=1617695&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/handler/component/ExpandComponent.java (original)
+++ lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/handler/component/ExpandComponent.java Wed Aug 13 09:36:54 2014
@@ -21,6 +21,7 @@ import com.carrotsearch.hppc.IntObjectMa
 import com.carrotsearch.hppc.IntObjectOpenHashMap;
 import com.carrotsearch.hppc.IntOpenHashSet;
 import com.carrotsearch.hppc.cursors.IntObjectCursor;
+
 import org.apache.lucene.index.AtomicReader;
 import org.apache.lucene.index.AtomicReaderContext;
 import org.apache.lucene.index.SortedDocValues;
@@ -37,6 +38,7 @@ import org.apache.lucene.search.TopField
 import org.apache.lucene.search.TopScoreDocCollector;
 import org.apache.lucene.util.BytesRef;
 import org.apache.lucene.util.CharsRef;
+import org.apache.lucene.util.CharsRefBuilder;
 import org.apache.lucene.util.FixedBitSet;
 import org.apache.solr.common.SolrDocumentList;
 import org.apache.solr.common.params.ExpandParams;
@@ -216,7 +218,7 @@ public class ExpandComponent extends Sea
     searcher.search(query, pfilter.filter, collector);
     IntObjectMap groups = groupExpandCollector.getGroups();
     Map<String, DocSlice> outMap = new HashMap();
-    CharsRef charsRef = new CharsRef();
+    CharsRefBuilder charsRef = new CharsRefBuilder();
     FieldType fieldType = searcher.getSchema().getField(field).getType();
     for (IntObjectCursor cursor : (Iterable<IntObjectCursor>) groups) {
       int ord = cursor.key;

Modified: lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/handler/component/PivotFacetHelper.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/handler/component/PivotFacetHelper.java?rev=1617695&r1=1617694&r2=1617695&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/handler/component/PivotFacetHelper.java (original)
+++ lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/handler/component/PivotFacetHelper.java Wed Aug 13 09:36:54 2014
@@ -17,32 +17,32 @@
 
 package org.apache.solr.handler.component;
 
-import org.apache.lucene.util.BytesRef;
-import org.apache.solr.schema.SchemaField;
-import org.apache.solr.search.SolrIndexSearcher;
-import org.apache.solr.search.DocSet;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Deque;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.lucene.index.Term;
+import org.apache.lucene.search.Query;
+import org.apache.lucene.search.TermQuery;
+import org.apache.lucene.search.TermRangeQuery;
+import org.apache.lucene.util.BytesRefBuilder;
 import org.apache.solr.common.SolrException;
-import org.apache.solr.common.util.NamedList;
-import org.apache.solr.common.util.SimpleOrderedMap;
 import org.apache.solr.common.SolrException.ErrorCode;
-import org.apache.solr.common.params.SolrParams;
 import org.apache.solr.common.params.FacetParams;
+import org.apache.solr.common.params.SolrParams;
+import org.apache.solr.common.util.NamedList;
+import org.apache.solr.common.util.SimpleOrderedMap;
 import org.apache.solr.request.SimpleFacets;
 import org.apache.solr.request.SolrQueryRequest;
 import org.apache.solr.schema.FieldType;
-import org.apache.lucene.search.Query;
-import org.apache.lucene.search.TermQuery;
-import org.apache.lucene.search.TermRangeQuery;
-import org.apache.lucene.index.Term;
+import org.apache.solr.schema.SchemaField;
+import org.apache.solr.search.DocSet;
+import org.apache.solr.search.SolrIndexSearcher;
 import org.apache.solr.search.SyntaxError;
 
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Deque;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-
 /**
  * @since solr 4.0
  */
@@ -116,16 +116,16 @@ public class PivotFacetHelper extends Si
 
         // don't reuse the same BytesRef each time since we will be 
         // constructing Term objects used in TermQueries that may be cached.
-        BytesRef termval = null;
+        BytesRefBuilder termval = null;
 
         SimpleOrderedMap<Object> pivot = new SimpleOrderedMap<>();
         pivot.add( "field", field );
         if (null == fieldValue) {
           pivot.add( "value", null );
         } else {
-          termval = new BytesRef();
+          termval = new BytesRefBuilder();
           ftype.readableToIndexed(fieldValue, termval);
-          pivot.add( "value", ftype.toObject(sfield, termval) );
+          pivot.add( "value", ftype.toObject(sfield, termval.get()) );
         }
         pivot.add( "count", kv.getValue() );
         
@@ -139,7 +139,7 @@ public class PivotFacetHelper extends Si
               (new TermRangeQuery(field, null, null, false, false));
             subset = docs.andNot(hasVal);
           } else {
-            Query query = new TermQuery(new Term(field, termval));
+            Query query = new TermQuery(new Term(field, termval.get()));
             subset = searcher.getDocSet(query, docs);
           }
           super.docs = subset;//used by getTermCounts()

Modified: lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/handler/component/QueryElevationComponent.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/handler/component/QueryElevationComponent.java?rev=1617695&r1=1617694&r2=1617695&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/handler/component/QueryElevationComponent.java (original)
+++ lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/handler/component/QueryElevationComponent.java Wed Aug 13 09:36:54 2014
@@ -19,6 +19,7 @@ package org.apache.solr.handler.componen
 
 import com.carrotsearch.hppc.IntOpenHashSet;
 import com.carrotsearch.hppc.IntIntOpenHashMap;
+
 import org.apache.lucene.analysis.Analyzer;
 import org.apache.lucene.analysis.TokenStream;
 import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
@@ -41,6 +42,7 @@ import org.apache.lucene.search.SortFiel
 import org.apache.lucene.search.TermQuery;
 import org.apache.lucene.util.Bits;
 import org.apache.lucene.util.BytesRef;
+import org.apache.lucene.util.BytesRefBuilder;
 import org.apache.lucene.util.IOUtils;
 import org.apache.lucene.util.SentinelIntSet;
 import org.apache.solr.cloud.ZkController;
@@ -75,6 +77,7 @@ import javax.xml.xpath.XPath;
 import javax.xml.xpath.XPathConstants;
 import javax.xml.xpath.XPathExpressionException;
 import javax.xml.xpath.XPathFactory;
+
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
@@ -690,17 +693,17 @@ public class QueryElevationComponent ext
         Terms terms = fields.terms(idField);
         if (terms == null) return this;
         termsEnum = terms.iterator(termsEnum);
-        BytesRef term = new BytesRef();
+        BytesRefBuilder term = new BytesRefBuilder();
         Bits liveDocs = context.reader().getLiveDocs();
 
         for (String id : elevations.ids) {
           term.copyChars(id);
-          if (seen.contains(id) == false  && termsEnum.seekExact(term)) {
+          if (seen.contains(id) == false  && termsEnum.seekExact(term.get())) {
             docsEnum = termsEnum.docs(liveDocs, docsEnum, DocsEnum.FLAG_NONE);
             if (docsEnum != null) {
               int docId = docsEnum.nextDoc();
               if (docId == DocIdSetIterator.NO_MORE_DOCS ) continue;  // must have been deleted
-              termValues[ordSet.put(docId)] = BytesRef.deepCopyOf(term);
+              termValues[ordSet.put(docId)] = term.toBytesRef();
               seen.add(id);
               assert docsEnum.nextDoc() == DocIdSetIterator.NO_MORE_DOCS;
             }

Modified: lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/handler/component/RealTimeGetComponent.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/handler/component/RealTimeGetComponent.java?rev=1617695&r1=1617694&r2=1617695&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/handler/component/RealTimeGetComponent.java (original)
+++ lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/handler/component/RealTimeGetComponent.java Wed Aug 13 09:36:54 2014
@@ -28,6 +28,7 @@ import org.apache.lucene.document.Docume
 import org.apache.lucene.index.IndexableField;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.util.BytesRef;
+import org.apache.lucene.util.BytesRefBuilder;
 import org.apache.solr.client.solrj.SolrResponse;
 import org.apache.solr.cloud.CloudDescriptor;
 import org.apache.solr.cloud.ZkController;
@@ -137,11 +138,11 @@ public class RealTimeGetComponent extend
    try {
      SolrIndexSearcher searcher = null;
 
-     BytesRef idBytes = new BytesRef();
+     BytesRefBuilder idBytes = new BytesRefBuilder();
      for (String idStr : allIds) {
        fieldType.readableToIndexed(idStr, idBytes);
        if (ulog != null) {
-         Object o = ulog.lookup(idBytes);
+         Object o = ulog.lookup(idBytes.get());
          if (o != null) {
            // should currently be a List<Oper,Ver,Doc/Id>
            List entry = (List)o;
@@ -172,7 +173,7 @@ public class RealTimeGetComponent extend
 
        // SolrCore.verbose("RealTimeGet using searcher ", searcher);
 
-       int docid = searcher.getFirstMatch(new Term(idField.getName(), idBytes));
+       int docid = searcher.getFirstMatch(new Term(idField.getName(), idBytes.get()));
        if (docid < 0) continue;
        Document luceneDocument = searcher.doc(docid);
        SolrDocument doc = toSolrDoc(luceneDocument,  core.getLatestSchema());

Modified: lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/handler/component/TermsComponent.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/handler/component/TermsComponent.java?rev=1617695&r1=1617694&r2=1617695&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/handler/component/TermsComponent.java (original)
+++ lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/handler/component/TermsComponent.java Wed Aug 13 09:36:54 2014
@@ -18,7 +18,9 @@ package org.apache.solr.handler.componen
 
 import org.apache.lucene.index.*;
 import org.apache.lucene.util.BytesRef;
+import org.apache.lucene.util.BytesRefBuilder;
 import org.apache.lucene.util.CharsRef;
+import org.apache.lucene.util.CharsRefBuilder;
 import org.apache.lucene.util.StringHelper;
 import org.apache.solr.common.SolrException;
 import org.apache.solr.common.params.*;
@@ -29,7 +31,6 @@ import org.apache.solr.schema.FieldType;
 import org.apache.solr.schema.StrField;
 import org.apache.solr.request.SimpleFacets.CountPair;
 import org.apache.solr.util.BoundedTreeSet;
-
 import org.apache.solr.client.solrj.response.TermsResponse;
 
 import java.io.IOException;
@@ -138,8 +139,9 @@ public class TermsComponent extends Sear
 
       BytesRef upperBytes = null;
       if (upperStr != null) {
-        upperBytes = new BytesRef();
-        ft.readableToIndexed(upperStr, upperBytes);
+        BytesRefBuilder b = new BytesRefBuilder();
+        ft.readableToIndexed(upperStr, b);
+        upperBytes = b.get();
       }
 
       BytesRef lowerBytes;
@@ -153,8 +155,9 @@ public class TermsComponent extends Sear
           // perhaps we detect if the FieldType is non-character and expect hex if so?
           lowerBytes = new BytesRef(lowerStr);
         } else {
-          lowerBytes = new BytesRef();
-          ft.readableToIndexed(lowerStr, lowerBytes);
+          BytesRefBuilder b = new BytesRefBuilder();
+          ft.readableToIndexed(lowerStr, b);
+          lowerBytes = b.get();
         }
       }
 
@@ -179,7 +182,7 @@ public class TermsComponent extends Sear
 
       int i = 0;
       BoundedTreeSet<CountPair<BytesRef, Integer>> queue = (sort ? new BoundedTreeSet<CountPair<BytesRef, Integer>>(limit) : null);
-      CharsRef external = new CharsRef();
+      CharsRefBuilder external = new CharsRefBuilder();
       while (term != null && (i<limit || sort)) {
         boolean externalized = false; // did we fill in "external" yet for this term?
 
@@ -191,7 +194,7 @@ public class TermsComponent extends Sear
           // TODO: support "raw" mode?
           ft.indexedToReadable(term, external);
           externalized = true;
-          if (!pattern.matcher(external).matches()) {
+          if (!pattern.matcher(external.get()).matches()) {
             term = termsEnum.next();
             continue;
           }

Modified: lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/request/DocValuesFacets.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/request/DocValuesFacets.java?rev=1617695&r1=1617694&r2=1617695&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/request/DocValuesFacets.java (original)
+++ lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/request/DocValuesFacets.java Wed Aug 13 09:36:54 2014
@@ -31,7 +31,9 @@ import org.apache.lucene.search.DocIdSet
 import org.apache.lucene.search.DocIdSetIterator;
 import org.apache.lucene.search.Filter;
 import org.apache.lucene.util.BytesRef;
+import org.apache.lucene.util.BytesRefBuilder;
 import org.apache.lucene.util.CharsRef;
+import org.apache.lucene.util.CharsRefBuilder;
 import org.apache.lucene.util.LongValues;
 import org.apache.lucene.util.UnicodeUtil;
 import org.apache.solr.common.params.FacetParams;
@@ -83,22 +85,23 @@ public class DocValuesFacets {
       throw new UnsupportedOperationException("Currently this faceting method is limited to " + Integer.MAX_VALUE + " unique terms");
     }
 
-    final BytesRef prefixRef;
+    final BytesRefBuilder prefixRef;
     if (prefix == null) {
       prefixRef = null;
     } else if (prefix.length()==0) {
       prefix = null;
       prefixRef = null;
     } else {
-      prefixRef = new BytesRef(prefix);
+      prefixRef = new BytesRefBuilder();
+      prefixRef.copyChars(prefix);
     }
 
     int startTermIndex, endTermIndex;
     if (prefix!=null) {
-      startTermIndex = (int) si.lookupTerm(prefixRef);
+      startTermIndex = (int) si.lookupTerm(prefixRef.get());
       if (startTermIndex<0) startTermIndex=-startTermIndex-1;
       prefixRef.append(UnicodeUtil.BIG_TERM);
-      endTermIndex = (int) si.lookupTerm(prefixRef);
+      endTermIndex = (int) si.lookupTerm(prefixRef.get());
       assert endTermIndex < 0;
       endTermIndex = -endTermIndex-1;
     } else {
@@ -108,7 +111,7 @@ public class DocValuesFacets {
 
     final int nTerms=endTermIndex-startTermIndex;
     int missingCount = -1; 
-    final CharsRef charsRef = new CharsRef(10);
+    final CharsRefBuilder charsRef = new CharsRefBuilder();
     if (nTerms>0 && docs.size() >= mincount) {
 
       // count collection array only needs to be as big as the number of terms we are

Modified: lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/request/NumericFacets.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/request/NumericFacets.java?rev=1617695&r1=1617694&r2=1617695&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/request/NumericFacets.java (original)
+++ lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/request/NumericFacets.java Wed Aug 13 09:36:54 2014
@@ -39,6 +39,7 @@ import org.apache.lucene.search.FieldCac
 import org.apache.lucene.util.Bits;
 import org.apache.lucene.util.BytesRef;
 import org.apache.lucene.util.CharsRef;
+import org.apache.lucene.util.CharsRefBuilder;
 import org.apache.lucene.util.NumericUtils;
 import org.apache.lucene.util.PriorityQueue;
 import org.apache.lucene.util.StringHelper;
@@ -290,7 +291,7 @@ final class NumericFacets {
             default:
               throw new AssertionError();
           }
-          final CharsRef spare = new CharsRef();
+          final CharsRefBuilder spare = new CharsRefBuilder();
           for (int skipped = hashTable.size; skipped < offset && term != null && StringHelper.startsWith(term, prefix); ) {
             ft.indexedToReadable(term, spare);
             final String termStr = spare.toString();
@@ -343,7 +344,7 @@ final class NumericFacets {
           default:
             throw new AssertionError();
         }
-        final CharsRef spare = new CharsRef();
+        final CharsRefBuilder spare = new CharsRefBuilder();
         for (int i = 0; i < offset && term != null && StringHelper.startsWith(term, prefix); ++i) {
           term = termsEnum.next();
         }

Modified: lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/request/PerSegmentSingleValuedFaceting.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/request/PerSegmentSingleValuedFaceting.java?rev=1617695&r1=1617694&r2=1617695&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/request/PerSegmentSingleValuedFaceting.java (original)
+++ lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/request/PerSegmentSingleValuedFaceting.java Wed Aug 13 09:36:54 2014
@@ -29,7 +29,9 @@ import org.apache.lucene.search.DocIdSet
 import org.apache.lucene.search.FieldCache;
 import org.apache.lucene.search.Filter;
 import org.apache.lucene.util.BytesRef;
+import org.apache.lucene.util.BytesRefBuilder;
 import org.apache.lucene.util.CharsRef;
+import org.apache.lucene.util.CharsRefBuilder;
 import org.apache.lucene.util.PriorityQueue;
 import org.apache.lucene.util.UnicodeUtil;
 import org.apache.lucene.util.packed.PackedInts;
@@ -169,7 +171,7 @@ class PerSegmentSingleValuedFaceting {
       collector = new IndexSortedFacetCollector(offset, limit, mincount);
     }
 
-    BytesRef val = new BytesRef();
+    BytesRefBuilder val = new BytesRefBuilder();
 
     while (queue.size() > 0) {
       SegFacet seg = queue.top();
@@ -194,9 +196,9 @@ class PerSegmentSingleValuedFaceting {
           seg.tempBR = seg.tenum.next();
           seg = queue.updateTop();
         }
-      } while (seg != null && val.compareTo(seg.tempBR) == 0);
+      } while (seg != null && val.get().compareTo(seg.tempBR) == 0);
 
-      boolean stop = collector.collect(val, count);
+      boolean stop = collector.collect(val.get(), count);
       if (stop) break;
     }
 
@@ -240,12 +242,13 @@ class PerSegmentSingleValuedFaceting {
       // SolrCore.log.info("reader= " + reader + "  FC=" + System.identityHashCode(si));
 
       if (prefix!=null) {
-        BytesRef prefixRef = new BytesRef(prefix);
-        startTermIndex = si.lookupTerm(prefixRef);
+        BytesRefBuilder prefixRef = new BytesRefBuilder();
+        prefixRef.copyChars(prefix);
+        startTermIndex = si.lookupTerm(prefixRef.get());
         if (startTermIndex<0) startTermIndex=-startTermIndex-1;
         prefixRef.append(UnicodeUtil.BIG_TERM);
         // TODO: we could constrain the lower endpoint if we had a binarySearch method that allowed passing start/end
-        endTermIndex = si.lookupTerm(prefixRef);
+        endTermIndex = si.lookupTerm(prefixRef.get());
         assert endTermIndex < 0;
         endTermIndex = -endTermIndex-1;
       } else {
@@ -295,7 +298,7 @@ abstract class FacetCollector {
 
 // This collector expects facets to be collected in index order
 class CountSortedFacetCollector extends FacetCollector {
-  private final CharsRef spare = new CharsRef();
+  private final CharsRefBuilder spare = new CharsRefBuilder();
 
   final int offset;
   final int limit;
@@ -318,7 +321,7 @@ class CountSortedFacetCollector extends 
       // NOTE: we use c>min rather than c>=min as an optimization because we are going in
       // index order, so we already know that the keys are ordered.  This can be very
       // important if a lot of the counts are repeated (like zero counts would be).
-      UnicodeUtil.UTF8toUTF16(term, spare);
+      spare.copyUTF8Bytes(term);
       queue.add(new SimpleFacets.CountPair<>(spare.toString(), count));
       if (queue.size()>=maxsize) min=queue.last().val;
     }
@@ -342,7 +345,7 @@ class CountSortedFacetCollector extends 
 
 // This collector expects facets to be collected in index order
 class IndexSortedFacetCollector extends FacetCollector {
-  private final CharsRef spare = new CharsRef();
+  private final CharsRefBuilder spare = new CharsRefBuilder();
 
   int offset;
   int limit;
@@ -367,7 +370,7 @@ class IndexSortedFacetCollector extends 
     }
 
     if (limit > 0) {
-      UnicodeUtil.UTF8toUTF16(term, spare);
+      spare.copyUTF8Bytes(term);
       res.add(spare.toString(), count);
       limit--;
     }

Modified: lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/request/SimpleFacets.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/request/SimpleFacets.java?rev=1617695&r1=1617694&r2=1617695&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/request/SimpleFacets.java (original)
+++ lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/request/SimpleFacets.java Wed Aug 13 09:36:54 2014
@@ -56,7 +56,9 @@ import org.apache.lucene.search.grouping
 import org.apache.lucene.search.grouping.term.TermAllGroupsCollector;
 import org.apache.lucene.search.grouping.term.TermGroupFacetCollector;
 import org.apache.lucene.util.BytesRef;
+import org.apache.lucene.util.BytesRefBuilder;
 import org.apache.lucene.util.CharsRef;
+import org.apache.lucene.util.CharsRefBuilder;
 import org.apache.lucene.util.StringHelper;
 import org.apache.lucene.util.UnicodeUtil;
 import org.apache.solr.common.SolrException;
@@ -481,7 +483,7 @@ public class SimpleFacets {
                                       (offset + limit), 
                                       mincount, orderByCount);
 
-    CharsRef charsRef = new CharsRef();
+    CharsRefBuilder charsRef = new CharsRefBuilder();
     FieldType facetFieldType = searcher.getSchema().getFieldType(field);
     NamedList<Integer> facetCounts = new NamedList<>();
     List<TermGroupFacetCollector.FacetEntry> scopedEntries 
@@ -654,22 +656,23 @@ public class SimpleFacets {
 
     BytesRef br = new BytesRef();
 
-    final BytesRef prefixRef;
+    final BytesRefBuilder prefixRef;
     if (prefix == null) {
       prefixRef = null;
     } else if (prefix.length()==0) {
       prefix = null;
       prefixRef = null;
     } else {
-      prefixRef = new BytesRef(prefix);
+      prefixRef = new BytesRefBuilder();
+      prefixRef.copyChars(prefix);
     }
 
     int startTermIndex, endTermIndex;
     if (prefix!=null) {
-      startTermIndex = si.lookupTerm(prefixRef);
+      startTermIndex = si.lookupTerm(prefixRef.get());
       if (startTermIndex<0) startTermIndex=-startTermIndex-1;
       prefixRef.append(UnicodeUtil.BIG_TERM);
-      endTermIndex = si.lookupTerm(prefixRef);
+      endTermIndex = si.lookupTerm(prefixRef.get());
       assert endTermIndex < 0;
       endTermIndex = -endTermIndex-1;
     } else {
@@ -679,7 +682,7 @@ public class SimpleFacets {
 
     final int nTerms=endTermIndex-startTermIndex;
     int missingCount = -1; 
-    final CharsRef charsRef = new CharsRef(10);
+    final CharsRefBuilder charsRef = new CharsRefBuilder();
     if (nTerms>0 && docs.size() >= mincount) {
 
       // count collection array only needs to be as big as the number of terms we are
@@ -846,7 +849,7 @@ public class SimpleFacets {
     }
 
     DocsEnum docsEnum = null;
-    CharsRef charsRef = new CharsRef(10);
+    CharsRefBuilder charsRef = new CharsRefBuilder();
 
     if (docs.size() >= mincount) {
       while (term != null) {

Modified: lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/request/UnInvertedField.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/request/UnInvertedField.java?rev=1617695&r1=1617694&r2=1617695&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/request/UnInvertedField.java (original)
+++ lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/request/UnInvertedField.java Wed Aug 13 09:36:54 2014
@@ -30,7 +30,9 @@ import org.apache.lucene.index.TermsEnum
 import org.apache.lucene.search.TermQuery;
 import org.apache.lucene.search.TermRangeQuery;
 import org.apache.lucene.util.BytesRef;
+import org.apache.lucene.util.BytesRefBuilder;
 import org.apache.lucene.util.CharsRef;
+import org.apache.lucene.util.CharsRefBuilder;
 import org.apache.lucene.util.FixedBitSet;
 import org.apache.lucene.util.UnicodeUtil;
 import org.apache.solr.common.SolrException;
@@ -239,14 +241,15 @@ public class UnInvertedField extends Doc
 
       TermsEnum te = getOrdTermsEnum(searcher.getAtomicReader());
       if (te != null && prefix != null && prefix.length() > 0) {
-        final BytesRef prefixBr = new BytesRef(prefix);
-        if (te.seekCeil(prefixBr) == TermsEnum.SeekStatus.END) {
+        final BytesRefBuilder prefixBr = new BytesRefBuilder();
+        prefixBr.copyChars(prefix);
+        if (te.seekCeil(prefixBr.get()) == TermsEnum.SeekStatus.END) {
           startTerm = numTermsInField;
         } else {
           startTerm = (int) te.ord();
         }
         prefixBr.append(UnicodeUtil.BIG_TERM);
-        if (te.seekCeil(prefixBr) == TermsEnum.SeekStatus.END) {
+        if (te.seekCeil(prefixBr.get()) == TermsEnum.SeekStatus.END) {
           endTerm = numTermsInField;
         } else {
           endTerm = (int) te.ord();
@@ -343,7 +346,7 @@ public class UnInvertedField extends Doc
           }
         }
       }
-      final CharsRef charsRef = new CharsRef();
+      final CharsRefBuilder charsRef = new CharsRefBuilder();
 
       int off=offset;
       int lim=limit>=0 ? limit : Integer.MAX_VALUE;
@@ -623,7 +626,7 @@ public class UnInvertedField extends Doc
 
   }
 
-  String getReadableValue(BytesRef termval, FieldType ft, CharsRef charsRef) {
+  String getReadableValue(BytesRef termval, FieldType ft, CharsRefBuilder charsRef) {
     return ft.indexedToReadable(termval, charsRef).toString();
   }
 

Modified: lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/response/PHPSerializedResponseWriter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/response/PHPSerializedResponseWriter.java?rev=1617695&r1=1617694&r2=1617695&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/response/PHPSerializedResponseWriter.java (original)
+++ lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/response/PHPSerializedResponseWriter.java Wed Aug 13 09:36:54 2014
@@ -24,6 +24,7 @@ import java.util.Collection;
 import java.util.Iterator;
 import java.util.LinkedHashMap;
 
+import org.apache.lucene.util.ArrayUtil;
 import org.apache.lucene.util.BytesRef;
 import org.apache.lucene.util.UnicodeUtil;
 import org.apache.solr.common.SolrDocument;
@@ -68,11 +69,11 @@ public class PHPSerializedResponseWriter
 }
 
 class PHPSerializedWriter extends JSONWriter {
-  final BytesRef utf8;
+  byte[] utf8;
 
   public PHPSerializedWriter(Writer writer, SolrQueryRequest req, SolrQueryResponse rsp) {
     super(writer, req, rsp);
-    this.utf8 = new BytesRef();
+    this.utf8 = BytesRef.EMPTY_BYTES;
     // never indent serialized PHP data
     doIndent = false;
   }
@@ -267,8 +268,8 @@ class PHPSerializedWriter extends JSONWr
   public void writeStr(String name, String val, boolean needsEscaping) throws IOException {
     // serialized PHP strings don't need to be escaped at all, however the 
     // string size reported needs be the number of bytes rather than chars.
-    UnicodeUtil.UTF16toUTF8(val, 0, val.length(), utf8);
-    int nBytes = utf8.length;
+    utf8 = ArrayUtil.grow(utf8, val.length() * UnicodeUtil.MAX_UTF8_BYTES_PER_CHAR);
+    final int nBytes = UnicodeUtil.UTF16toUTF8(val, 0, val.length(), utf8);
 
     writer.write("s:");
     writer.write(Integer.toString(nBytes));

Modified: lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/schema/BoolField.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/schema/BoolField.java?rev=1617695&r1=1617694&r2=1617695&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/schema/BoolField.java (original)
+++ lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/schema/BoolField.java Wed Aug 13 09:36:54 2014
@@ -35,6 +35,7 @@ import org.apache.lucene.search.FieldCac
 import org.apache.lucene.search.SortField;
 import org.apache.lucene.util.BytesRef;
 import org.apache.lucene.util.CharsRef;
+import org.apache.lucene.util.CharsRefBuilder;
 import org.apache.lucene.util.mutable.MutableValue;
 import org.apache.lucene.util.mutable.MutableValueBool;
 import org.apache.solr.analysis.SolrAnalyzer;
@@ -137,13 +138,13 @@ public class BoolField extends Primitive
   private static final CharsRef FALSE = new CharsRef("false");
   
   @Override
-  public CharsRef indexedToReadable(BytesRef input, CharsRef charsRef) {
+  public CharsRef indexedToReadable(BytesRef input, CharsRefBuilder charsRef) {
     if (input.length > 0 && input.bytes[input.offset] == 'T') {
       charsRef.copyChars(TRUE);
     } else {
       charsRef.copyChars(FALSE);
     }
-    return charsRef;
+    return charsRef.get();
   }
 
   @Override

Modified: lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/schema/DateField.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/schema/DateField.java?rev=1617695&r1=1617694&r2=1617695&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/schema/DateField.java (original)
+++ lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/schema/DateField.java Wed Aug 13 09:36:54 2014
@@ -28,6 +28,7 @@ import org.apache.lucene.queries.functio
 import org.apache.lucene.queries.function.valuesource.FieldCacheSource;
 import org.apache.lucene.util.BytesRef;
 import org.apache.lucene.util.CharsRef;
+import org.apache.lucene.util.CharsRefBuilder;
 import org.apache.lucene.util.UnicodeUtil;
 import org.apache.solr.common.SolrException;
 import org.apache.solr.common.util.DateUtil;
@@ -216,10 +217,10 @@ public class DateField extends Primitive
   }
 
   @Override
-  public CharsRef indexedToReadable(BytesRef input, CharsRef charsRef) {
-    UnicodeUtil.UTF8toUTF16(input, charsRef);
+  public CharsRef indexedToReadable(BytesRef input, CharsRefBuilder charsRef) {
+    charsRef.copyUTF8Bytes(input);
     charsRef.append(Z_ARRAY, 0, 1);
-    return charsRef;
+    return charsRef.get();
   }
 
   @Override

Modified: lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/schema/EnumField.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/schema/EnumField.java?rev=1617695&r1=1617694&r2=1617695&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/schema/EnumField.java (original)
+++ lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/schema/EnumField.java Wed Aug 13 09:36:54 2014
@@ -24,7 +24,9 @@ import org.apache.lucene.queries.functio
 import org.apache.lucene.queries.function.valuesource.EnumFieldSource;
 import org.apache.lucene.search.*;
 import org.apache.lucene.util.BytesRef;
+import org.apache.lucene.util.BytesRefBuilder;
 import org.apache.lucene.util.CharsRef;
+import org.apache.lucene.util.CharsRefBuilder;
 import org.apache.lucene.util.NumericUtils;
 import org.apache.solr.common.EnumFieldValue;
 import org.apache.solr.common.SolrException;
@@ -43,9 +45,9 @@ import javax.xml.xpath.XPath;
 import javax.xml.xpath.XPathConstants;
 import javax.xml.xpath.XPathExpressionException;
 import javax.xml.xpath.XPathFactory;
+
 import java.io.IOException;
 import java.io.InputStream;
-
 import java.util.HashMap;
 import java.util.Locale;
 import java.util.Map;
@@ -263,16 +265,16 @@ public class EnumField extends Primitive
     if (val == null)
       return null;
 
-    final BytesRef bytes = new BytesRef(NumericUtils.BUF_SIZE_LONG);
+    final BytesRefBuilder bytes = new BytesRefBuilder();
     readableToIndexed(val, bytes);
-    return bytes.utf8ToString();
+    return bytes.get().utf8ToString();
   }
 
   /**
    * {@inheritDoc}
    */
   @Override
-  public void readableToIndexed(CharSequence val, BytesRef result) {
+  public void readableToIndexed(CharSequence val, BytesRefBuilder result) {
     final String s = val.toString();
     if (s == null)
       return;
@@ -317,13 +319,13 @@ public class EnumField extends Primitive
    * {@inheritDoc}
    */
   @Override
-  public CharsRef indexedToReadable(BytesRef input, CharsRef output) {
+  public CharsRef indexedToReadable(BytesRef input, CharsRefBuilder output) {
     final Integer intValue = NumericUtils.prefixCodedToInt(input);
     final String stringValue = intValueToStringValue(intValue);
     output.grow(stringValue.length());
-    output.length = stringValue.length();
-    stringValue.getChars(0, output.length, output.chars, 0);
-    return output;
+    output.setLength(stringValue.length());
+    stringValue.getChars(0, output.length(), output.chars(), 0);
+    return output.get();
   }
 
   /**
@@ -344,9 +346,9 @@ public class EnumField extends Primitive
     final Number val = f.numericValue();
     if (val == null)
       return null;
-    final BytesRef bytes = new BytesRef(NumericUtils.BUF_SIZE_LONG);
+    final BytesRefBuilder bytes = new BytesRefBuilder();
     NumericUtils.intToPrefixCoded(val.intValue(), 0, bytes);
-    return bytes.utf8ToString();
+    return bytes.get().utf8ToString();
   }
 
   /**

Modified: lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/schema/FieldType.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/schema/FieldType.java?rev=1617695&r1=1617694&r2=1617695&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/schema/FieldType.java (original)
+++ lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/schema/FieldType.java Wed Aug 13 09:36:54 2014
@@ -42,7 +42,9 @@ import org.apache.lucene.search.TermQuer
 import org.apache.lucene.search.TermRangeQuery;
 import org.apache.lucene.search.similarities.Similarity;
 import org.apache.lucene.util.BytesRef;
+import org.apache.lucene.util.BytesRefBuilder;
 import org.apache.lucene.util.CharsRef;
+import org.apache.lucene.util.CharsRefBuilder;
 import org.apache.lucene.util.UnicodeUtil;
 import org.apache.solr.analysis.SolrAnalyzer;
 import org.apache.solr.analysis.TokenizerChain;
@@ -358,7 +360,7 @@ public abstract class FieldType extends 
   }
 
   public Object toObject(SchemaField sf, BytesRef term) {
-    final CharsRef ref = new CharsRef(term.length);
+    final CharsRefBuilder ref = new CharsRefBuilder();
     indexedToReadable(term, ref);
     final IndexableField f = createField(sf, ref.toString(), 1.0f);
     return toObject(f);
@@ -370,9 +372,9 @@ public abstract class FieldType extends 
   }
 
   /** Given an indexed term, append the human readable representation*/
-  public CharsRef indexedToReadable(BytesRef input, CharsRef output) {
-    UnicodeUtil.UTF8toUTF16(input, output);
-    return output;
+  public CharsRef indexedToReadable(BytesRef input, CharsRefBuilder output) {
+    output.copyUTF8Bytes(input);
+    return output.get();
   }
 
   /** Given the stored field, return the human readable representation */
@@ -394,9 +396,9 @@ public abstract class FieldType extends 
   }
 
   /** Given the readable value, return the term value that will match it. */
-  public void readableToIndexed(CharSequence val, BytesRef result) {
+  public void readableToIndexed(CharSequence val, BytesRefBuilder result) {
     final String internal = readableToIndexed(val.toString());
-    UnicodeUtil.UTF16toUTF8(internal, 0, internal.length(), result);
+    result.copyChars(internal);
   }
 
   public void setIsExplicitQueryAnalyzer(boolean isExplicitQueryAnalyzer) {
@@ -746,13 +748,13 @@ public abstract class FieldType extends 
    * 
    */
   public Query getFieldQuery(QParser parser, SchemaField field, String externalVal) {
-    BytesRef br = new BytesRef();
+    BytesRefBuilder br = new BytesRefBuilder();
     readableToIndexed(externalVal, br);
     if (field.hasDocValues() && !field.indexed()) {
       // match-only
       return getRangeQuery(parser, field, externalVal, externalVal, true, true);
     } else {
-      return new TermQuery(new Term(field.getName(), br));
+      return new TermQuery(new Term(field.getName(), br.toBytesRef()));
     }
   }
   
@@ -1008,8 +1010,8 @@ public abstract class FieldType extends 
     if (null == value) {
       return null;
     }
-    CharsRef spare = new CharsRef();
-    UnicodeUtil.UTF8toUTF16((BytesRef)value, spare);
+    CharsRefBuilder spare = new CharsRefBuilder();
+    spare.copyUTF8Bytes((BytesRef)value);
     return spare.toString();
   }
 
@@ -1020,10 +1022,10 @@ public abstract class FieldType extends 
     if (null == value) {
       return null;
     }
-    BytesRef spare = new BytesRef();
+    BytesRefBuilder spare = new BytesRefBuilder();
     String stringVal = (String)value;
-    UnicodeUtil.UTF16toUTF8(stringVal, 0, stringVal.length(), spare);
-    return spare;
+    spare.copyChars(stringVal);
+    return spare.get();
   }
 
   /**

Modified: lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/schema/SortableDoubleField.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/schema/SortableDoubleField.java?rev=1617695&r1=1617694&r2=1617695&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/schema/SortableDoubleField.java (original)
+++ lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/schema/SortableDoubleField.java Wed Aug 13 09:36:54 2014
@@ -23,8 +23,9 @@ import org.apache.lucene.queries.functio
 import org.apache.lucene.queries.function.valuesource.FieldCacheSource;
 import org.apache.lucene.search.SortField;
 import org.apache.lucene.util.BytesRef;
+import org.apache.lucene.util.BytesRefBuilder;
 import org.apache.lucene.util.CharsRef;
-import org.apache.lucene.util.UnicodeUtil;
+import org.apache.lucene.util.CharsRefBuilder;
 import org.apache.lucene.util.mutable.MutableValue;
 import org.apache.lucene.util.mutable.MutableValueDouble;
 import org.apache.solr.search.QParser;
@@ -35,6 +36,7 @@ import org.apache.solr.response.TextResp
 
 import java.util.Map;
 import java.io.IOException;
+
 /**
  * A legacy numeric field type that encodes "Double" values as Strings such 
  * that Term enumeration order matches the natural numeric order.  This class 
@@ -86,12 +88,12 @@ public class SortableDoubleField extends
   }
 
   @Override
-  public CharsRef indexedToReadable(BytesRef input, CharsRef charsRef) {
+  public CharsRef indexedToReadable(BytesRef input, CharsRefBuilder charsRef) {
     // TODO: this could be more efficient, but the sortable types should be deprecated instead
-    UnicodeUtil.UTF8toUTF16(input, charsRef);
+    charsRef.copyUTF8Bytes(input);
     final char[] indexedToReadable = indexedToReadable(charsRef.toString()).toCharArray();
     charsRef.copyChars(indexedToReadable, 0, indexedToReadable.length);
-    return charsRef;
+    return charsRef.get();
   }
 
   @Override
@@ -105,9 +107,9 @@ public class SortableDoubleField extends
     if (null == value) {
       return null;
     }
-    CharsRef chars = new CharsRef();
-    UnicodeUtil.UTF8toUTF16((BytesRef)value, chars);
-    return NumberUtils.SortableStr2double(chars.toString());
+    CharsRefBuilder chars = new CharsRefBuilder();
+    chars.copyUTF8Bytes((BytesRef) value);
+    return NumberUtils.SortableStr2double(chars.get().toString());
   }
 
   @Override
@@ -116,9 +118,9 @@ public class SortableDoubleField extends
       return null;
     }
     String sortableString = NumberUtils.double2sortableStr(value.toString());
-    BytesRef bytes = new BytesRef();
-    UnicodeUtil.UTF16toUTF8(sortableString, 0, sortableString.length(), bytes);
-    return bytes;
+    BytesRefBuilder bytes = new BytesRefBuilder();
+    bytes.copyChars(sortableString);
+    return bytes.get();
   }
 }
 

Modified: lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/schema/SortableFloatField.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/schema/SortableFloatField.java?rev=1617695&r1=1617694&r2=1617695&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/schema/SortableFloatField.java (original)
+++ lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/schema/SortableFloatField.java Wed Aug 13 09:36:54 2014
@@ -23,7 +23,9 @@ import org.apache.lucene.queries.functio
 import org.apache.lucene.queries.function.valuesource.FieldCacheSource;
 import org.apache.lucene.search.SortField;
 import org.apache.lucene.util.BytesRef;
+import org.apache.lucene.util.BytesRefBuilder;
 import org.apache.lucene.util.CharsRef;
+import org.apache.lucene.util.CharsRefBuilder;
 import org.apache.lucene.util.UnicodeUtil;
 import org.apache.lucene.util.mutable.MutableValue;
 import org.apache.lucene.util.mutable.MutableValueFloat;
@@ -87,12 +89,12 @@ public class SortableFloatField extends 
   }
 
   @Override
-  public CharsRef indexedToReadable(BytesRef input, CharsRef charsRef) {
+  public CharsRef indexedToReadable(BytesRef input, CharsRefBuilder charsRef) {
     // TODO: this could be more efficient, but the sortable types should be deprecated instead
-    UnicodeUtil.UTF8toUTF16(input, charsRef);
+    charsRef.copyUTF8Bytes(input);
     final char[] indexedToReadable = indexedToReadable(charsRef.toString()).toCharArray();
     charsRef.copyChars(indexedToReadable, 0, indexedToReadable.length);
-    return charsRef;
+    return charsRef.get();
   }
 
   @Override
@@ -106,9 +108,9 @@ public class SortableFloatField extends 
     if (null == value) {
       return null;
     }
-    CharsRef chars = new CharsRef();
-    UnicodeUtil.UTF8toUTF16((BytesRef)value, chars);
-    return NumberUtils.SortableStr2float(chars.toString());
+    CharsRefBuilder chars = new CharsRefBuilder();
+    chars.copyUTF8Bytes((BytesRef)value);
+    return NumberUtils.SortableStr2float(chars.get().toString());
   }
 
   @Override
@@ -117,9 +119,9 @@ public class SortableFloatField extends 
       return null;
     }
     String sortableString = NumberUtils.float2sortableStr(value.toString());
-    BytesRef bytes = new BytesRef();
-    UnicodeUtil.UTF16toUTF8(sortableString, 0, sortableString.length(), bytes);
-    return bytes;
+    BytesRefBuilder bytes = new BytesRefBuilder();
+    bytes.copyChars(sortableString);
+    return bytes.get();
   }
 }
 

Modified: lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/schema/SortableIntField.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/schema/SortableIntField.java?rev=1617695&r1=1617694&r2=1617695&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/schema/SortableIntField.java (original)
+++ lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/schema/SortableIntField.java Wed Aug 13 09:36:54 2014
@@ -23,7 +23,9 @@ import org.apache.lucene.queries.functio
 import org.apache.lucene.queries.function.valuesource.FieldCacheSource;
 import org.apache.lucene.search.SortField;
 import org.apache.lucene.util.BytesRef;
+import org.apache.lucene.util.BytesRefBuilder;
 import org.apache.lucene.util.CharsRef;
+import org.apache.lucene.util.CharsRefBuilder;
 import org.apache.lucene.util.UnicodeUtil;
 import org.apache.lucene.util.mutable.MutableValue;
 import org.apache.lucene.util.mutable.MutableValueInt;
@@ -85,12 +87,12 @@ public class SortableIntField extends Pr
   }
 
   @Override
-  public CharsRef indexedToReadable(BytesRef input, CharsRef charsRef) {
+  public CharsRef indexedToReadable(BytesRef input, CharsRefBuilder charsRef) {
     // TODO: this could be more efficient, but the sortable types should be deprecated instead
-    UnicodeUtil.UTF8toUTF16(input, charsRef);
-    final char[] indexedToReadable = indexedToReadable(charsRef.toString()).toCharArray();
+    charsRef.copyUTF8Bytes(input);
+    final char[] indexedToReadable = indexedToReadable(charsRef.get().toString()).toCharArray();
     charsRef.copyChars(indexedToReadable, 0, indexedToReadable.length);
-    return charsRef;
+    return charsRef.get();
   }
 
   @Override
@@ -109,8 +111,8 @@ public class SortableIntField extends Pr
     if (null == value) { 
       return null;
     }
-    CharsRef chars = new CharsRef();
-    UnicodeUtil.UTF8toUTF16((BytesRef)value, chars);
+    CharsRefBuilder chars = new CharsRefBuilder();
+    chars.copyUTF8Bytes((BytesRef)value);
     return NumberUtils.SortableStr2int(chars.toString());
   }
 
@@ -120,9 +122,9 @@ public class SortableIntField extends Pr
       return null;
     }
     String sortableString = NumberUtils.int2sortableStr(value.toString());
-    BytesRef bytes = new BytesRef();
-    UnicodeUtil.UTF16toUTF8(sortableString, 0, sortableString.length(), bytes);
-    return bytes;
+    BytesRefBuilder bytes = new BytesRefBuilder();
+    bytes.copyChars(sortableString);
+    return bytes.get();
   }
 }
 

Modified: lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/schema/SortableLongField.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/schema/SortableLongField.java?rev=1617695&r1=1617694&r2=1617695&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/schema/SortableLongField.java (original)
+++ lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/schema/SortableLongField.java Wed Aug 13 09:36:54 2014
@@ -23,7 +23,9 @@ import org.apache.lucene.queries.functio
 import org.apache.lucene.queries.function.valuesource.FieldCacheSource;
 import org.apache.lucene.search.SortField;
 import org.apache.lucene.util.BytesRef;
+import org.apache.lucene.util.BytesRefBuilder;
 import org.apache.lucene.util.CharsRef;
+import org.apache.lucene.util.CharsRefBuilder;
 import org.apache.lucene.util.UnicodeUtil;
 import org.apache.lucene.util.mutable.MutableValue;
 import org.apache.lucene.util.mutable.MutableValueLong;
@@ -76,12 +78,12 @@ public class SortableLongField extends P
   }
 
   @Override
-  public CharsRef indexedToReadable(BytesRef input, CharsRef charsRef) {
+  public CharsRef indexedToReadable(BytesRef input, CharsRefBuilder charsRef) {
     // TODO: this could be more efficient, but the sortable types should be deprecated instead
-    UnicodeUtil.UTF8toUTF16(input, charsRef);
-    final char[] indexedToReadable = indexedToReadable(charsRef.toString()).toCharArray();
+    charsRef.copyUTF8Bytes(input);
+    final char[] indexedToReadable = indexedToReadable(charsRef.get().toString()).toCharArray();
     charsRef.copyChars(indexedToReadable, 0, indexedToReadable.length);
-    return charsRef;
+    return charsRef.get();
   }
 
   @Override
@@ -105,8 +107,8 @@ public class SortableLongField extends P
     if (null == value) {
       return null;
     }
-    CharsRef chars = new CharsRef();
-    UnicodeUtil.UTF8toUTF16((BytesRef)value, chars);
+    CharsRefBuilder chars = new CharsRefBuilder();
+    chars.copyUTF8Bytes((BytesRef) value);
     return NumberUtils.SortableStr2long(chars.toString());
   }
 
@@ -116,9 +118,9 @@ public class SortableLongField extends P
       return null;
     }
     String sortableString = NumberUtils.long2sortableStr(value.toString());
-    BytesRef bytes = new BytesRef();
-    UnicodeUtil.UTF16toUTF8(sortableString, 0, sortableString.length(), bytes);
-    return bytes;
+    BytesRefBuilder bytes = new BytesRefBuilder();
+    bytes.copyChars(sortableString);
+    return bytes.get();
   }
 }
 

Modified: lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/schema/TrieDateField.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/schema/TrieDateField.java?rev=1617695&r1=1617694&r2=1617695&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/schema/TrieDateField.java (original)
+++ lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/schema/TrieDateField.java Wed Aug 13 09:36:54 2014
@@ -30,6 +30,7 @@ import org.apache.lucene.search.Query;
 import org.apache.lucene.search.SortField;
 import org.apache.lucene.util.BytesRef;
 import org.apache.lucene.util.CharsRef;
+import org.apache.lucene.util.CharsRefBuilder;
 import org.apache.solr.response.TextResponseWriter;
 import org.apache.solr.search.QParser;
 import org.apache.solr.update.processor.TimestampUpdateProcessorFactory; //jdoc
@@ -155,7 +156,7 @@ public class TrieDateField extends DateF
     return wrappedField.indexedToReadable(_indexedForm);
   }
   @Override
-  public CharsRef indexedToReadable(BytesRef input, CharsRef charsRef) {
+  public CharsRef indexedToReadable(BytesRef input, CharsRefBuilder charsRef) {
     // TODO: this could be more efficient, but the sortable types should be deprecated instead
     return wrappedField.indexedToReadable(input, charsRef);
   }

Modified: lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/schema/TrieField.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/schema/TrieField.java?rev=1617695&r1=1617694&r2=1617695&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/schema/TrieField.java (original)
+++ lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/schema/TrieField.java Wed Aug 13 09:36:54 2014
@@ -45,7 +45,9 @@ import org.apache.lucene.search.NumericR
 import org.apache.lucene.search.Query;
 import org.apache.lucene.search.SortField;
 import org.apache.lucene.util.BytesRef;
+import org.apache.lucene.util.BytesRefBuilder;
 import org.apache.lucene.util.CharsRef;
+import org.apache.lucene.util.CharsRefBuilder;
 import org.apache.lucene.util.NumericUtils;
 import org.apache.lucene.util.mutable.MutableValueDate;
 import org.apache.lucene.util.mutable.MutableValueLong;
@@ -374,13 +376,13 @@ public class TrieField extends Primitive
   @Override
   public String readableToIndexed(String val) {
     // TODO: Numeric should never be handled as String, that may break in future lucene versions! Change to use BytesRef for term texts!
-    final BytesRef bytes = new BytesRef(NumericUtils.BUF_SIZE_LONG);
+    final BytesRefBuilder bytes = new BytesRefBuilder();
     readableToIndexed(val, bytes);
-    return bytes.utf8ToString();
+    return bytes.get().utf8ToString();
   }
 
   @Override
-  public void readableToIndexed(CharSequence val, BytesRef result) {
+  public void readableToIndexed(CharSequence val, BytesRefBuilder result) {
     String s = val.toString();
     try {
       switch (type) {
@@ -445,7 +447,7 @@ public class TrieField extends Primitive
   }
 
   @Override
-  public CharsRef indexedToReadable(BytesRef indexedForm, CharsRef charsRef) {
+  public CharsRef indexedToReadable(BytesRef indexedForm, CharsRefBuilder charsRef) {
     final String value;
     switch (type) {
       case INTEGER:
@@ -467,9 +469,9 @@ public class TrieField extends Primitive
         throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Unknown type for trie field: " + type);
     }
     charsRef.grow(value.length());
-    charsRef.length = value.length();
-    value.getChars(0, charsRef.length, charsRef.chars, 0);
-    return charsRef;
+    charsRef.setLength(value.length());
+    value.getChars(0, charsRef.length(), charsRef.chars(), 0);
+    return charsRef.get();
   }
 
   @Override
@@ -492,7 +494,7 @@ public class TrieField extends Primitive
 
   @Override
   public String storedToIndexed(IndexableField f) {
-    final BytesRef bytes = new BytesRef(NumericUtils.BUF_SIZE_LONG);
+    final BytesRefBuilder bytes = new BytesRefBuilder();
     final Number val = f.numericValue();
     if (val != null) {
       switch (type) {
@@ -547,7 +549,7 @@ public class TrieField extends Primitive
           throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Unknown type for trie field: " + f.name());
       }
     }
-    return bytes.utf8ToString();
+    return bytes.get().utf8ToString();
   }
   
   @Override
@@ -639,9 +641,9 @@ public class TrieField extends Primitive
       fields.add(field);
       
       if (sf.multiValued()) {
-        BytesRef bytes = new BytesRef();
+        BytesRefBuilder bytes = new BytesRefBuilder();
         readableToIndexed(value.toString(), bytes);
-        fields.add(new SortedSetDocValuesField(sf.getName(), bytes));
+        fields.add(new SortedSetDocValuesField(sf.getName(), bytes.get()));
       } else {
         final long bits;
         if (field.numericValue() instanceof Integer || field.numericValue() instanceof Long) {

Modified: lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/search/CursorMark.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/search/CursorMark.java?rev=1617695&r1=1617694&r2=1617695&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/search/CursorMark.java (original)
+++ lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/search/CursorMark.java Wed Aug 13 09:36:54 2014
@@ -26,9 +26,12 @@ import org.apache.lucene.search.Sort;
 import org.apache.lucene.search.SortField;
 import org.apache.lucene.search.Query;
 import org.apache.lucene.util.BytesRef;
+import org.apache.lucene.util.BytesRefBuilder;
 import org.apache.solr.common.SolrException;
 import org.apache.solr.common.SolrException.ErrorCode;
+
 import static org.apache.solr.common.params.CursorMarkParams.*;
+
 import org.apache.solr.common.util.Base64;
 import org.apache.solr.common.util.JavaBinCodec;
 import org.apache.solr.schema.IndexSchema;
@@ -200,6 +203,16 @@ public final class CursorMark {
       ByteArrayInputStream in = new ByteArrayInputStream(rawData);
       try {
         pieces = (List<Object>) codec.unmarshal(in);
+        boolean b = false;
+        for (Object o : pieces) {
+          if (o instanceof BytesRefBuilder || o instanceof BytesRef || o instanceof String) {
+            b = true; break;
+          }
+        }
+        if (b) {
+          in.reset();
+          pieces = (List<Object>) codec.unmarshal(in);
+        }
       } finally {
         in.close();
       }

Modified: lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/search/QueryParsing.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/search/QueryParsing.java?rev=1617695&r1=1617694&r2=1617695&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/search/QueryParsing.java (original)
+++ lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/search/QueryParsing.java Wed Aug 13 09:36:54 2014
@@ -34,6 +34,7 @@ import org.apache.lucene.search.TermRang
 import org.apache.lucene.search.WildcardQuery;
 import org.apache.lucene.util.BytesRef;
 import org.apache.lucene.util.CharsRef;
+import org.apache.lucene.util.CharsRefBuilder;
 import org.apache.solr.common.SolrException;
 import org.apache.solr.common.params.MapSolrParams;
 import org.apache.solr.common.params.SolrParams;
@@ -42,6 +43,7 @@ import org.apache.solr.request.SolrQuery
 import org.apache.solr.schema.FieldType;
 import org.apache.solr.schema.IndexSchema;
 import org.apache.solr.schema.SchemaField;
+
 import java.io.IOException;
 import java.util.Collections;
 import java.util.ArrayList;
@@ -421,9 +423,9 @@ public class QueryParsing {
   static void writeFieldVal(BytesRef val, FieldType ft, Appendable out, int flags) throws IOException {
     if (ft != null) {
       try {
-        CharsRef readable = new CharsRef();
+        CharsRefBuilder readable = new CharsRefBuilder();
         ft.indexedToReadable(val, readable);
-        out.append(readable);
+        out.append(readable.get());
       } catch (Exception e) {
         out.append("EXCEPTION(val=");
         out.append(val.utf8ToString());

Modified: lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/search/TermQParserPlugin.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/search/TermQParserPlugin.java?rev=1617695&r1=1617694&r2=1617695&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/search/TermQParserPlugin.java (original)
+++ lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/search/TermQParserPlugin.java Wed Aug 13 09:36:54 2014
@@ -19,7 +19,7 @@ package org.apache.solr.search;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.search.Query;
 import org.apache.lucene.search.TermQuery;
-import org.apache.lucene.util.BytesRef;
+import org.apache.lucene.util.BytesRefBuilder;
 import org.apache.solr.common.params.SolrParams;
 import org.apache.solr.common.util.NamedList;
 import org.apache.solr.request.SolrQueryRequest;
@@ -55,13 +55,13 @@ public class TermQParserPlugin extends Q
         String fname = localParams.get(QueryParsing.F);
         FieldType ft = req.getSchema().getFieldTypeNoEx(fname);
         String val = localParams.get(QueryParsing.V);
-        BytesRef term = new BytesRef();
+        BytesRefBuilder term = new BytesRefBuilder();
         if (ft != null) {
           ft.readableToIndexed(val, term);
         } else {
           term.copyChars(val);
         }
-        return new TermQuery(new Term(fname, term));
+        return new TermQuery(new Term(fname, term.get()));
       }
     };
   }