summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorWesley Wolfe <weswolf@aol.com>2012-08-05 21:36:25 -0500
committerWesley Wolfe <weswolf@aol.com>2012-08-05 21:36:25 -0500
commit9cccb1c89e45edbba80e2ccb5e048f194129f2a7 (patch)
tree663517f6a8c5269a047e5387d829e28eff6c870a /src
parentf5777cc0b726aa87fa2af245cc57d4e809143638 (diff)
downloadcraftbukkit-9cccb1c89e45edbba80e2ccb5e048f194129f2a7.tar
craftbukkit-9cccb1c89e45edbba80e2ccb5e048f194129f2a7.tar.gz
craftbukkit-9cccb1c89e45edbba80e2ccb5e048f194129f2a7.tar.lz
craftbukkit-9cccb1c89e45edbba80e2ccb5e048f194129f2a7.tar.xz
craftbukkit-9cccb1c89e45edbba80e2ccb5e048f194129f2a7.zip
Fix Vec3DPool; don't pool objects indefinitely or O(n^2) clear()
Diffstat (limited to 'src')
-rw-r--r--src/main/java/net/minecraft/server/Vec3DPool.java16
1 files changed, 10 insertions, 6 deletions
diff --git a/src/main/java/net/minecraft/server/Vec3DPool.java b/src/main/java/net/minecraft/server/Vec3DPool.java
index 1d7e8e1b..33e21ef2 100644
--- a/src/main/java/net/minecraft/server/Vec3DPool.java
+++ b/src/main/java/net/minecraft/server/Vec3DPool.java
@@ -18,6 +18,7 @@ public class Vec3DPool {
}
public Vec3D create(double d0, double d1, double d2) {
+ if (this.f == 0) return new Vec3D(d0, d1, d2); // CraftBukkit - don't pool objects indefinitely if thread doesn't adhere to contract
Vec3D vec3d;
if (this.d >= this.c.size()) {
@@ -37,16 +38,19 @@ public class Vec3DPool {
this.e = this.d;
}
- if (this.f++ == this.a) {
- int i = Math.max(this.e, this.c.size() - this.b);
-
- while (this.c.size() > i) {
- this.c.remove(i);
+ // CraftBukkit start - intelligent cache
+ if ((this.f++ & 0xff) == 0) {
+ int newSize = this.c.size() - (this.c.size() >> 3);
+ if (newSize > this.e) { // newSize will be 87.5%, but if we were not in that range, we clear some of the cache
+ for (int i = this.c.size() - 1; i > newSize; i--) { // Work down from size() to prevent insane array copies
+ this.c.remove(i);
+ }
}
this.e = 0;
- this.f = 0;
+ // this.f = 0; // We do not reset to zero; it doubles for a flag
}
+ // CraftBukkit end
this.d = 0;
}