1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
package net.minecraft.server;
import java.util.ArrayList;
import java.util.List;
public class Vec3DPool {
private final int a;
private final int b;
// CraftBukkit start
// private final List pool = new ArrayList();
private Vec3D freelist = null;
private Vec3D alloclist = null;
private Vec3D freelisthead = null;
private Vec3D alloclisthead = null;
private int total_size = 0;
// CraftBukkit end
private int position = 0;
private int largestSize = 0;
private int resizeTime = 0;
public Vec3DPool(int i, int j) {
this.a = i;
this.b = j;
}
public final Vec3D create(double d0, double d1, double d2) { // CraftBukkit - add final
if (this.resizeTime == 0) return Vec3D.a(d0, d1, d2); // CraftBukkit - don't pool objects indefinitely if thread doesn't adhere to contract
Vec3D vec3d;
if (this.freelist == null) { // CraftBukkit
vec3d = new Vec3D(this, d0, d1, d2);
this.total_size++; // CraftBukkit
} else {
// CraftBukkit start
vec3d = this.freelist;
this.freelist = vec3d.next;
// CraftBukkit end
vec3d.b(d0, d1, d2);
}
// CraftBukkit start
if (this.alloclist == null) {
this.alloclisthead = vec3d;
}
vec3d.next = this.alloclist; // add to allocated list
this.alloclist = vec3d;
// CraftBukkit end
++this.position;
return vec3d;
}
// CraftBukkit start - offer back vector (can save LOTS of unneeded bloat) - works about 90% of the time
public void release(Vec3D v) {
if (this.alloclist == v) {
this.alloclist = v.next; // Pop off alloc list
// Push on to free list
if (this.freelist == null) this.freelisthead = v;
v.next = this.freelist;
this.freelist = v;
this.position--;
}
}
// CraftBukkit end
public void a() {
if (this.position > this.largestSize) {
this.largestSize = this.position;
}
// CraftBukkit start - intelligent cache
// Take any allocated blocks and put them on free list
if (this.alloclist != null) {
if (this.freelist == null) {
this.freelist = this.alloclist;
this.freelisthead = this.alloclisthead;
}
else {
this.alloclisthead.next = this.freelist;
this.freelist = this.alloclist;
this.freelisthead = this.alloclisthead;
}
this.alloclist = null;
}
if ((this.resizeTime++ & 0xff) == 0) {
int newSize = total_size - (total_size >> 3);
if (newSize > this.largestSize) { // newSize will be 87.5%, but if we were not in that range, we clear some of the cache
for (int i = total_size; i > newSize; i--) {
freelist = freelist.next;
}
total_size = newSize;
}
this.largestSize = 0;
// this.f = 0; // We do not reset to zero; it doubles for a flag
}
// CraftBukkit end
this.position = 0;
}
public int c() {
return this.total_size; // CraftBukkit
}
public int d() {
return this.position;
}
private boolean e() {
return this.b < 0 || this.a < 0;
}
}
|