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 [6/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/core/src/test/org/apache/lucene/util/TestNumericUtils.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/util/TestNumericUtils.java?rev=1617695&r1=1617694&r2=1617695&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/util/TestNumericUtils.java (original)
+++ lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/util/TestNumericUtils.java Wed Aug 13 09:36:54 2014
@@ -26,37 +26,37 @@ public class TestNumericUtils extends Lu
 
   public void testLongConversionAndOrdering() throws Exception {
     // generate a series of encoded longs, each numerical one bigger than the one before
-    BytesRef last=null, act=new BytesRef(NumericUtils.BUF_SIZE_LONG);
+    BytesRefBuilder last = new BytesRefBuilder();
+    BytesRefBuilder act = new BytesRefBuilder();
     for (long l=-100000L; l<100000L; l++) {
       NumericUtils.longToPrefixCodedBytes(l, 0, act);
       if (last!=null) {
         // test if smaller
-        assertTrue("actual bigger than last (BytesRef)", last.compareTo(act) < 0 );
-        assertTrue("actual bigger than last (as String)", last.utf8ToString().compareTo(act.utf8ToString()) < 0 );
+        assertTrue("actual bigger than last (BytesRef)", last.get().compareTo(act.get()) < 0 );
+        assertTrue("actual bigger than last (as String)", last.get().utf8ToString().compareTo(act.get().utf8ToString()) < 0 );
       }
       // test is back and forward conversion works
-      assertEquals("forward and back conversion should generate same long", l, NumericUtils.prefixCodedToLong(act));
+      assertEquals("forward and back conversion should generate same long", l, NumericUtils.prefixCodedToLong(act.get()));
       // next step
-      last = act;
-      act = new BytesRef(NumericUtils.BUF_SIZE_LONG);
+      last.copyBytes(act);
     }
   }
 
   public void testIntConversionAndOrdering() throws Exception {
     // generate a series of encoded ints, each numerical one bigger than the one before
-    BytesRef last=null, act=new BytesRef(NumericUtils.BUF_SIZE_INT);
+    BytesRefBuilder act = new BytesRefBuilder();
+    BytesRefBuilder last = new BytesRefBuilder();
     for (int i=-100000; i<100000; i++) {
       NumericUtils.intToPrefixCodedBytes(i, 0, act);
       if (last!=null) {
         // test if smaller
-        assertTrue("actual bigger than last (BytesRef)", last.compareTo(act) < 0 );
-        assertTrue("actual bigger than last (as String)", last.utf8ToString().compareTo(act.utf8ToString()) < 0 );
+        assertTrue("actual bigger than last (BytesRef)", last.get().compareTo(act.get()) < 0 );
+        assertTrue("actual bigger than last (as String)", last.get().utf8ToString().compareTo(act.get().utf8ToString()) < 0 );
       }
       // test is back and forward conversion works
-      assertEquals("forward and back conversion should generate same int", i, NumericUtils.prefixCodedToInt(act));
+      assertEquals("forward and back conversion should generate same int", i, NumericUtils.prefixCodedToInt(act.get()));
       // next step
-      last=act;
-      act = new BytesRef(NumericUtils.BUF_SIZE_INT);
+      last.copyBytes(act.get());
     }
   }
 
@@ -65,18 +65,18 @@ public class TestNumericUtils extends Lu
       Long.MIN_VALUE, Long.MIN_VALUE+1, Long.MIN_VALUE+2, -5003400000000L,
       -4000L, -3000L, -2000L, -1000L, -1L, 0L, 1L, 10L, 300L, 50006789999999999L, Long.MAX_VALUE-2, Long.MAX_VALUE-1, Long.MAX_VALUE
     };
-    BytesRef[] prefixVals=new BytesRef[vals.length];
+    BytesRefBuilder[] prefixVals = new BytesRefBuilder[vals.length];
     
     for (int i=0; i<vals.length; i++) {
-      prefixVals[i] = new BytesRef(NumericUtils.BUF_SIZE_LONG);
+      prefixVals[i] = new BytesRefBuilder();
       NumericUtils.longToPrefixCodedBytes(vals[i], 0, prefixVals[i]);
       
       // check forward and back conversion
-      assertEquals( "forward and back conversion should generate same long", vals[i], NumericUtils.prefixCodedToLong(prefixVals[i]) );
+      assertEquals( "forward and back conversion should generate same long", vals[i], NumericUtils.prefixCodedToLong(prefixVals[i].get()) );
 
       // test if decoding values as int fails correctly
       try {
-        NumericUtils.prefixCodedToInt(prefixVals[i]);
+        NumericUtils.prefixCodedToInt(prefixVals[i].get());
         fail("decoding a prefix coded long value as int should fail");
       } catch (NumberFormatException e) {
         // worked
@@ -85,15 +85,15 @@ public class TestNumericUtils extends Lu
     
     // check sort order (prefixVals should be ascending)
     for (int i=1; i<prefixVals.length; i++) {
-      assertTrue( "check sort order", prefixVals[i-1].compareTo(prefixVals[i]) < 0 );
+      assertTrue( "check sort order", prefixVals[i-1].get().compareTo(prefixVals[i].get()) < 0 );
     }
         
     // check the prefix encoding, lower precision should have the difference to original value equal to the lower removed bits
-    final BytesRef ref = new BytesRef(NumericUtils.BUF_SIZE_LONG);
+    final BytesRefBuilder ref = new BytesRefBuilder();
     for (int i=0; i<vals.length; i++) {
       for (int j=0; j<64; j++) {
         NumericUtils.longToPrefixCodedBytes(vals[i], j, ref);
-        long prefixVal=NumericUtils.prefixCodedToLong(ref);
+        long prefixVal=NumericUtils.prefixCodedToLong(ref.get());
         long mask=(1L << j) - 1L;
         assertEquals( "difference between prefix val and original value for "+vals[i]+" with shift="+j, vals[i] & mask, vals[i]-prefixVal );
       }
@@ -105,18 +105,18 @@ public class TestNumericUtils extends Lu
       Integer.MIN_VALUE, Integer.MIN_VALUE+1, Integer.MIN_VALUE+2, -64765767,
       -4000, -3000, -2000, -1000, -1, 0, 1, 10, 300, 765878989, Integer.MAX_VALUE-2, Integer.MAX_VALUE-1, Integer.MAX_VALUE
     };
-    BytesRef[] prefixVals=new BytesRef[vals.length];
+    BytesRefBuilder[] prefixVals=new BytesRefBuilder[vals.length];
     
     for (int i=0; i<vals.length; i++) {
-      prefixVals[i] = new BytesRef(NumericUtils.BUF_SIZE_INT);
+      prefixVals[i] = new BytesRefBuilder();
       NumericUtils.intToPrefixCodedBytes(vals[i], 0, prefixVals[i]);
       
       // check forward and back conversion
-      assertEquals( "forward and back conversion should generate same int", vals[i], NumericUtils.prefixCodedToInt(prefixVals[i]) );
+      assertEquals( "forward and back conversion should generate same int", vals[i], NumericUtils.prefixCodedToInt(prefixVals[i].get()) );
       
       // test if decoding values as long fails correctly
       try {
-        NumericUtils.prefixCodedToLong(prefixVals[i]);
+        NumericUtils.prefixCodedToLong(prefixVals[i].get());
         fail("decoding a prefix coded int value as long should fail");
       } catch (NumberFormatException e) {
         // worked
@@ -125,15 +125,15 @@ public class TestNumericUtils extends Lu
     
     // check sort order (prefixVals should be ascending)
     for (int i=1; i<prefixVals.length; i++) {
-      assertTrue( "check sort order", prefixVals[i-1].compareTo(prefixVals[i]) < 0 );
+      assertTrue( "check sort order", prefixVals[i-1].get().compareTo(prefixVals[i].get()) < 0 );
     }
     
     // check the prefix encoding, lower precision should have the difference to original value equal to the lower removed bits
-    final BytesRef ref = new BytesRef(NumericUtils.BUF_SIZE_LONG);
+    final BytesRefBuilder ref = new BytesRefBuilder();
     for (int i=0; i<vals.length; i++) {
       for (int j=0; j<32; j++) {
         NumericUtils.intToPrefixCodedBytes(vals[i], j, ref);
-        int prefixVal=NumericUtils.prefixCodedToInt(ref);
+        int prefixVal=NumericUtils.prefixCodedToInt(ref.get());
         int mask=(1 << j) - 1;
         assertEquals( "difference between prefix val and original value for "+vals[i]+" with shift="+j, vals[i] & mask, vals[i]-prefixVal );
       }

Modified: lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/util/TestUnicodeUtil.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/util/TestUnicodeUtil.java?rev=1617695&r1=1617694&r2=1617695&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/util/TestUnicodeUtil.java (original)
+++ lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/util/TestUnicodeUtil.java Wed Aug 13 09:36:54 2014
@@ -108,13 +108,13 @@ public class TestUnicodeUtil extends Luc
     assertEquals(2, UnicodeUtil.codePointCount(new BytesRef(asByteArray('z', 0xf0, 0xa4, 0xad, 0xa2))));
 
     // And do some random stuff.
-    BytesRef utf8 = new BytesRef(20);
     int num = atLeast(50000);
     for (int i = 0; i < num; i++) {
       final String s = TestUtil.randomUnicodeString(random());
-      UnicodeUtil.UTF16toUTF8(s, 0, s.length(), utf8);
+      final byte[] utf8 = new byte[s.length() * UnicodeUtil.MAX_UTF8_BYTES_PER_CHAR];
+      final int utf8Len = UnicodeUtil.UTF16toUTF8(s, 0, s.length(), utf8);
       assertEquals(s.codePointCount(0, s.length()),
-                   UnicodeUtil.codePointCount(utf8));
+                   UnicodeUtil.codePointCount(new BytesRef(utf8, 0, utf8Len)));
     }
   }
 
@@ -137,14 +137,15 @@ public class TestUnicodeUtil extends Luc
   }
 
   public void testUTF8toUTF32() {
-    BytesRef utf8 = new BytesRef(20);
-    IntsRef utf32 = new IntsRef(20);
+    int[] utf32 = new int[0];
     int[] codePoints = new int[20];
     int num = atLeast(50000);
     for (int i = 0; i < num; i++) {
       final String s = TestUtil.randomUnicodeString(random());
-      UnicodeUtil.UTF16toUTF8(s, 0, s.length(), utf8);
-      UnicodeUtil.UTF8toUTF32(utf8, utf32);
+      final byte[] utf8 = new byte[s.length() * UnicodeUtil.MAX_UTF8_BYTES_PER_CHAR];
+      final int utf8Len = UnicodeUtil.UTF16toUTF8(s, 0, s.length(), utf8);
+      utf32 = ArrayUtil.grow(utf32, utf8Len);
+      final int utf32Len = UnicodeUtil.UTF8toUTF32(new BytesRef(utf8, 0, utf8Len), utf32);
       
       int charUpto = 0;
       int intUpto = 0;
@@ -153,15 +154,15 @@ public class TestUnicodeUtil extends Luc
         codePoints[intUpto++] = cp;
         charUpto += Character.charCount(cp);
       }
-      if (!ArrayUtil.equals(codePoints, 0, utf32.ints, utf32.offset, intUpto)) {
+      if (!ArrayUtil.equals(codePoints, 0, utf32, 0, intUpto)) {
         System.out.println("FAILED");
         for(int j=0;j<s.length();j++) {
           System.out.println("  char[" + j + "]=" + Integer.toHexString(s.charAt(j)));
         }
         System.out.println();
-        assertEquals(intUpto, utf32.length);
+        assertEquals(intUpto, utf32Len);
         for(int j=0;j<intUpto;j++) {
-          System.out.println("  " + Integer.toHexString(utf32.ints[j]) + " vs " + Integer.toHexString(codePoints[j]));
+          System.out.println("  " + Integer.toHexString(utf32[j]) + " vs " + Integer.toHexString(codePoints[j]));
         }
         fail("mismatch");
       }
@@ -210,11 +211,8 @@ public class TestUnicodeUtil extends Luc
     for (int i = 0; i < num; i++) {
       String unicode = TestUtil.randomRealisticUnicodeString(random());
       BytesRef ref = new BytesRef(unicode);
-      char[] arr = new char[1 + random().nextInt(100)];
-      int offset = random().nextInt(arr.length);
-      int len = random().nextInt(arr.length - offset);
-      CharsRef cRef = new CharsRef(arr, offset, len);
-      UnicodeUtil.UTF8toUTF16(ref, cRef);
+      CharsRefBuilder cRef = new CharsRefBuilder();
+      cRef.copyUTF8Bytes(ref);
       assertEquals(cRef.toString(), unicode);
     }
   }

Modified: lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/util/automaton/TestAutomaton.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/util/automaton/TestAutomaton.java?rev=1617695&r1=1617694&r2=1617695&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/util/automaton/TestAutomaton.java (original)
+++ lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/util/automaton/TestAutomaton.java Wed Aug 13 09:36:54 2014
@@ -27,7 +27,9 @@ import java.util.List;
 import java.util.Set;
 
 import org.apache.lucene.util.BytesRef;
+import org.apache.lucene.util.BytesRefBuilder;
 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;
@@ -481,7 +483,7 @@ public class TestAutomaton extends Lucen
   private void assertMatches(Automaton a, String... strings) {
     Set<IntsRef> expected = new HashSet<>();
     for(String s : strings) {
-      IntsRef ints = new IntsRef();
+      IntsRefBuilder ints = new IntsRefBuilder();
       expected.add(Util.toUTF32(s, ints));
     }
 
@@ -679,10 +681,11 @@ public class TestAutomaton extends Lucen
           }
           Set<BytesRef> newTerms = new HashSet<>();
           BytesRef prefix = new BytesRef(getRandomString());
+          BytesRefBuilder newTerm = new BytesRefBuilder();
           for(BytesRef term : terms) {
-            BytesRef newTerm = BytesRef.deepCopyOf(prefix);
+            newTerm.copyBytes(prefix);
             newTerm.append(term);
-            newTerms.add(newTerm);
+            newTerms.add(newTerm.toBytesRef());
           }
           terms = newTerms;
           boolean wasDeterministic1 = a.isDeterministic();
@@ -699,10 +702,11 @@ public class TestAutomaton extends Lucen
             System.out.println("  op=concat suffix " + suffix);
           }
           Set<BytesRef> newTerms = new HashSet<>();
+          BytesRefBuilder newTerm = new BytesRefBuilder();
           for(BytesRef term : terms) {
-            BytesRef newTerm = BytesRef.deepCopyOf(term);
+            newTerm.copyBytes(term);
             newTerm.append(suffix);
-            newTerms.add(newTerm);
+            newTerms.add(newTerm.toBytesRef());
           }
           terms = newTerms;
           a = Operations.concatenate(a, Automata.makeString(suffix.utf8ToString()));
@@ -965,11 +969,12 @@ public class TestAutomaton extends Lucen
               System.out.println("  do suffix");
             }
             a = Operations.concatenate(a, randomNoOp(a2));
+            BytesRefBuilder newTerm = new BytesRefBuilder();
             for(BytesRef term : terms) {
               for(BytesRef suffix : addTerms) {
-                BytesRef newTerm = BytesRef.deepCopyOf(term);
+                newTerm.copyBytes(term);
                 newTerm.append(suffix);
-                newTerms.add(newTerm);
+                newTerms.add(newTerm.toBytesRef());
               }
             }
           } else {
@@ -978,11 +983,12 @@ public class TestAutomaton extends Lucen
               System.out.println("  do prefix");
             }
             a = Operations.concatenate(randomNoOp(a2), a);
