Skip to content

Commit e4f322e

Browse files
committed
Use systemarray copy in when converting int/long to byte array instead of manual
1 parent b932b28 commit e4f322e

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

src/main/java/at/favre/lib/bytes/Util.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,7 @@ static byte[] toByteArray(int[] intArray) {
202202
byte[] primitivesArray = new byte[intArray.length * 4];
203203
for (int i = 0; i < intArray.length; i++) {
204204
byte[] intBytes = ByteBuffer.allocate(4).putInt(intArray[i]).array();
205-
for (int j = 0; j < intBytes.length; j++) {
206-
primitivesArray[(i * 4) + j] = intBytes[j];
207-
}
205+
System.arraycopy(intBytes, 0, primitivesArray, (i * 4), intBytes.length);
208206
}
209207
return primitivesArray;
210208
}
@@ -220,9 +218,7 @@ static byte[] toByteArray(long[] longArray) {
220218
byte[] primitivesArray = new byte[longArray.length * 8];
221219
for (int i = 0; i < longArray.length; i++) {
222220
byte[] longBytes = ByteBuffer.allocate(8).putLong(longArray[i]).array();
223-
for (int j = 0; j < longBytes.length; j++) {
224-
primitivesArray[(i * 8) + j] = longBytes[j];
225-
}
221+
System.arraycopy(longBytes, 0, primitivesArray, (i * 8), longBytes.length);
226222
}
227223
return primitivesArray;
228224
}

0 commit comments

Comments
 (0)