9
0
mirror of https://github.com/Winds-Studio/Leaf.git synced 2025-12-26 18:39:23 +00:00
Files
Leaf/leaf-server/minecraft-patches/features/0127-Bulk-writes-to-writeLongArray-during-chunk-loading.patch
Taiyou cbcc54726a Async playerPacket sending (#245)
* async player packet sending

* small cleanup

* eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee

* holy shit this is fast

* some cleanup

* change .size to O(1)

* rewrite starts (i need to do this OMEGA SAFE)

* rebuilt

* rebase

* Rewritten AsyncPacketSending
2025-03-25 03:20:49 -04:00

47 lines
2.0 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Taiyou06 <kaandindar21@gmail.com>
Date: Fri, 21 Feb 2025 15:06:55 +0100
Subject: [PATCH] Bulk writes to writeLongArray during chunk loading
diff --git a/net/minecraft/network/FriendlyByteBuf.java b/net/minecraft/network/FriendlyByteBuf.java
index abb0141426fd716e79a947b9498a8351daa342fc..5353b8331cf9c428ab7ffba6ebeac4fa323af456 100644
--- a/net/minecraft/network/FriendlyByteBuf.java
+++ b/net/minecraft/network/FriendlyByteBuf.java
@@ -341,10 +341,33 @@ public class FriendlyByteBuf extends ByteBuf {
public FriendlyByteBuf writeLongArray(long[] array) {
this.writeVarInt(array.length);
+ // Leaf start - Bulk writes to writeLongArray during chunk loading
+ if (array.length == 0) {
+ return this;
+ }
+
+ this.source.ensureWritable(array.length * Long.BYTES);
+ int writerIndex = this.source.writerIndex();
+
+ if (this.source.hasArray()) {
+ byte[] dest = this.source.array();
+ int offset = this.source.arrayOffset() + writerIndex;
- for (long l : array) {
- this.writeLong(l);
+ ByteBuffer buf = ByteBuffer.wrap(dest, offset, array.length * Long.BYTES).order(this.source.order());
+ buf.asLongBuffer().put(array);
+
+ this.source.writerIndex(writerIndex + array.length * Long.BYTES);
+ } else if (this.source.nioBufferCount() > 0) {
+ ByteBuffer nioBuf = this.source.nioBuffer(writerIndex, array.length * Long.BYTES);
+ nioBuf.asLongBuffer().put(array);
+ this.source.writerIndex(writerIndex + array.length * Long.BYTES);
+ } else {
+ ByteBuffer temp = ByteBuffer.allocate(array.length * Long.BYTES).order(this.source.order());
+ temp.asLongBuffer().put(array);
+ temp.rewind();
+ this.source.writeBytes(temp);
}
+ // Leaf end - Bulk writes to writeLongArray during chunk loading
return this;
}