From 1192646b168ce0a4844f3906fe920c25cf617f6c Mon Sep 17 00:00:00 2001 From: retgal Date: Fri, 27 Dec 2024 19:21:35 +0100 Subject: [PATCH] Reduce method calls --- .../mpo/dayon/common/buffer/MemByteBuffer.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/main/java/mpo/dayon/common/buffer/MemByteBuffer.java b/src/main/java/mpo/dayon/common/buffer/MemByteBuffer.java index 29d9d3d7..88aa19ad 100644 --- a/src/main/java/mpo/dayon/common/buffer/MemByteBuffer.java +++ b/src/main/java/mpo/dayon/common/buffer/MemByteBuffer.java @@ -85,15 +85,20 @@ public void write(byte[] buffer, int off, int len) { * Equivalent to the DataOutputStream version (!) */ public final void writeInt(int val) { - write((val >>> 24) & 0xFF, (val >>> 16) & 0xFF); - write((val >>> 8) & 0xFF, val & 0xFF); + ensureCapacity(count + 4); + buffer[count++] = (byte) ((val >>> 24) & 0xFF); + buffer[count++] = (byte) ((val >>> 16) & 0xFF); + buffer[count++] = (byte) ((val >>> 8) & 0xFF); + buffer[count++] = (byte) (val & 0xFF); } /** * Equivalent to the DataOutputStream version (!) */ public final void writeShort(int val) { - write((val >>> 8) & 0xFF, val & 0xFF); + ensureCapacity(count + 2); + buffer[count++] = (byte) ((val >>> 8) & 0xFF); + buffer[count++] = (byte) (val & 0xFF); } public void writeLenAsShort(int mark) { @@ -106,9 +111,7 @@ public void writeLenAsShort(int mark) { public void fill(int len, int val) { ensureCapacity(count + len); - for (int i = count; i < count + len; i++) { - buffer[i] = (byte) val; - } + Arrays.fill(buffer, count, count + len, (byte) val); count += len; }