Use simpler iterator

This commit is contained in:
md_5 2014-01-28 21:46:15 +11:00
parent 202b1fd11d
commit 23615e1c9f

View file

@ -1,4 +1,4 @@
From 7acc085a95961261de6b3e68d46ec46e974a2c3b Mon Sep 17 00:00:00 2001
From c1d148a1f2b801d24c81d9ffdbfb8669de69cc55 Mon Sep 17 00:00:00 2001
From: md_5 <git@md-5.net>
Date: Tue, 28 Jan 2014 20:32:07 +1100
Subject: [PATCH] Implement Threaded Bulk Chunk Compression and Caching
@ -79,10 +79,10 @@ index fb95be4..2875c94 100644
ServerConnection.a(this.a).add(networkmanager);
diff --git a/src/main/java/org/spigotmc/ChunkCompressor.java b/src/main/java/org/spigotmc/ChunkCompressor.java
new file mode 100644
index 0000000..023900f
index 0000000..3fd45dc
--- /dev/null
+++ b/src/main/java/org/spigotmc/ChunkCompressor.java
@@ -0,0 +1,65 @@
@@ -0,0 +1,64 @@
+package org.spigotmc;
+
+import java.util.Arrays;
@ -131,12 +131,11 @@ index 0000000..023900f
+ chunk.compress(); // Compress the chunk
+ byte[] buffer = Arrays.copyOf( chunk.buffer, chunk.size ); // Resize the array to correct sizing
+
+ Iterator<Map.Entry<Integer, byte[]>> iter = cache.entrySet().iterator(); // Grab a single iterator reference
+ Iterator<byte[]> iter = cache.values().iterator(); // Grab a single iterator reference
+ // Whilst this next entry is too big for us, and we have stuff to remove
+ while ( cacheSize + buffer.length > org.spigotmc.SpigotConfig.chunkCacheBytes && iter.hasNext() )
+ {
+ Map.Entry<Integer, byte[]> entry = iter.next(); // Grab entry
+ cacheSize -= entry.getValue().length; // Update size table
+ cacheSize -= iter.next().length; // Update size table
+ iter.remove(); // Remove it alltogether
+ }
+ cacheSize += buffer.length; // Update size table