@Test public void stress_compareBytes_diff_scale() throws Exception { int count = 10000000; byte[] a = toBytes(new DecimalOption(new BigDecimal("3.14"))); byte[] b = toBytes(new DecimalOption(new BigDecimal("1.414"))); for (int i = 0; i < count; i++) { DecimalOption.compareBytes(a, 0, a.length, b, 0, b.length); } }
public static int compareBytes( byte[] b1, int s1, int l1, byte[] b2, int s2, int l2) { try { int cursor1 = s1; int cursor2 = s2; int h1 = b1[cursor1++] & 0xff; int h2 = b2[cursor2++] & 0xff; boolean null1 = (h1 & MASK_PRESENT) == 0; boolean null2 = (h2 & MASK_PRESENT) == 0; if (null1) { if (null2) { return 0; } else { return -1; } } else if (null2) { return +1; } boolean plus1 = (h1 & MASK_PLUS) != 0; boolean plus2 = (h2 & MASK_PLUS) != 0; if (plus1 && plus2 == false) { return +1; } else if (plus1 == false && plus2) { return -1; } int scale1 = WritableComparator.readVInt(b1, cursor1); int scale2 = WritableComparator.readVInt(b2, cursor2); cursor1 += WritableUtils.decodeVIntSize(b1[cursor1]); cursor2 += WritableUtils.decodeVIntSize(b2[cursor2]); int bytesCount1 = WritableComparator.readVInt(b1, cursor1); int bytesCount2 = WritableComparator.readVInt(b2, cursor2); cursor1 += WritableUtils.decodeVIntSize(b1[cursor1]); cursor2 += WritableUtils.decodeVIntSize(b2[cursor2]); DecimalBuffer d1 = BUFFER_MAIN.get(); d1.set(plus1, scale1, b1, cursor1, bytesCount1); DecimalBuffer d2 = BUFFER_SUB.get(); d2.set(plus2, scale2, b2, cursor2, bytesCount2); return DecimalBuffer.compare(d1, d2); } catch (IOException e) { throw new IllegalStateException(e); } }
DecimalOption extends ValueOption<DecimalOption> { public static int compareBytes( byte[] b1, int s1, int l1, byte[] b2, int s2, int l2) { try { int cursor1 = s1; int cursor2 = s2; int h1 = b1[cursor1++] & 0xff; int h2 = b2[cursor2++] & 0xff; boolean null1 = (h1 & MASK_PRESENT) == 0; boolean null2 = (h2 & MASK_PRESENT) == 0; if (null1) { if (null2) { return 0; } else { return -1; } } else if (null2) { return +1; } boolean plus1 = (h1 & MASK_PLUS) != 0; boolean plus2 = (h2 & MASK_PLUS) != 0; if (plus1 && plus2 == false) { return +1; } else if (plus1 == false && plus2) { return -1; } int scale1 = WritableComparator.readVInt(b1, cursor1); int scale2 = WritableComparator.readVInt(b2, cursor2); cursor1 += WritableUtils.decodeVIntSize(b1[cursor1]); cursor2 += WritableUtils.decodeVIntSize(b2[cursor2]); int bytesCount1 = WritableComparator.readVInt(b1, cursor1); int bytesCount2 = WritableComparator.readVInt(b2, cursor2); cursor1 += WritableUtils.decodeVIntSize(b1[cursor1]); cursor2 += WritableUtils.decodeVIntSize(b2[cursor2]); DecimalBuffer d1 = BUFFER_MAIN.get(); d1.set(plus1, scale1, b1, cursor1, bytesCount1); DecimalBuffer d2 = BUFFER_SUB.get(); d2.set(plus2, scale2, b2, cursor2, bytesCount2); return DecimalBuffer.compare(d1, d2); } catch (IOException e) { throw new IllegalStateException(e); } } }
DecimalOption extends ValueOption<DecimalOption> { public static int compareBytes( byte[] b1, int s1, int l1, byte[] b2, int s2, int l2) { try { int cursor1 = s1; int cursor2 = s2; int h1 = b1[cursor1++] & 0xff; int h2 = b2[cursor2++] & 0xff; boolean null1 = (h1 & MASK_PRESENT) == 0; boolean null2 = (h2 & MASK_PRESENT) == 0; if (null1) { if (null2) { return 0; } else { return -1; } } else if (null2) { return +1; } boolean plus1 = (h1 & MASK_PLUS) != 0; boolean plus2 = (h2 & MASK_PLUS) != 0; if (plus1 && plus2 == false) { return +1; } else if (plus1 == false && plus2) { return -1; } int scale1 = WritableComparator.readVInt(b1, cursor1); int scale2 = WritableComparator.readVInt(b2, cursor2); cursor1 += WritableUtils.decodeVIntSize(b1[cursor1]); cursor2 += WritableUtils.decodeVIntSize(b2[cursor2]); int bytesCount1 = WritableComparator.readVInt(b1, cursor1); int bytesCount2 = WritableComparator.readVInt(b2, cursor2); cursor1 += WritableUtils.decodeVIntSize(b1[cursor1]); cursor2 += WritableUtils.decodeVIntSize(b2[cursor2]); DecimalBuffer d1 = BUFFER_MAIN.get(); d1.set(plus1, scale1, b1, cursor1, bytesCount1); DecimalBuffer d2 = BUFFER_SUB.get(); d2.set(plus2, scale2, b2, cursor2, bytesCount2); return DecimalBuffer.compare(d1, d2); } catch (IOException e) { throw new IllegalStateException(e); } } DecimalOption();  DecimalOption(BigDecimal valueOrNull); }
DecimalOption extends ValueOption<DecimalOption> { public static int compareBytes( byte[] b1, int s1, int l1, byte[] b2, int s2, int l2) { try { int cursor1 = s1; int cursor2 = s2; int h1 = b1[cursor1++] & 0xff; int h2 = b2[cursor2++] & 0xff; boolean null1 = (h1 & MASK_PRESENT) == 0; boolean null2 = (h2 & MASK_PRESENT) == 0; if (null1) { if (null2) { return 0; } else { return -1; } } else if (null2) { return +1; } boolean plus1 = (h1 & MASK_PLUS) != 0; boolean plus2 = (h2 & MASK_PLUS) != 0; if (plus1 && plus2 == false) { return +1; } else if (plus1 == false && plus2) { return -1; } int scale1 = WritableComparator.readVInt(b1, cursor1); int scale2 = WritableComparator.readVInt(b2, cursor2); cursor1 += WritableUtils.decodeVIntSize(b1[cursor1]); cursor2 += WritableUtils.decodeVIntSize(b2[cursor2]); int bytesCount1 = WritableComparator.readVInt(b1, cursor1); int bytesCount2 = WritableComparator.readVInt(b2, cursor2); cursor1 += WritableUtils.decodeVIntSize(b1[cursor1]); cursor2 += WritableUtils.decodeVIntSize(b2[cursor2]); DecimalBuffer d1 = BUFFER_MAIN.get(); d1.set(plus1, scale1, b1, cursor1, bytesCount1); DecimalBuffer d2 = BUFFER_SUB.get(); d2.set(plus2, scale2, b2, cursor2, bytesCount2); return DecimalBuffer.compare(d1, d2); } catch (IOException e) { throw new IllegalStateException(e); } } DecimalOption();  DecimalOption(BigDecimal valueOrNull); BigDecimal get(); BigDecimal or(BigDecimal alternate); void add(BigDecimal delta); void add(DecimalOption other); @Deprecated DecimalOption modify(BigDecimal newValue); @Override @Deprecated void copyFrom(DecimalOption optionOrNull); @Override int hashCode(); @Override boolean equals(Object obj); boolean has(BigDecimal other); @Override int compareTo(WritableRawComparable o); @Override String toString(); @Override void write(DataOutput out); @SuppressWarnings("deprecation") @Override void readFields(DataInput in); @SuppressWarnings("deprecation") @Override int restore(byte[] bytes, int offset, int limit); @Override int getSizeInBytes(byte[] buf, int offset); @Override int compareInBytes(byte[] b1, int o1, byte[] b2, int o2); static int getBytesLength(byte[] bytes, int offset, int length); static int compareBytes(
            byte[] b1, int s1, int l1,
            byte[] b2, int s2, int l2); }
