You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by si...@apache.org on 2011/11/01 20:41:46 UTC
svn commit: r1196239 - in /lucene/dev/branches/branch_3x: ./ lucene/
lucene/backwards/src/test/ lucene/contrib/analyzers/common/
lucene/src/java/org/apache/lucene/util/
lucene/src/test/org/apache/lucene/util/ solr/
solr/core/src/test/org/apache/solr/an...
Author: simonw
Date: Tue Nov 1 19:41:45 2011
New Revision: 1196239
URL: http://svn.apache.org/viewvc?rev=1196239&view=rev
Log:
LUCENE-3548: fix broken CharsRef#append
Modified:
lucene/dev/branches/branch_3x/ (props changed)
lucene/dev/branches/branch_3x/lucene/ (props changed)
lucene/dev/branches/branch_3x/lucene/CHANGES.txt
lucene/dev/branches/branch_3x/lucene/backwards/src/test/ (props changed)
lucene/dev/branches/branch_3x/lucene/contrib/analyzers/common/ (props changed)
lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/util/CharsRef.java
lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/util/TestCharsRef.java
lucene/dev/branches/branch_3x/solr/ (props changed)
lucene/dev/branches/branch_3x/solr/core/src/test/org/apache/solr/analysis/TestPhoneticFilterFactory.java (props changed)
Modified: lucene/dev/branches/branch_3x/lucene/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/CHANGES.txt?rev=1196239&r1=1196238&r2=1196239&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/CHANGES.txt (original)
+++ lucene/dev/branches/branch_3x/lucene/CHANGES.txt Tue Nov 1 19:41:45 2011
@@ -90,6 +90,9 @@ Bug fixes
* LUCENE-3541: IndexInput's default copyBytes() implementation was not safe
across multiple threads, because all clones shared the same buffer.
(Robert Muir)
+
+* LUCENE-3548: Fix CharsRef#append to extend length of the existing char[]
+ and presever existing chars. (Simon Willnauer)
New Features
Modified: lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/util/CharsRef.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/util/CharsRef.java?rev=1196239&r1=1196238&r2=1196239&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/util/CharsRef.java (original)
+++ lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/util/CharsRef.java Tue Nov 1 19:41:45 2011
@@ -189,18 +189,22 @@ public final class CharsRef implements C
* Copies the given array into this CharsRef starting at offset 0
*/
public void copy(char[] otherChars, int otherOffset, int otherLength) {
+ grow(otherLength);
+ System.arraycopy(otherChars, otherOffset, this.chars, 0,
+ otherLength);
this.offset = 0;
- append(otherChars, otherOffset, otherLength);
+ this.length = otherLength;
}
/**
- * Appends the given array to this CharsRef starting at the current offset
+ * Appends the given array to this CharsRef
*/
public void append(char[] otherChars, int otherOffset, int otherLength) {
- grow(this.offset + otherLength);
- System.arraycopy(otherChars, otherOffset, this.chars, this.offset,
+ final int newLength = length + otherLength;
+ grow(this.offset + newLength);
+ System.arraycopy(otherChars, otherOffset, this.chars, this.offset+length,
otherLength);
- this.length = otherLength;
+ this.length += otherLength;
}
@Override
Modified: lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/util/TestCharsRef.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/util/TestCharsRef.java?rev=1196239&r1=1196238&r2=1196239&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/util/TestCharsRef.java (original)
+++ lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/util/TestCharsRef.java Tue Nov 1 19:41:45 2011
@@ -38,4 +38,33 @@ public class TestCharsRef extends Lucene
assertEquals(utf8[i].utf8ToString(), utf16[i].toString());
}
}
+
+ public void testAppend() {
+ CharsRef ref = new CharsRef();
+ StringBuilder builder = new StringBuilder();
+ int numStrings = atLeast(10);
+ for (int i = 0; i < numStrings; i++) {
+ char[] charArray = _TestUtil.randomRealisticUnicodeString(random, 1, 100).toCharArray();
+ int offset = random.nextInt(charArray.length);
+ int length = charArray.length - offset;
+ builder.append(charArray, offset, length);
+ ref.append(charArray, offset, length);
+ }
+
+ assertEquals(builder.toString(), ref.toString());
+ }
+
+ public void testCopy() {
+ int numIters = atLeast(10);
+ for (int i = 0; i < numIters; i++) {
+ CharsRef ref = new CharsRef();
+ char[] charArray = _TestUtil.randomRealisticUnicodeString(random, 1, 100).toCharArray();
+ int offset = random.nextInt(charArray.length);
+ int length = charArray.length - offset;
+ String str = new String(charArray, offset, length);
+ ref.copy(charArray, offset, length);
+ assertEquals(str, ref.toString());
+ }
+
+ }
}