Skip to content

Commit f3069d9

Browse files
author
akonyaev
committed
remove bytes array revers
1 parent 830cb34 commit f3069d9

File tree

1 file changed

+13
-32
lines changed

1 file changed

+13
-32
lines changed

src/main/java/ru/yandex/clickhouse/util/ClickHouseRowBinaryStream.java

Lines changed: 13 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
import java.util.UUID;
1818
import java.util.concurrent.TimeUnit;
1919

20-
import static com.google.common.primitives.Bytes.concat;
21-
2220
/**
2321
* @author Dmitry Andreev <a href="mailto:[email protected]"></a>
2422
*/
@@ -168,44 +166,27 @@ public void writeFloat64(double value) throws IOException {
168166
out.writeDouble(value);
169167
}
170168

171-
public static void reverse(byte[] array) {
172-
if (array == null) {
173-
return;
174-
}
175-
int i = 0;
176-
int j = array.length - 1;
177-
byte tmp;
178-
while (j > i) {
179-
tmp = array[j];
180-
array[j] = array[i];
181-
array[i] = tmp;
182-
j--;
183-
i++;
184-
}
185-
}
186-
187-
byte[] bigDecimalToByte(BigDecimal num, int bytesLen, int scale) {
169+
private BigInteger removeComma(BigDecimal num, int scale) {
188170
BigDecimal ten = BigDecimal.valueOf(10);
189171
BigDecimal s = ten.pow(scale);
190-
BigInteger res = num.multiply(s).toBigInteger();
191-
byte[] r = res.toByteArray();
192-
reverse(r);
193-
return concat(r, new byte[bytesLen - r.length]);
172+
return num.multiply(s).toBigInteger();
194173
}
195174

196-
public void writeDecimal128(BigDecimal v, int scale) throws IOException {
197-
byte[] x = bigDecimalToByte(v, 16, scale);
198-
out.write(x);
175+
public void writeDecimal128(BigDecimal num, int scale) throws IOException {
176+
BigInteger bi = removeComma(num, scale);
177+
byte[] r = bi.toByteArray();
178+
for (int i = r.length; i > 0; i--) {
179+
out.write(r[i - 1]);
180+
}
181+
out.write(new byte[16 - r.length]);
199182
}
200183

201-
public void writeDecimal64(BigDecimal v, int scale) throws IOException {
202-
byte[] x = bigDecimalToByte(v, 8, scale);
203-
out.write(x);
184+
public void writeDecimal64(BigDecimal num, int scale) throws IOException {
185+
out.writeLong(removeComma(num, scale).longValue());
204186
}
205187

206-
public void writeDecimal32(BigDecimal v, int scale) throws IOException {
207-
byte[] x = bigDecimalToByte(v, 4, scale);
208-
out.write(x);
188+
public void writeDecimal32(BigDecimal num, int scale) throws IOException {
189+
out.writeInt(removeComma(num, scale).intValue());
209190
}
210191

211192
public void writeDateArray(Date[] dates) throws IOException {

0 commit comments

Comments
 (0)