Skip to content

Commit

Permalink
Reduce method calls
Browse files Browse the repository at this point in the history
  • Loading branch information
RetGal committed Dec 27, 2024
1 parent b74c046 commit 1192646
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/main/java/mpo/dayon/common/buffer/MemByteBuffer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
}

Expand Down

0 comments on commit 1192646

Please sign in to comment.