DecimalOption extends ValueOption<DecimalOption> { public static int compareBytes( byte[] b1, int s1, int l1, byte[] b2, int s2, int l2) { try { int cursor1 = s1; int cursor2 = s2; int h1 = b1[cursor1++] & 0xff; int h2 = b2[cursor2++] & 0xff; boolean null1 = (h1 & MASK_PRESENT) == 0; boolean null2 = (h2 & MASK_PRESENT) == 0; if (null1) { if (null2) { return 0; } else { return -1; } } else if (null2) { return +1; } boolean plus1 = (h1 & MASK_PLUS) != 0; boolean plus2 = (h2 & MASK_PLUS) != 0; if (plus1 && plus2 == false) { return +1; } else if (plus1 == false && plus2) { return -1; } int scale1 = WritableComparator.readVInt(b1, cursor1); int scale2 = WritableComparator.readVInt(b2, cursor2); cursor1 += WritableUtils.decodeVIntSize(b1[cursor1]); cursor2 += WritableUtils.decodeVIntSize(b2[cursor2]); int bytesCount1 = WritableComparator.readVInt(b1, cursor1); int bytesCount2 = WritableComparator.readVInt(b2, cursor2); cursor1 += WritableUtils.decodeVIntSize(b1[cursor1]); cursor2 += WritableUtils.decodeVIntSize(b2[cursor2]); DecimalBuffer d1 = BUFFER_MAIN.get(); d1.set(plus1, scale1, b1, cursor1, bytesCount1); DecimalBuffer d2 = BUFFER_SUB.get(); d2.set(plus2, scale2, b2, cursor2, bytesCount2); return DecimalBuffer.compare(d1, d2); } catch (IOException e) { throw new IllegalStateException(e); } } DecimalOption();  DecimalOption(BigDecimal valueOrNull); BigDecimal get(); BigDecimal or(BigDecimal alternate); void add(BigDecimal delta); void add(DecimalOption other); @Deprecated DecimalOption modify(BigDecimal newValue); @Override @Deprecated void copyFrom(DecimalOption optionOrNull); @Override int hashCode(); @Override boolean equals(Object obj); boolean has(BigDecimal other); @Override int compareTo(WritableRawComparable o); @Override String toString(); @Override void write(DataOutput out); @SuppressWarnings("deprecation") @Override void readFields(DataInput in); @SuppressWarnings("deprecation") @Override int restore(byte[] bytes, int offset, int limit); @Override int getSizeInBytes(byte[] buf, int offset); @Override int compareInBytes(byte[] b1, int o1, byte[] b2, int o2); static int getBytesLength(byte[] bytes, int offset, int length); static int compareBytes(
            byte[] b1, int s1, int l1,
            byte[] b2, int s2, int l2);  }