+            BytesRefBuilder newTerm = new BytesRefBuilder();
             for(BytesRef term : terms) {
               for(BytesRef prefix : addTerms) {
-                BytesRef newTerm = BytesRef.deepCopyOf(prefix);
+                newTerm.copyBytes(prefix);
                 newTerm.append(term);
-                newTerms.add(newTerm);
+                newTerms.add(newTerm.toBytesRef());
               }
             }
           }
@@ -990,9 +996,11 @@ public class TestAutomaton extends Lucen
           terms = newTerms;
         }
         break;
+      default:
+        throw new AssertionError();
       }
 
-      // assertSame(terms, a);
+      assertSame(terms, a);
       assertEquals(AutomatonTestUtil.isDeterministicSlow(a), a.isDeterministic());
     }
 
@@ -1008,7 +1016,7 @@ public class TestAutomaton extends Lucen
       Automaton detA = Operations.determinize(a);
 
       // Make sure all terms are accepted:
-      IntsRef scratch = new IntsRef();
+      IntsRefBuilder scratch = new IntsRefBuilder();
       for(BytesRef term : terms) {
         Util.toIntsRef(term, scratch);
         assertTrue("failed to accept term=" + term.utf8ToString(), Operations.run(detA, term.utf8ToString()));
@@ -1017,9 +1025,9 @@ public class TestAutomaton extends Lucen
       // Use getFiniteStrings:
       Set<IntsRef> expected = new HashSet<>();
       for(BytesRef term : terms) {
-        IntsRef intsRef = new IntsRef();
+        IntsRefBuilder intsRef = new IntsRefBuilder();
         Util.toUTF32(term.utf8ToString(), intsRef);
-        expected.add(intsRef);
+        expected.add(intsRef.toIntsRef());
       }
       Set<IntsRef> actual = Operations.getFiniteStrings(a, -1);
 
@@ -1047,9 +1055,9 @@ public class TestAutomaton extends Lucen
     
       Set<IntsRef> expected2 = new HashSet<>();
       for(BytesRef term : terms) {
-        IntsRef intsRef = new IntsRef();
+        IntsRefBuilder intsRef = new IntsRefBuilder();
         Util.toIntsRef(term, intsRef);
-        expected2.add(intsRef);
+        expected2.add(intsRef.toIntsRef());
       }
       assertEquals(expected2, Operations.getFiniteStrings(utf8, -1));
     } catch (AssertionError ae) {

Modified: lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/util/automaton/TestCompiledAutomaton.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/util/automaton/TestCompiledAutomaton.java?rev=1617695&r1=1617694&r2=1617695&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/util/automaton/TestCompiledAutomaton.java (original)
+++ lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/util/automaton/TestCompiledAutomaton.java Wed Aug 13 09:36:54 2014
@@ -25,6 +25,7 @@ import java.util.List;
 import java.util.Set;
 
 import org.apache.lucene.util.BytesRef;
+import org.apache.lucene.util.BytesRefBuilder;
 import org.apache.lucene.util.LuceneTestCase;
 import org.apache.lucene.util.TestUtil;
 
@@ -42,7 +43,7 @@ public class TestCompiledAutomaton exten
 
   private void testFloor(CompiledAutomaton c, String input, String expected) {
     final BytesRef b = new BytesRef(input);
-    final BytesRef result = c.floor(b, b);
+    final BytesRef result = c.floor(b, new BytesRefBuilder());
     if (expected == null) {
       assertNull(result);
     } else {

Modified: lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/util/automaton/TestOperations.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/util/automaton/TestOperations.java?rev=1617695&r1=1617694&r2=1617695&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/util/automaton/TestOperations.java (original)
+++ lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/util/automaton/TestOperations.java Wed Aug 13 09:36:54 2014
@@ -21,6 +21,7 @@ import java.util.*;
 
 import org.apache.lucene.util.*;
 import org.apache.lucene.util.fst.Util;
+
 import com.carrotsearch.randomizedtesting.generators.RandomInts;
 
 public class TestOperations extends LuceneTestCase {
@@ -139,12 +140,12 @@ public class TestOperations extends Luce
     a = MinimizationOperations.minimize(a);
     Set<IntsRef> strings = getFiniteStrings(a, -1, true);
     assertEquals(2, strings.size());
-    IntsRef dog = new IntsRef();
+    IntsRefBuilder dog = new IntsRefBuilder();
     Util.toIntsRef(new BytesRef("dog"), dog);
-    assertTrue(strings.contains(dog));
-    IntsRef duck = new IntsRef();
+    assertTrue(strings.contains(dog.get()));
+    IntsRefBuilder duck = new IntsRefBuilder();
     Util.toIntsRef(new BytesRef("duck"), duck);
-    assertTrue(strings.contains(duck));
+    assertTrue(strings.contains(duck.get()));
   }
 
   public void testFiniteStringsEatsStack() {
@@ -156,11 +157,11 @@ public class TestOperations extends Luce
     Automaton a = Operations.union(Automata.makeString(bigString1), Automata.makeString(bigString2));
     Set<IntsRef> strings = getFiniteStrings(a, -1, false);
     assertEquals(2, strings.size());
-    IntsRef scratch = new IntsRef();
+    IntsRefBuilder scratch = new IntsRefBuilder();
     Util.toUTF32(bigString1.toCharArray(), 0, bigString1.length(), scratch);
-    assertTrue(strings.contains(scratch));
+    assertTrue(strings.contains(scratch.get()));
     Util.toUTF32(bigString2.toCharArray(), 0, bigString2.length(), scratch);
-    assertTrue(strings.contains(scratch));
+    assertTrue(strings.contains(scratch.get()));
   }
 
   public void testRandomFiniteStrings1() {
@@ -172,12 +173,12 @@ public class TestOperations extends Luce
 
     Set<IntsRef> strings = new HashSet<IntsRef>();
     List<Automaton> automata = new ArrayList<>();
+    IntsRefBuilder scratch = new IntsRefBuilder();
     for(int i=0;i<numStrings;i++) {
       String s = TestUtil.randomSimpleString(random(), 1, 200);
       automata.add(Automata.makeString(s));
-      IntsRef scratch = new IntsRef();
       Util.toUTF32(s.toCharArray(), 0, s.length(), scratch);
-      strings.add(scratch);
+      strings.add(scratch.toIntsRef());
       if (VERBOSE) {
         System.out.println("  add string=" + s);
       }
@@ -281,16 +282,16 @@ public class TestOperations extends Luce
   public void testSingletonNoLimit() {
     Set<IntsRef> result = Operations.getFiniteStrings(Automata.makeString("foobar"), -1);
     assertEquals(1, result.size());
-    IntsRef scratch = new IntsRef();
+    IntsRefBuilder scratch = new IntsRefBuilder();
     Util.toUTF32("foobar".toCharArray(), 0, 6, scratch);
-    assertTrue(result.contains(scratch));
+    assertTrue(result.contains(scratch.get()));
   }
 
   public void testSingletonLimit1() {
     Set<IntsRef> result = Operations.getFiniteStrings(Automata.makeString("foobar"), 1);
     assertEquals(1, result.size());
-    IntsRef scratch = new IntsRef();
+    IntsRefBuilder scratch = new IntsRefBuilder();
     Util.toUTF32("foobar".toCharArray(), 0, 6, scratch);
-    assertTrue(result.contains(scratch));
+    assertTrue(result.contains(scratch.get()));
   }
 }

Modified: lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/util/automaton/TestUTF32ToUTF8.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/util/automaton/TestUTF32ToUTF8.java?rev=1617695&r1=1617694&r2=1617695&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/util/automaton/TestUTF32ToUTF8.java (original)
+++ lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/util/automaton/TestUTF32ToUTF8.java Wed Aug 13 09:36:54 2014
@@ -24,6 +24,7 @@ import java.util.Set;
 
 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;
@@ -38,12 +39,11 @@ public class TestUTF32ToUTF8 extends Luc
 
   private static final int MAX_UNICODE = 0x10FFFF;
 
-  final BytesRef b = new BytesRef(4);
-
   private boolean matches(ByteRunAutomaton a, int code) {
     char[] chars = Character.toChars(code);
-    UnicodeUtil.UTF16toUTF8(chars, 0, chars.length, b);
-    return a.run(b.bytes, 0, b.length);
+    byte[] b = new byte[UnicodeUtil.MAX_UTF8_BYTES_PER_CHAR * chars.length];
+    final int len = UnicodeUtil.UTF16toUTF8(chars, 0, chars.length, b);
+    return a.run(b, 0, len);
   }
 
   private void testOne(Random r, ByteRunAutomaton a, int startCode, int endCode, int iters) {
@@ -214,10 +214,10 @@ public class TestUTF32ToUTF8 extends Luc
       String s = TestUtil.randomRealisticUnicodeString(random());
       Automaton a = Automata.makeString(s);
       Automaton utf8 = new UTF32ToUTF8().convert(a);
-      IntsRef ints = new IntsRef();
+      IntsRefBuilder ints = new IntsRefBuilder();
       Util.toIntsRef(new BytesRef(s), ints);
       Set<IntsRef> set = new HashSet<>();
-      set.add(ints);
+      set.add(ints.get());
       assertEquals(set, Operations.getFiniteStrings(utf8, -1));
     }
   }

Modified: lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/util/fst/TestFSTs.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/util/fst/TestFSTs.java?rev=1617695&r1=1617694&r2=1617695&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/util/fst/TestFSTs.java (original)
+++ lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/util/fst/TestFSTs.java Wed Aug 13 09:36:54 2014
@@ -62,7 +62,9 @@ import org.apache.lucene.store.IndexInpu
 import org.apache.lucene.store.IndexOutput;
 import org.apache.lucene.store.MockDirectoryWrapper;
 import org.apache.lucene.util.BytesRef;
+import org.apache.lucene.util.BytesRefBuilder;
 import org.apache.lucene.util.IntsRef;
+import org.apache.lucene.util.IntsRefBuilder;
 import org.apache.lucene.util.LineFileDocs;
 import org.apache.lucene.util.LuceneTestCase.Slow;
 import org.apache.lucene.util.LuceneTestCase.SuppressCodecs;
@@ -338,7 +340,7 @@ public class TestFSTs extends LuceneTest
     }
     Terms terms = MultiFields.getTerms(r, "body");
     if (terms != null) {
-      final IntsRef scratchIntsRef = new IntsRef();
+      final IntsRefBuilder scratchIntsRef = new IntsRefBuilder();
       final TermsEnum termsEnum = terms.iterator(null);
       if (VERBOSE) {
         System.out.println("TEST: got termsEnum=" + termsEnum);
@@ -477,7 +479,7 @@ public class TestFSTs extends LuceneTest
     public void run(int limit, boolean verify, boolean verifyByOutput) throws IOException {
       BufferedReader is = new BufferedReader(new InputStreamReader(new FileInputStream(wordsFileIn), StandardCharsets.UTF_8), 65536);
       try {
-        final IntsRef intsRef = new IntsRef(10);
+        final IntsRefBuilder intsRef = new IntsRefBuilder();
         long tStart = System.currentTimeMillis();
         int ord = 0;
         while(true) {
@@ -486,8 +488,8 @@ public class TestFSTs extends LuceneTest
             break;
           }
           toIntsRef(w, inputMode, intsRef);
-          builder.add(intsRef,
-                      getOutput(intsRef, ord));
+          builder.add(intsRef.get(),
+                      getOutput(intsRef.get(), ord));
 
           ord++;
           if (ord % 500000 == 0) {
@@ -556,8 +558,8 @@ public class TestFSTs extends LuceneTest
               }
               toIntsRef(w, inputMode, intsRef);
               if (iter == 0) {
-                T expected = getOutput(intsRef, ord);
-                T actual = Util.get(fst, intsRef);
+                T expected = getOutput(intsRef.get(), ord);
+                T actual = Util.get(fst, intsRef.get());
                 if (actual == null) {
                   throw new RuntimeException("unexpected null output on input=" + w);
                 }
@@ -566,7 +568,7 @@ public class TestFSTs extends LuceneTest
                 }
               } else {
                 // Get by output
-                final Long output = (Long) getOutput(intsRef, ord);
+                final Long output = (Long) getOutput(intsRef.get(), ord);
                 @SuppressWarnings("unchecked") final IntsRef actual = Util.getByOutput((FST<Long>) fst, output.longValue());
                 if (actual == null) {
                   throw new RuntimeException("unexpected null input from output=" + output);
@@ -721,7 +723,7 @@ public class TestFSTs extends LuceneTest
   public void testSingleString() throws Exception {
     final Outputs<Object> outputs = NoOutputs.getSingleton();
     final Builder<Object> b = new Builder<>(FST.INPUT_TYPE.BYTE1, outputs);
-    b.add(Util.toIntsRef(new BytesRef("foobar"), new IntsRef()), outputs.getNoOutput());
+    b.add(Util.toIntsRef(new BytesRef("foobar"), new IntsRefBuilder()), outputs.getNoOutput());
     final BytesRefFSTEnum<Object> fstEnum = new BytesRefFSTEnum<>(b.finish());
     assertNull(fstEnum.seekFloor(new BytesRef("foo")));
     assertNull(fstEnum.seekCeil(new BytesRef("foobaz")));
@@ -732,7 +734,7 @@ public class TestFSTs extends LuceneTest
     String str = "foobar";
     final Outputs<Object> outputs = NoOutputs.getSingleton();
     final Builder<Object> b = new Builder<>(FST.INPUT_TYPE.BYTE1, outputs);
-    IntsRef ints = new IntsRef();
+    IntsRefBuilder ints = new IntsRefBuilder();
     for(int i=0; i<10; i++) {
       b.add(Util.toIntsRef(new BytesRef(str), ints), outputs.getNoOutput());
     }
@@ -806,9 +808,9 @@ public class TestFSTs extends LuceneTest
     final BytesRef b = new BytesRef("b");
     final BytesRef c = new BytesRef("c");
 
-    builder.add(Util.toIntsRef(a, new IntsRef()), 17L);
-    builder.add(Util.toIntsRef(b, new IntsRef()), 42L);
-    builder.add(Util.toIntsRef(c, new IntsRef()), 13824324872317238L);
+    builder.add(Util.toIntsRef(a, new IntsRefBuilder()), 17L);
+    builder.add(Util.toIntsRef(b, new IntsRefBuilder()), 42L);
+    builder.add(Util.toIntsRef(c, new IntsRefBuilder()), 13824324872317238L);
 
     final FST<Long> fst = builder.finish();
 
@@ -833,12 +835,12 @@ public class TestFSTs extends LuceneTest
     assertEquals(b, seekResult.input);
     assertEquals(42, (long) seekResult.output);
 
-    assertEquals(Util.toIntsRef(new BytesRef("c"), new IntsRef()),
+    assertEquals(Util.toIntsRef(new BytesRef("c"), new IntsRefBuilder()),
                  Util.getByOutput(fst, 13824324872317238L));
     assertNull(Util.getByOutput(fst, 47));
-    assertEquals(Util.toIntsRef(new BytesRef("b"), new IntsRef()),
+    assertEquals(Util.toIntsRef(new BytesRef("b"), new IntsRefBuilder()),
                  Util.getByOutput(fst, 42));
-    assertEquals(Util.toIntsRef(new BytesRef("a"), new IntsRef()),
+    assertEquals(Util.toIntsRef(new BytesRef("a"), new IntsRefBuilder()),
                  Util.getByOutput(fst, 17));
   }
 
@@ -1041,15 +1043,15 @@ public class TestFSTs extends LuceneTest
         final Builder<Object> b = new Builder<>(FST.INPUT_TYPE.BYTE1, outputs);
 
         int line = 0;
-        final BytesRef term = new BytesRef();
-        final IntsRef scratchIntsRef = new IntsRef();
+        final BytesRefBuilder term = new BytesRefBuilder();
+        final IntsRefBuilder scratchIntsRef = new IntsRefBuilder();
         while (line < lines.length) {
           String w = lines[line++];
           if (w == null) {
             break;
           }
           term.copyChars(w);
-          b.add(Util.toIntsRef(term, scratchIntsRef), nothing);
+          b.add(Util.toIntsRef(term.get(), scratchIntsRef), nothing);
         }
 
         return b.finish();
@@ -1114,8 +1116,8 @@ public class TestFSTs extends LuceneTest
     final PositiveIntOutputs outputs = PositiveIntOutputs.getSingleton();
 
     final Builder<Long> builder = new Builder<>(FST.INPUT_TYPE.BYTE4, 2, 0, true, true, Integer.MAX_VALUE, outputs, random().nextBoolean(), PackedInts.DEFAULT, true, 15);
-    builder.add(Util.toUTF32("stat", new IntsRef()), 17L);
-    builder.add(Util.toUTF32("station", new IntsRef()), 10L);
+    builder.add(Util.toUTF32("stat", new IntsRefBuilder()), 17L);
+    builder.add(Util.toUTF32("station", new IntsRefBuilder()), 10L);
     final FST<Long> fst = builder.finish();
     //Writer w = new OutputStreamWriter(new FileOutputStream("/x/tmp3/out.dot"));
     StringWriter w = new StringWriter();
@@ -1129,8 +1131,8 @@ public class TestFSTs extends LuceneTest
     final PositiveIntOutputs outputs = PositiveIntOutputs.getSingleton();
     final boolean willRewrite = random().nextBoolean();
     final Builder<Long> builder = new Builder<>(FST.INPUT_TYPE.BYTE1, 0, 0, true, true, Integer.MAX_VALUE, outputs, willRewrite, PackedInts.DEFAULT, true, 15);
-    builder.add(Util.toIntsRef(new BytesRef("stat"), new IntsRef()), outputs.getNoOutput());
-    builder.add(Util.toIntsRef(new BytesRef("station"), new IntsRef()), outputs.getNoOutput());
+    builder.add(Util.toIntsRef(new BytesRef("stat"), new IntsRefBuilder()), outputs.getNoOutput());
+    builder.add(Util.toIntsRef(new BytesRef("station"), new IntsRefBuilder()), outputs.getNoOutput());
     final FST<Long> fst = builder.finish();
     StringWriter w = new StringWriter();
     //Writer w = new OutputStreamWriter(new FileOutputStream("/x/tmp/out.dot"));
@@ -1230,7 +1232,7 @@ public class TestFSTs extends LuceneTest
     final PositiveIntOutputs outputs = PositiveIntOutputs.getSingleton();
     final Builder<Long> builder = new Builder<>(FST.INPUT_TYPE.BYTE1, outputs);
 
-    final IntsRef scratch = new IntsRef();
+    final IntsRefBuilder scratch = new IntsRefBuilder();
     builder.add(Util.toIntsRef(new BytesRef("aab"), scratch), 22L);
     builder.add(Util.toIntsRef(new BytesRef("aac"), scratch), 7L);
     builder.add(Util.toIntsRef(new BytesRef("ax"), scratch), 17L);
@@ -1261,7 +1263,7 @@ public class TestFSTs extends LuceneTest
     final PositiveIntOutputs outputs = PositiveIntOutputs.getSingleton();
     final Builder<Long> builder = new Builder<Long>(FST.INPUT_TYPE.BYTE1, outputs);
 
-    final IntsRef scratch = new IntsRef();
+    final IntsRefBuilder scratch = new IntsRefBuilder();
     builder.add(Util.toIntsRef(new BytesRef("aab"), scratch), 22L);
     builder.add(Util.toIntsRef(new BytesRef("aac"), scratch), 7L);
     builder.add(Util.toIntsRef(new BytesRef("adcd"), scratch), 17L);
@@ -1281,7 +1283,7 @@ public class TestFSTs extends LuceneTest
       }
     };
 
-    searcher.addStartPaths(fst.getFirstArc(new FST.Arc<Long>()),  outputs.getNoOutput(), true, new IntsRef());
+    searcher.addStartPaths(fst.getFirstArc(new FST.Arc<Long>()),  outputs.getNoOutput(), true, new IntsRefBuilder());
     Util.TopResults<Long> res = searcher.search();
     assertEquals(rejectCount.get(), 4);
     assertTrue(res.isComplete); // rejected(4) + topN(2) <= maxQueueSize(6)
@@ -1301,7 +1303,7 @@ public class TestFSTs extends LuceneTest
       }
     };
 
-    searcher.addStartPaths(fst.getFirstArc(new FST.Arc<Long>()),  outputs.getNoOutput(), true, new IntsRef());
+    searcher.addStartPaths(fst.getFirstArc(new FST.Arc<Long>()),  outputs.getNoOutput(), true, new IntsRefBuilder());
     res = searcher.search();
     assertEquals(rejectCount.get(), 4);
     assertFalse(res.isComplete); // rejected(4) + topN(2) > maxQueueSize(5)
@@ -1325,7 +1327,7 @@ public class TestFSTs extends LuceneTest
 
     final Builder<Pair<Long,Long>> builder = new Builder<>(FST.INPUT_TYPE.BYTE1, outputs);
 
-    final IntsRef scratch = new IntsRef();
+    final IntsRefBuilder scratch = new IntsRefBuilder();
     builder.add(Util.toIntsRef(new BytesRef("aab"), scratch), outputs.newPair(22L, 57L));
     builder.add(Util.toIntsRef(new BytesRef("aac"), scratch), outputs.newPair(7L, 36L));
     builder.add(Util.toIntsRef(new BytesRef("ax"), scratch), outputs.newPair(17L, 85L));
@@ -1365,7 +1367,7 @@ public class TestFSTs extends LuceneTest
 
     final PositiveIntOutputs outputs = PositiveIntOutputs.getSingleton();
     final Builder<Long> builder = new Builder<>(FST.INPUT_TYPE.BYTE1, outputs);
-    final IntsRef scratch = new IntsRef();
+    final IntsRefBuilder scratch = new IntsRefBuilder();
 
     for (int i = 0; i < numWords; i++) {
       String s;
@@ -1422,7 +1424,7 @@ public class TestFSTs extends LuceneTest
       for (Map.Entry<String,Long> e : slowCompletor.entrySet()) {
         if (e.getKey().startsWith(prefix)) {
           //System.out.println("  consider " + e.getKey());
-          matches.add(new Result<>(Util.toIntsRef(new BytesRef(e.getKey().substring(prefix.length())), new IntsRef()),
+          matches.add(new Result<>(Util.toIntsRef(new BytesRef(e.getKey().substring(prefix.length())), new IntsRefBuilder()),
                                          e.getValue() - prefixOutput));
         }
       }
@@ -1483,7 +1485,7 @@ public class TestFSTs extends LuceneTest
         PositiveIntOutputs.getSingleton()  // output
     );
     final Builder<Pair<Long,Long>> builder = new Builder<>(FST.INPUT_TYPE.BYTE1, outputs);
-    final IntsRef scratch = new IntsRef();
+    final IntsRefBuilder scratch = new IntsRefBuilder();
 
     Random random = random();
     for (int i = 0; i < numWords; i++) {
@@ -1543,7 +1545,7 @@ public class TestFSTs extends LuceneTest
       for (Map.Entry<String,TwoLongs> e : slowCompletor.entrySet()) {
         if (e.getKey().startsWith(prefix)) {
           //System.out.println("  consider " + e.getKey());
-          matches.add(new Result<>(Util.toIntsRef(new BytesRef(e.getKey().substring(prefix.length())), new IntsRef()),
+          matches.add(new Result<>(Util.toIntsRef(new BytesRef(e.getKey().substring(prefix.length())), new IntsRefBuilder()),
                                                   outputs.newPair(e.getValue().a - prefixOutput.output1, e.getValue().b - prefixOutput.output2)));
         }
       }
@@ -1569,20 +1571,19 @@ public class TestFSTs extends LuceneTest
     final Builder<BytesRef> builder = new Builder<>(FST.INPUT_TYPE.BYTE1, outputs);
 
     final byte[] bytes = new byte[300];
-    final IntsRef input = new IntsRef();
-    input.grow(1);
-    input.length = 1;
+    final IntsRefBuilder input = new IntsRefBuilder();
+    input.append(0);
     final BytesRef output = new BytesRef(bytes);
     for(int arc=0;arc<6;arc++) {
-      input.ints[0] = arc;
+      input.setIntAt(0, arc);
       output.bytes[0] = (byte) arc;
-      builder.add(input, BytesRef.deepCopyOf(output));
+      builder.add(input.get(), BytesRef.deepCopyOf(output));
     }
 
     final FST<BytesRef> fst = builder.finish();
     for(int arc=0;arc<6;arc++) {
-      input.ints[0] = arc;
-      final BytesRef result = Util.get(fst, input);
+      input.setIntAt(0,  arc);
+      final BytesRef result = Util.get(fst, input.get());
       assertNotNull(result);
       assertEquals(300, result.length);
       assertEquals(result.bytes[result.offset], arc);

Modified: lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/util/mutable/TestMutableValues.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/util/mutable/TestMutableValues.java?rev=1617695&r1=1617694&r2=1617695&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/util/mutable/TestMutableValues.java (original)
+++ lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/util/mutable/TestMutableValues.java Wed Aug 13 09:36:54 2014
@@ -26,7 +26,7 @@ public class TestMutableValues extends L
 
   public void testStr() {
     MutableValueStr xxx = new MutableValueStr();
-    assert xxx.value.equals(new BytesRef()) : "defaults have changed, test utility may not longer be as high";
+    assert xxx.value.get().equals(new BytesRef()) : "defaults have changed, test utility may not longer be as high";
     assert xxx.exists : "defaults have changed, test utility may not longer be as high";
     assertSanity(xxx);
     MutableValueStr yyy = new MutableValueStr();
@@ -42,14 +42,14 @@ public class TestMutableValues extends L
     yyy.exists = false;
     assertEquality(xxx, yyy);
 
-    xxx.value.length = 0;
+    xxx.value.clear();
     xxx.value.copyChars("zzz");
     xxx.exists = true;
     assertSanity(xxx);
 
     assertInEquality(xxx,yyy);
 
-    yyy.value.length = 0;
+    yyy.value.clear();
     yyy.value.copyChars("aaa");
     yyy.exists = true;
     assertSanity(yyy);
@@ -65,11 +65,11 @@ public class TestMutableValues extends L
     // special BytesRef considerations...
 
     xxx.exists = false;
-    xxx.value.length = 0; // but leave bytes alone
+    xxx.value.clear(); // but leave bytes alone
     assertInEquality(xxx,yyy);
 
     yyy.exists = false;
-    yyy.value.length = 0; // but leave bytes alone
+    yyy.value.clear(); // but leave bytes alone
     assertEquality(xxx, yyy);
 
   }

Modified: lucene/dev/branches/branch_4x/lucene/facet/src/java/org/apache/lucene/facet/FacetsConfig.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/facet/src/java/org/apache/lucene/facet/FacetsConfig.java?rev=1617695&r1=1617694&r2=1617695&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/facet/src/java/org/apache/lucene/facet/FacetsConfig.java (original)
+++ lucene/dev/branches/branch_4x/lucene/facet/src/java/org/apache/lucene/facet/FacetsConfig.java Wed Aug 13 09:36:54 2014
@@ -43,6 +43,7 @@ import org.apache.lucene.index.Indexable
 import org.apache.lucene.util.ArrayUtil;
 import org.apache.lucene.util.BytesRef;
 import org.apache.lucene.util.IntsRef;
+import org.apache.lucene.util.IntsRefBuilder;
 
 /** Records per-dimension configuration.  By default a
  *  dimension is flat, single valued and does
@@ -305,7 +306,7 @@ public class FacetsConfig {
       String indexFieldName = ent.getKey();
       //System.out.println("  indexFieldName=" + indexFieldName + " fields=" + ent.getValue());
 
-      IntsRef ordinals = new IntsRef(32);
+      IntsRefBuilder ordinals = new IntsRefBuilder();
       for(FacetField facetField : ent.getValue()) {
 
         FacetsConfig.DimConfig ft = getDimConfig(facetField.dim);
@@ -317,10 +318,7 @@ public class FacetsConfig {
 
         checkTaxoWriter(taxoWriter);
         int ordinal = taxoWriter.addCategory(cp);
-        if (ordinals.length == ordinals.ints.length) {
-          ordinals.grow(ordinals.length+1);
-        }
-        ordinals.ints[ordinals.length++] = ordinal;
+        ordinals.append(ordinal);
         //System.out.println("ords[" + (ordinals.length-1) + "]=" + ordinal);
         //System.out.println("  add cp=" + cp);
 
@@ -329,16 +327,13 @@ public class FacetsConfig {
           // Add all parents too:
           int parent = taxoWriter.getParent(ordinal);
           while (parent > 0) {
-            if (ordinals.ints.length == ordinals.length) {
-              ordinals.grow(ordinals.length+1);
-            }
-            ordinals.ints[ordinals.length++] = parent;
+            ordinals.append(parent);
             parent = taxoWriter.getParent(parent);
           }
 
           if (ft.requireDimCount == false) {
             // Remove last (dimension) ord:
-            ordinals.length--;
+            ordinals.setLength(ordinals.length() - 1);
           }
         }
 
@@ -350,7 +345,7 @@ public class FacetsConfig {
 
       // Facet counts:
       // DocValues are considered stored fields:
-      doc.add(new BinaryDocValuesField(indexFieldName, dedupAndEncode(ordinals)));
+      doc.add(new BinaryDocValuesField(indexFieldName, dedupAndEncode(ordinals.get())));
     }
   }
 

Modified: lucene/dev/branches/branch_4x/lucene/grouping/src/java/org/apache/lucene/search/grouping/term/TermAllGroupHeadsCollector.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/grouping/src/java/org/apache/lucene/search/grouping/term/TermAllGroupHeadsCollector.java?rev=1617695&r1=1617694&r2=1617695&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/grouping/src/java/org/apache/lucene/search/grouping/term/TermAllGroupHeadsCollector.java (original)
+++ lucene/dev/branches/branch_4x/lucene/grouping/src/java/org/apache/lucene/search/grouping/term/TermAllGroupHeadsCollector.java Wed Aug 13 09:36:54 2014
@@ -25,6 +25,7 @@ import org.apache.lucene.index.SortedDoc
 import org.apache.lucene.search.*;
 import org.apache.lucene.search.grouping.AbstractAllGroupHeadsCollector;
 import org.apache.lucene.util.BytesRef;
+import org.apache.lucene.util.BytesRefBuilder;
 import org.apache.lucene.util.SentinelIntSet;
 
 /**
@@ -295,7 +296,7 @@ public abstract class TermAllGroupHeadsC
             if (collectedGroup.sortValues[i] == null) {
               sortOrd = -1;
             } else {
-              sortOrd = sortsIndex[i].lookupTerm(collectedGroup.sortValues[i]);
+              sortOrd = sortsIndex[i].lookupTerm(collectedGroup.sortValues[i].get());
             }
             collectedGroup.sortOrds[i] = sortOrd;
           }
@@ -305,13 +306,13 @@ public abstract class TermAllGroupHeadsC
 
     class GroupHead extends AbstractAllGroupHeadsCollector.GroupHead<BytesRef> {
 
-      BytesRef[] sortValues;
+      BytesRefBuilder[] sortValues;
       int[] sortOrds;
       float[] scores;
 
       private GroupHead(int doc, BytesRef groupValue) throws IOException {
         super(groupValue, doc + readerContext.docBase);
-        sortValues = new BytesRef[sortsIndex.length];
+        sortValues = new BytesRefBuilder[sortsIndex.length];
         sortOrds = new int[sortsIndex.length];
         scores = new float[sortsIndex.length];
         for (int i = 0; i < sortsIndex.length; i++) {
@@ -319,7 +320,7 @@ public abstract class TermAllGroupHeadsC
             scores[i] = scorer.score();
           } else {
             sortOrds[i] = sortsIndex[i].getOrd(doc);
-            sortValues[i] = new BytesRef();
+            sortValues[i] = new BytesRefBuilder();
             if (sortOrds[i] != -1) {
               sortValues[i].copyBytes(sortsIndex[i].get(doc));
             }
@@ -341,7 +342,7 @@ public abstract class TermAllGroupHeadsC
           if (sortOrds[compIDX] < 0) {
             // The current segment doesn't contain the sort value we encountered before. Therefore the ord is negative.
             final BytesRef term = sortsIndex[compIDX].get(doc);
-            return sortValues[compIDX].compareTo(term);
+            return sortValues[compIDX].get().compareTo(term);
           } else {
             return sortOrds[compIDX] - sortsIndex[compIDX].getOrd(doc);
           }
@@ -447,7 +448,7 @@ public abstract class TermAllGroupHeadsC
             if (collectedGroup.sortOrds[i] == -1) {
               sortOrd = -1;
             } else {
-              sortOrd = sortsIndex[i].lookupTerm(collectedGroup.sortValues[i]);
+              sortOrd = sortsIndex[i].lookupTerm(collectedGroup.sortValues[i].get());
             }
             collectedGroup.sortOrds[i] = sortOrd;
           }
@@ -457,16 +458,16 @@ public abstract class TermAllGroupHeadsC
 
     class GroupHead extends AbstractAllGroupHeadsCollector.GroupHead<BytesRef> {
 
-      BytesRef[] sortValues;
+      BytesRefBuilder[] sortValues;
       int[] sortOrds;
 
       private GroupHead(int doc, BytesRef groupValue) {
         super(groupValue, doc + readerContext.docBase);
-        sortValues = new BytesRef[sortsIndex.length];
+        sortValues = new BytesRefBuilder[sortsIndex.length];
         sortOrds = new int[sortsIndex.length];
         for (int i = 0; i < sortsIndex.length; i++) {
           sortOrds[i] = sortsIndex[i].getOrd(doc);
-          sortValues[i] = new BytesRef();
+          sortValues[i] = new BytesRefBuilder();
           sortValues[i].copyBytes(sortsIndex[i].get(doc));
         }
       }
@@ -476,7 +477,7 @@ public abstract class TermAllGroupHeadsC
         if (sortOrds[compIDX] < 0) {
           // The current segment doesn't contain the sort value we encountered before. Therefore the ord is negative.
           final BytesRef term = sortsIndex[compIDX].get(doc);
-          return sortValues[compIDX].compareTo(term);
+          return sortValues[compIDX].get().compareTo(term);
         } else {
           return sortOrds[compIDX] - sortsIndex[compIDX].getOrd(doc);
         }

Modified: lucene/dev/branches/branch_4x/lucene/grouping/src/java/org/apache/lucene/search/grouping/term/TermFirstPassGroupingCollector.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/grouping/src/java/org/apache/lucene/search/grouping/term/TermFirstPassGroupingCollector.java?rev=1617695&r1=1617694&r2=1617695&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/grouping/src/java/org/apache/lucene/search/grouping/term/TermFirstPassGroupingCollector.java (original)
+++ lucene/dev/branches/branch_4x/lucene/grouping/src/java/org/apache/lucene/search/grouping/term/TermFirstPassGroupingCollector.java Wed Aug 13 09:36:54 2014
@@ -24,6 +24,7 @@ import org.apache.lucene.index.SortedDoc
 import org.apache.lucene.search.FieldCache;
 import org.apache.lucene.search.Sort;
 import org.apache.lucene.search.grouping.AbstractFirstPassGroupingCollector;
+import org.apache.lucene.util.ArrayUtil;
 import org.apache.lucene.util.BytesRef;
 
 /**
@@ -75,7 +76,10 @@ public class TermFirstPassGroupingCollec
     if (groupValue == null) {
       return null;
     } else if (reuse != null) {
-      reuse.copyBytes(groupValue);
+      reuse.bytes = ArrayUtil.grow(reuse.bytes, groupValue.length);
+      reuse.offset = 0;
+      reuse.length = groupValue.length;
+      System.arraycopy(groupValue.bytes, groupValue.offset, reuse.bytes, 0, groupValue.length);
       return reuse;
     } else {
       return BytesRef.deepCopyOf(groupValue);

Modified: lucene/dev/branches/branch_4x/lucene/grouping/src/java/org/apache/lucene/search/grouping/term/TermGroupFacetCollector.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/grouping/src/java/org/apache/lucene/search/grouping/term/TermGroupFacetCollector.java?rev=1617695&r1=1617694&r2=1617695&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/grouping/src/java/org/apache/lucene/search/grouping/term/TermGroupFacetCollector.java (original)
+++ lucene/dev/branches/branch_4x/lucene/grouping/src/java/org/apache/lucene/search/grouping/term/TermGroupFacetCollector.java Wed Aug 13 09:36:54 2014
@@ -22,7 +22,6 @@ import java.util.ArrayList;
 import java.util.List;
 
 import org.apache.lucene.index.AtomicReaderContext;
-import org.apache.lucene.index.DocTermOrds;
 import org.apache.lucene.index.SortedDocValues;
 import org.apache.lucene.index.SortedSetDocValues;
 import org.apache.lucene.index.TermsEnum;
@@ -153,9 +152,10 @@ public abstract class TermGroupFacetColl
           // Points to the ord one higher than facetPrefix
           startFacetOrd = -startFacetOrd - 1;
         }
-        BytesRef facetEndPrefix = BytesRef.deepCopyOf(facetPrefix);
+        BytesRefBuilder facetEndPrefix = new BytesRefBuilder();
+        facetEndPrefix.append(facetPrefix);
         facetEndPrefix.append(UnicodeUtil.BIG_TERM);
-        endFacetOrd = facetFieldTermsIndex.lookupTerm(facetEndPrefix);
+        endFacetOrd = facetFieldTermsIndex.lookupTerm(facetEndPrefix.get());
         assert endFacetOrd < 0;
         endFacetOrd = -endFacetOrd - 1; // Points to the ord one higher than facetEndPrefix
       } else {
@@ -197,7 +197,6 @@ public abstract class TermGroupFacetColl
     private SortedSetDocValues facetFieldDocTermOrds;
     private TermsEnum facetOrdTermsEnum;
     private int facetFieldNumTerms;
-    private final BytesRef scratch = new BytesRef();
 
     MV(String groupField, String facetField, BytesRef facetPrefix, int initialSize) {
       super(groupField, facetField, facetPrefix, initialSize);
@@ -326,9 +325,10 @@ public abstract class TermGroupFacetColl
           return;
         }
 
-        BytesRef facetEndPrefix = BytesRef.deepCopyOf(facetPrefix);
+        BytesRefBuilder facetEndPrefix = new BytesRefBuilder();
+        facetEndPrefix.append(facetPrefix);
         facetEndPrefix.append(UnicodeUtil.BIG_TERM);
-        seekStatus = facetOrdTermsEnum.seekCeil(facetEndPrefix);
+        seekStatus = facetOrdTermsEnum.seekCeil(facetEndPrefix.get());
         if (seekStatus != TermsEnum.SeekStatus.END) {
           endFacetOrd = (int) facetOrdTermsEnum.ord();
         } else {

Modified: lucene/dev/branches/branch_4x/lucene/grouping/src/java/org/apache/lucene/search/grouping/term/TermSecondPassGroupingCollector.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/grouping/src/java/org/apache/lucene/search/grouping/term/TermSecondPassGroupingCollector.java?rev=1617695&r1=1617694&r2=1617695&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/grouping/src/java/org/apache/lucene/search/grouping/term/TermSecondPassGroupingCollector.java (original)
+++ lucene/dev/branches/branch_4x/lucene/grouping/src/java/org/apache/lucene/search/grouping/term/TermSecondPassGroupingCollector.java Wed Aug 13 09:36:54 2014
@@ -42,7 +42,7 @@ public class TermSecondPassGroupingColle
   private SortedDocValues index;
   private final String groupField;
 
-  @SuppressWarnings({"unchecked", "rawtypes"})
+  @SuppressWarnings({"unchecked"})
   public TermSecondPassGroupingCollector(String groupField, Collection<SearchGroup<BytesRef>> groups, Sort groupSort, Sort withinGroupSort,
                                          int maxDocsPerGroup, boolean getScores, boolean getMaxScores, boolean fillSortFields)
       throws IOException {

Modified: lucene/dev/branches/branch_4x/lucene/grouping/src/test/org/apache/lucene/search/grouping/DistinctValuesCollectorTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/grouping/src/test/org/apache/lucene/search/grouping/DistinctValuesCollectorTest.java?rev=1617695&r1=1617694&r2=1617695&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/grouping/src/test/org/apache/lucene/search/grouping/DistinctValuesCollectorTest.java (original)
+++ lucene/dev/branches/branch_4x/lucene/grouping/src/test/org/apache/lucene/search/grouping/DistinctValuesCollectorTest.java Wed Aug 13 09:36:54 2014
@@ -316,7 +316,7 @@ public class DistinctValuesCollectorTest
       assertEquals(Long.parseLong(expected), groupValue);
     } else if (MutableValue.class.isAssignableFrom(groupValue.getClass())) {
       MutableValueStr mutableValue = new MutableValueStr();
-      mutableValue.value = new BytesRef(expected);
+      mutableValue.value.copyChars(expected);
       assertEquals(mutableValue, groupValue);
     } else {
       fail();

Modified: lucene/dev/branches/branch_4x/lucene/grouping/src/test/org/apache/lucene/search/grouping/GroupingSearchTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/grouping/src/test/org/apache/lucene/search/grouping/GroupingSearchTest.java?rev=1617695&r1=1617694&r2=1617695&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/grouping/src/test/org/apache/lucene/search/grouping/GroupingSearchTest.java (original)
+++ lucene/dev/branches/branch_4x/lucene/grouping/src/test/org/apache/lucene/search/grouping/GroupingSearchTest.java Wed Aug 13 09:36:54 2014
@@ -195,7 +195,7 @@ public class GroupingSearchTest extends 
       assertEquals(new BytesRef(expected), group.groupValue);
     } else if (group.groupValue.getClass().isAssignableFrom(MutableValueStr.class)) {
       MutableValueStr v = new MutableValueStr();
-      v.value = new BytesRef(expected);
+      v.value.copyChars(expected);
       assertEquals(v, group.groupValue);
     } else {
       fail();

Modified: lucene/dev/branches/branch_4x/lucene/grouping/src/test/org/apache/lucene/search/grouping/TestGrouping.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/grouping/src/test/org/apache/lucene/search/grouping/TestGrouping.java?rev=1617695&r1=1617694&r2=1617695&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/grouping/src/test/org/apache/lucene/search/grouping/TestGrouping.java (original)
+++ lucene/dev/branches/branch_4x/lucene/grouping/src/test/org/apache/lucene/search/grouping/TestGrouping.java Wed Aug 13 09:36:54 2014
@@ -242,9 +242,8 @@ public class TestGrouping extends Lucene
         SearchGroup<MutableValue> sg = new SearchGroup<>();
         MutableValueStr groupValue = new MutableValueStr();
         if (mergedTopGroup.groupValue != null) {
-          groupValue.value =  mergedTopGroup.groupValue;
+          groupValue.value.copyBytes(mergedTopGroup.groupValue);
         } else {
-          groupValue.value = new BytesRef();
           groupValue.exists = false;
         }
         sg.groupValue = groupValue;
@@ -282,7 +281,7 @@ public class TestGrouping extends Lucene
       assertEquals(new BytesRef(expected), group.groupValue);
     } else if (group.groupValue.getClass().isAssignableFrom(MutableValueStr.class)) {
       MutableValueStr v = new MutableValueStr();
-      v.value = new BytesRef(expected);
+      v.value.copyChars(expected);
       assertEquals(v, group.groupValue);
     } else {
       fail();
@@ -301,7 +300,7 @@ public class TestGrouping extends Lucene
       List<SearchGroup<BytesRef>> groups = new ArrayList<>(mutableValueGroups.size());
       for (SearchGroup<MutableValue> mutableValueGroup : mutableValueGroups) {
         SearchGroup<BytesRef> sg = new SearchGroup<>();
-        sg.groupValue = mutableValueGroup.groupValue.exists() ? ((MutableValueStr) mutableValueGroup.groupValue).value : null;
+        sg.groupValue = mutableValueGroup.groupValue.exists() ? ((MutableValueStr) mutableValueGroup.groupValue).value.get() : null;
         sg.sortValues = mutableValueGroup.sortValues;
         groups.add(sg);
       }
@@ -319,7 +318,7 @@ public class TestGrouping extends Lucene
       TopGroups<MutableValue> mvalTopGroups = ((FunctionSecondPassGroupingCollector) c).getTopGroups(withinGroupOffset);
       List<GroupDocs<BytesRef>> groups = new ArrayList<>(mvalTopGroups.groups.length);
       for (GroupDocs<MutableValue> mvalGd : mvalTopGroups.groups) {
-        BytesRef groupValue = mvalGd.groupValue.exists() ? ((MutableValueStr) mvalGd.groupValue).value : null;
+        BytesRef groupValue = mvalGd.groupValue.exists() ? ((MutableValueStr) mvalGd.groupValue).value.get() : null;
         groups.add(new GroupDocs<>(Float.NaN, mvalGd.maxScore, mvalGd.totalHits, mvalGd.scoreDocs, groupValue, mvalGd.groupSortValues));
       }
       return new TopGroups<>(mvalTopGroups.groupSort, mvalTopGroups.withinGroupSort, mvalTopGroups.totalHitCount, mvalTopGroups.totalGroupedHitCount, groups.toArray(new GroupDocs[groups.size()]), Float.NaN);

Modified: lucene/dev/branches/branch_4x/lucene/highlighter/src/java/org/apache/lucene/search/vectorhighlight/FieldTermStack.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/highlighter/src/java/org/apache/lucene/search/vectorhighlight/FieldTermStack.java?rev=1617695&r1=1617694&r2=1617695&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/highlighter/src/java/org/apache/lucene/search/vectorhighlight/FieldTermStack.java (original)
+++ lucene/dev/branches/branch_4x/lucene/highlighter/src/java/org/apache/lucene/search/vectorhighlight/FieldTermStack.java Wed Aug 13 09:36:54 2014
@@ -29,8 +29,7 @@ import org.apache.lucene.index.Term;
 import org.apache.lucene.index.Terms;
 import org.apache.lucene.index.TermsEnum;
 import org.apache.lucene.util.BytesRef;
-import org.apache.lucene.util.CharsRef;
-import org.apache.lucene.util.UnicodeUtil;
+import org.apache.lucene.util.CharsRefBuilder;
 
 /**
  * <code>FieldTermStack</code> is a stack that keeps query terms in the specified field
@@ -92,7 +91,7 @@ public class FieldTermStack {
       return;
     }
 
-    final CharsRef spare = new CharsRef();
+    final CharsRefBuilder spare = new CharsRefBuilder();
     final TermsEnum termsEnum = vector.iterator(null);
     DocsAndPositionsEnum dpEnum = null;
     BytesRef text;
@@ -100,7 +99,7 @@ public class FieldTermStack {
     int numDocs = reader.maxDoc();
     
     while ((text = termsEnum.next()) != null) {
-      UnicodeUtil.UTF8toUTF16(text, spare);
+      spare.copyUTF8Bytes(text);
       final String term = spare.toString();
       if (!termSet.contains(term)) {
         continue;

Modified: lucene/dev/branches/branch_4x/lucene/misc/src/test/org/apache/lucene/util/fst/TestFSTsMisc.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/misc/src/test/org/apache/lucene/util/fst/TestFSTsMisc.java?rev=1617695&r1=1617694&r2=1617695&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/misc/src/test/org/apache/lucene/util/fst/TestFSTsMisc.java (original)
+++ lucene/dev/branches/branch_4x/lucene/misc/src/test/org/apache/lucene/util/fst/TestFSTsMisc.java Wed Aug 13 09:36:54 2014
@@ -28,6 +28,7 @@ import java.util.Set;
 import org.apache.lucene.store.MockDirectoryWrapper;
 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.TestUtil;
@@ -168,7 +169,7 @@ public class TestFSTsMisc extends Lucene
     ListOfOutputs<Long> outputs = new ListOfOutputs<>(_outputs);
     final Builder<Object> builder = new Builder<>(FST.INPUT_TYPE.BYTE1, outputs);
 
-    final IntsRef scratch = new IntsRef();
+    final IntsRefBuilder scratch = new IntsRefBuilder();
     // Add the same input more than once and the outputs
     // are merged:
     builder.add(Util.toIntsRef(new BytesRef("a"), scratch), 1L);
@@ -197,11 +198,11 @@ public class TestFSTsMisc extends Lucene
     ListOfOutputs<Long> outputs = new ListOfOutputs<>(_outputs);
     final Builder<Object> builder = new Builder<>(FST.INPUT_TYPE.BYTE1, outputs);
 
-    final IntsRef scratch = new IntsRef();
-    builder.add(scratch, 0L);
-    builder.add(scratch, 1L);
-    builder.add(scratch, 17L);
-    builder.add(scratch, 1L);
+    final IntsRefBuilder scratch = new IntsRefBuilder();
+    builder.add(scratch.get(), 0L);
+    builder.add(scratch.get(), 1L);
+    builder.add(scratch.get(), 17L);
+    builder.add(scratch.get(), 1L);
 
     builder.add(Util.toIntsRef(new BytesRef("a"), scratch), 1L);
     builder.add(Util.toIntsRef(new BytesRef("a"), scratch), 3L);

Modified: lucene/dev/branches/branch_4x/lucene/queries/src/java/org/apache/lucene/queries/function/FunctionValues.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/queries/src/java/org/apache/lucene/queries/function/FunctionValues.java?rev=1617695&r1=1617694&r2=1617695&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/queries/src/java/org/apache/lucene/queries/function/FunctionValues.java (original)
+++ lucene/dev/branches/branch_4x/lucene/queries/src/java/org/apache/lucene/queries/function/FunctionValues.java Wed Aug 13 09:36:54 2014
@@ -19,7 +19,7 @@ package org.apache.lucene.queries.functi
 
 import org.apache.lucene.search.*;
 import org.apache.lucene.index.IndexReader;
-import org.apache.lucene.util.BytesRef;
+import org.apache.lucene.util.BytesRefBuilder;
 import org.apache.lucene.util.mutable.MutableValue;
 import org.apache.lucene.util.mutable.MutableValueFloat;
 
@@ -53,10 +53,10 @@ public abstract class FunctionValues {
   }
 
   /** returns the bytes representation of the string val - TODO: should this return the indexed raw bytes not? */
-  public boolean bytesVal(int doc, BytesRef target) {
+  public boolean bytesVal(int doc, BytesRefBuilder target) {
     String s = strVal(doc);
     if (s==null) {
-      target.length = 0;
+      target.clear();
       return false;
     }
     target.copyChars(s);

Modified: lucene/dev/branches/branch_4x/lucene/queries/src/java/org/apache/lucene/queries/function/docvalues/DocTermsIndexDocValues.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/queries/src/java/org/apache/lucene/queries/function/docvalues/DocTermsIndexDocValues.java?rev=1617695&r1=1617694&r2=1617695&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/queries/src/java/org/apache/lucene/queries/function/docvalues/DocTermsIndexDocValues.java (original)
+++ lucene/dev/branches/branch_4x/lucene/queries/src/java/org/apache/lucene/queries/function/docvalues/DocTermsIndexDocValues.java Wed Aug 13 09:36:54 2014
@@ -27,8 +27,8 @@ import org.apache.lucene.queries.functio
 import org.apache.lucene.queries.function.ValueSourceScorer;
 import org.apache.lucene.search.FieldCache;
 import org.apache.lucene.util.BytesRef;
-import org.apache.lucene.util.CharsRef;
-import org.apache.lucene.util.UnicodeUtil;
+import org.apache.lucene.util.BytesRefBuilder;
+import org.apache.lucene.util.CharsRefBuilder;
 import org.apache.lucene.util.mutable.MutableValue;
 import org.apache.lucene.util.mutable.MutableValueStr;
 
@@ -40,7 +40,7 @@ public abstract class DocTermsIndexDocVa
   protected final SortedDocValues termsIndex;
   protected final ValueSource vs;
   protected final MutableValueStr val = new MutableValueStr();
-  protected final CharsRef spareChars = new CharsRef();
+  protected final CharsRefBuilder spareChars = new CharsRefBuilder();
 
   public DocTermsIndexDocValues(ValueSource vs, AtomicReaderContext context, String field) throws IOException {
     try {
@@ -69,10 +69,10 @@ public abstract class DocTermsIndexDocVa
   }
 
   @Override
-  public boolean bytesVal(int doc, BytesRef target) {
-    target.length = 0;
+  public boolean bytesVal(int doc, BytesRefBuilder target) {
+    target.clear();
     target.copyBytes(termsIndex.get(doc));
-    return target.length > 0;
+    return target.length() > 0;
   }
 
   @Override
@@ -81,7 +81,7 @@ public abstract class DocTermsIndexDocVa
     if (term.length == 0) {
       return null;
     }
-    UnicodeUtil.UTF8toUTF16(term, spareChars);
+    spareChars.copyUTF8Bytes(term);
     return spareChars.toString();
   }
 
@@ -149,7 +149,7 @@ public abstract class DocTermsIndexDocVa
       @Override
       public void fillValue(int doc) {
         int ord = termsIndex.getOrd(doc);
-        mval.value.length = 0;
+        mval.value.clear();
         mval.exists = ord >= 0;
         if (mval.exists) {
           mval.value.copyBytes(termsIndex.lookupOrd(ord));

Modified: lucene/dev/branches/branch_4x/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/BytesRefFieldSource.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/BytesRefFieldSource.java?rev=1617695&r1=1617694&r2=1617695&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/BytesRefFieldSource.java (original)
+++ lucene/dev/branches/branch_4x/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/BytesRefFieldSource.java Wed Aug 13 09:36:54 2014
@@ -28,7 +28,7 @@ import org.apache.lucene.queries.functio
 import org.apache.lucene.queries.function.docvalues.DocTermsIndexDocValues;
 import org.apache.lucene.search.FieldCache;
 import org.apache.lucene.util.Bits;
-import org.apache.lucene.util.BytesRef;
+import org.apache.lucene.util.BytesRefBuilder;
 import org.apache.lucene.util.mutable.MutableValue;
 import org.apache.lucene.util.mutable.MutableValueStr;
 
@@ -57,15 +57,15 @@ public class BytesRefFieldSource extends
         }
 
         @Override
-        public boolean bytesVal(int doc, BytesRef target) {
+        public boolean bytesVal(int doc, BytesRefBuilder target) {
           target.copyBytes(binaryValues.get(doc));
-          return target.length > 0;
+          return target.length() > 0;
         }
 
         public String strVal(int doc) {
-          final BytesRef bytes = new BytesRef();
+          final BytesRefBuilder bytes = new BytesRefBuilder();
           return bytesVal(doc, bytes)
-              ? bytes.utf8ToString()
+              ? bytes.get().utf8ToString()
               : null;
         }
 
@@ -92,7 +92,7 @@ public class BytesRefFieldSource extends
             @Override
             public void fillValue(int doc) {
               mval.exists = docsWithField.get(doc);
-              mval.value.length = 0;
+              mval.value.clear();
               mval.value.copyBytes(binaryValues.get(doc));
             }
           };

Modified: lucene/dev/branches/branch_4x/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/DefFunction.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/DefFunction.java?rev=1617695&r1=1617694&r2=1617695&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/DefFunction.java (original)
+++ lucene/dev/branches/branch_4x/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/DefFunction.java Wed Aug 13 09:36:54 2014
@@ -19,11 +19,9 @@ package org.apache.lucene.queries.functi
 import org.apache.lucene.index.AtomicReaderContext;
 import org.apache.lucene.queries.function.FunctionValues;
 import org.apache.lucene.queries.function.ValueSource;
-import org.apache.lucene.search.IndexSearcher;
-import org.apache.lucene.util.BytesRef;
+import org.apache.lucene.util.BytesRefBuilder;
 
 import java.io.IOException;
-import java.util.Arrays;
 import java.util.List;
 import java.util.Map;
 
@@ -102,7 +100,7 @@ public class DefFunction extends MultiFu
       }
 
       @Override
-      public boolean bytesVal(int doc, BytesRef target) {
+      public boolean bytesVal(int doc, BytesRefBuilder target) {
         return get(doc).bytesVal(doc, target);
       }
 

Modified: lucene/dev/branches/branch_4x/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/IfFunction.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/IfFunction.java?rev=1617695&r1=1617694&r2=1617695&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/IfFunction.java (original)
+++ lucene/dev/branches/branch_4x/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/IfFunction.java Wed Aug 13 09:36:54 2014
@@ -23,7 +23,7 @@ import org.apache.lucene.queries.functio
 import org.apache.lucene.queries.function.ValueSource;
 import org.apache.lucene.search.Explanation;
 import org.apache.lucene.search.IndexSearcher;
-import org.apache.lucene.util.BytesRef;
+import org.apache.lucene.util.BytesRefBuilder;
 
 import java.io.IOException;
 import java.util.List;
@@ -94,7 +94,7 @@ public class IfFunction extends BoolFunc
       }
 
       @Override
-      public boolean bytesVal(int doc, BytesRef target) {
+      public boolean bytesVal(int doc, BytesRefBuilder target) {
         return ifVals.boolVal(doc) ? trueVals.bytesVal(doc, target) : falseVals.bytesVal(doc, target);
       }
 

Modified: lucene/dev/branches/branch_4x/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/LiteralValueSource.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/LiteralValueSource.java?rev=1617695&r1=1617694&r2=1617695&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/LiteralValueSource.java (original)
+++ lucene/dev/branches/branch_4x/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/LiteralValueSource.java Wed Aug 13 09:36:54 2014
@@ -21,6 +21,7 @@ import org.apache.lucene.queries.functio
 import org.apache.lucene.queries.function.ValueSource;
 import org.apache.lucene.queries.function.docvalues.StrDocValues;
 import org.apache.lucene.util.BytesRef;
+import org.apache.lucene.util.BytesRefBuilder;
 
 import java.util.Map;
 import java.io.IOException;
@@ -54,7 +55,7 @@ public class LiteralValueSource extends 
       }
 
       @Override
-      public boolean bytesVal(int doc, BytesRef target) {
+      public boolean bytesVal(int doc, BytesRefBuilder target) {
         target.copyBytes(bytesRef);
         return true;
       }

Modified: lucene/dev/branches/branch_4x/lucene/queries/src/java/org/apache/lucene/queries/mlt/MoreLikeThis.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/queries/src/java/org/apache/lucene/queries/mlt/MoreLikeThis.java?rev=1617695&r1=1617694&r2=1617695&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/queries/src/java/org/apache/lucene/queries/mlt/MoreLikeThis.java (original)
+++ lucene/dev/branches/branch_4x/lucene/queries/src/java/org/apache/lucene/queries/mlt/MoreLikeThis.java Wed Aug 13 09:36:54 2014
@@ -15,6 +15,15 @@
  */
 package org.apache.lucene.queries.mlt;
 
+import java.io.IOException;
+import java.io.Reader;
+import java.io.StringReader;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
 import org.apache.lucene.analysis.Analyzer;
 import org.apache.lucene.analysis.TokenStream;
 import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
@@ -33,19 +42,9 @@ import org.apache.lucene.search.TermQuer
 import org.apache.lucene.search.similarities.DefaultSimilarity;
 import org.apache.lucene.search.similarities.TFIDFSimilarity;
 import org.apache.lucene.util.BytesRef;
-import org.apache.lucene.util.CharsRef;
+import org.apache.lucene.util.CharsRefBuilder;
 import org.apache.lucene.util.IOUtils;
 import org.apache.lucene.util.PriorityQueue;
-import org.apache.lucene.util.UnicodeUtil;
-
-import java.io.IOException;
-import java.io.Reader;
-import java.io.StringReader;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Set;
 
 
 /**
@@ -761,10 +760,10 @@ public final class MoreLikeThis {
    */
   private void addTermFrequencies(Map<String, Int> termFreqMap, Terms vector) throws IOException {
     final TermsEnum termsEnum = vector.iterator(null);
-    final CharsRef spare = new CharsRef();
+    final CharsRefBuilder spare = new CharsRefBuilder();
     BytesRef text;
     while((text = termsEnum.next()) != null) {
-      UnicodeUtil.UTF8toUTF16(text, spare);
+      spare.copyUTF8Bytes(text);
       final String term = spare.toString();
       if (isNoiseWord(term)) {
         continue;

Modified: lucene/dev/branches/branch_4x/lucene/queries/src/test/org/apache/lucene/queries/function/TestDocValuesFieldSources.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/queries/src/test/org/apache/lucene/queries/function/TestDocValuesFieldSources.java?rev=1617695&r1=1617694&r2=1617695&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/queries/src/test/org/apache/lucene/queries/function/TestDocValuesFieldSources.java (original)
+++ lucene/dev/branches/branch_4x/lucene/queries/src/test/org/apache/lucene/queries/function/TestDocValuesFieldSources.java Wed Aug 13 09:36:54 2014
@@ -34,6 +34,7 @@ import org.apache.lucene.queries.functio
 import org.apache.lucene.queries.function.valuesource.LongFieldSource;
 import org.apache.lucene.store.Directory;
 import org.apache.lucene.util.BytesRef;
+import org.apache.lucene.util.BytesRefBuilder;
 import org.apache.lucene.util.LuceneTestCase;
 import org.apache.lucene.util.LuceneTestCase.SuppressCodecs;
 import org.apache.lucene.util.TestUtil;
@@ -109,7 +110,7 @@ public class TestDocValuesFieldSources e
           throw new AssertionError();
       }
       final FunctionValues values = vs.getValues(null, leave);
-      BytesRef bytes = new BytesRef();
+      BytesRefBuilder bytes = new BytesRefBuilder();
       for (int i = 0; i < leave.reader().maxDoc(); ++i) {
         assertTrue(values.exists(i));
         if (vs instanceof BytesRefFieldSource) {
@@ -132,7 +133,7 @@ public class TestDocValuesFieldSources e
             assertEquals(expected, values.objectVal(i));
             assertEquals(expected, values.strVal(i));
             assertTrue(values.bytesVal(i, bytes));
-            assertEquals(new BytesRef((String) expected), bytes);
+            assertEquals(new BytesRef((String) expected), bytes.get());
             break;
           case NUMERIC:
             assertEquals(((Number) expected).longValue(), values.longVal(i));