rename the 3 bytesref.copy methods to avoid type promotion traps

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1205842 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Muir 2011-11-24 14:24:43 +00:00
parent 0ec321de3f
commit 145d6e8d92
4 changed files with 13 additions and 13 deletions

View File

@ -62,11 +62,11 @@ abstract class IndexDocValuesArray extends Source {
} }
void toBytes(long value, BytesRef bytesRef) { void toBytes(long value, BytesRef bytesRef) {
bytesRef.copy(value); bytesRef.copyLong(value);
} }
void toBytes(double value, BytesRef bytesRef) { void toBytes(double value, BytesRef bytesRef) {
bytesRef.copy(Double.doubleToRawLongBits(value)); bytesRef.copyLong(Double.doubleToRawLongBits(value));
} }
final static class ByteValues extends IndexDocValuesArray { final static class ByteValues extends IndexDocValuesArray {
@ -140,7 +140,7 @@ abstract class IndexDocValuesArray extends Source {
} }
void toBytes(long value, BytesRef bytesRef) { void toBytes(long value, BytesRef bytesRef) {
bytesRef.copy((short) (0xFFFFL & value)); bytesRef.copyShort((short) (0xFFFFL & value));
} }
}; };
@ -179,7 +179,7 @@ abstract class IndexDocValuesArray extends Source {
} }
void toBytes(long value, BytesRef bytesRef) { void toBytes(long value, BytesRef bytesRef) {
bytesRef.copy((int) (0xFFFFFFFF & value)); bytesRef.copyInt((int) (0xFFFFFFFF & value));
} }
}; };
@ -252,7 +252,7 @@ abstract class IndexDocValuesArray extends Source {
@Override @Override
void toBytes(double value, BytesRef bytesRef) { void toBytes(double value, BytesRef bytesRef) {
bytesRef.copy(Float.floatToRawIntBits((float)value)); bytesRef.copyInt(Float.floatToRawIntBits((float)value));
} }

View File

@ -73,7 +73,7 @@ class PackedIntValues {
} }
} }
lastDocId = docID; lastDocId = docID;
bytesRef.copy(v); bytesRef.copyLong(v);
add(docID, bytesRef); add(docID, bytesRef);
} }
@ -244,7 +244,7 @@ class PackedIntValues {
@Override @Override
public BytesRef getBytes(int docID, BytesRef ref) { public BytesRef getBytes(int docID, BytesRef ref) {
ref.grow(8); ref.grow(8);
ref.copy(getInt(docID)); ref.copyLong(getInt(docID));
return ref; return ref;
} }

View File

@ -227,7 +227,7 @@ public final class BytesRef implements Comparable<BytesRef> {
* NOTE: this method resets the offset to 0, length to 8 and resizes the reference array * NOTE: this method resets the offset to 0, length to 8 and resizes the reference array
* if needed. * if needed.
*/ */
public void copy(long value) { public void copyLong(long value) {
if (bytes.length < 8) { if (bytes.length < 8) {
bytes = new byte[8]; bytes = new byte[8];
} }
@ -242,7 +242,7 @@ public final class BytesRef implements Comparable<BytesRef> {
* NOTE: this method resets the offset to 0, length to 4 and resizes the reference array * NOTE: this method resets the offset to 0, length to 4 and resizes the reference array
* if needed. * if needed.
*/ */
public void copy(int value) { public void copyInt(int value) {
if (bytes.length < 4) { if (bytes.length < 4) {
bytes = new byte[4]; bytes = new byte[4];
} }
@ -256,7 +256,7 @@ public final class BytesRef implements Comparable<BytesRef> {
* NOTE: this method resets the offset to 0, length to 2 and resizes the reference array * NOTE: this method resets the offset to 0, length to 2 and resizes the reference array
* if needed. * if needed.
*/ */
public void copy(short value) { public void copyShort(short value) {
if (bytes.length < 2) { if (bytes.length < 2) {
bytes = new byte[2]; bytes = new byte[2];
} }

View File

@ -239,17 +239,17 @@ public class TestTypePromotion extends LuceneTestCase {
case BYTES_FIXED_SORTED: case BYTES_FIXED_SORTED:
case BYTES_FIXED_STRAIGHT: case BYTES_FIXED_STRAIGHT:
values[i] = random.nextLong(); values[i] = random.nextLong();
ref.copy(values[i]); ref.copyLong(values[i]);
valField.setBytes(ref, valueType); valField.setBytes(ref, valueType);
break; break;
case BYTES_VAR_DEREF: case BYTES_VAR_DEREF:
case BYTES_VAR_SORTED: case BYTES_VAR_SORTED:
case BYTES_VAR_STRAIGHT: case BYTES_VAR_STRAIGHT:
if (random.nextBoolean()) { if (random.nextBoolean()) {
ref.copy(random.nextInt()); ref.copyInt(random.nextInt());
values[i] = asInt(ref); values[i] = asInt(ref);
} else { } else {
ref.copy(random.nextLong()); ref.copyLong(random.nextLong());
values[i] = asLong(ref); values[i] = asLong(ref);
} }
valField.setBytes(ref, valueType); valField.setBytes(ref, valueType);