blob: 3f5988c66c3902b83fe23742d3d8bc714897255d (
plain) (
blame)
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
|
/* */ package NET.worlds.scape;
/* */
/* */ import NET.worlds.console.Main;
/* */ import NET.worlds.console.MainCallback;
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */ public class Recycler
/* */ implements MainCallback
/* */ {
/* 33 */ private static int minCapacity = 50;
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* 43 */ private Object[] list = new Object[minCapacity];
/* */
/* */
/* */
/* */
/* 48 */ private int numFilled = 0;
/* */
/* */
/* */
/* */
/* */
/* 54 */ private int numAllocked = 0;
/* */
/* 56 */ private int maxAllockedRecently = 0;
/* 57 */ private int howRecently = 0;
/* */
/* */ Recycler()
/* */ {
/* 61 */ Main.register(this);
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */ private void resizeTo(int newCapacity)
/* */ {
/* 70 */ assert (newCapacity > this.numAllocked);
/* */
/* 72 */ if (newCapacity < minCapacity) {
/* 73 */ newCapacity = minCapacity;
/* */ }
/* */
/* */
/* 77 */ if ((newCapacity < this.list.length) &&
/* 78 */ (this.list.length < 2 * newCapacity))
/* */ {
/* 80 */ while (this.numFilled > newCapacity) {
/* 81 */ this.list[(--this.numFilled)] = null;
/* */ }
/* */ } else {
/* 84 */ Object[] newList = new Object[newCapacity];
/* */ try {
/* 86 */ System.arraycopy(this.list, 0, newList, 0, this.numAllocked);
/* 87 */ } catch (Exception e) { throw new Error(e.toString());
/* */ }
/* 89 */ this.list = newList;
/* 90 */ this.numFilled = this.numAllocked;
/* */ }
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */
/* */ public void mainCallback()
/* */ {
/* 101 */ if (this.numAllocked > this.maxAllockedRecently) {
/* 102 */ this.maxAllockedRecently = this.numAllocked;
/* */ }
/* 104 */ if (++this.howRecently == 1000)
/* */ {
/* 106 */ int newCapacity = this.maxAllockedRecently + minCapacity;
/* */
/* */
/* 109 */ if (newCapacity < this.list.length) {
/* 110 */ resizeTo(newCapacity);
/* */ }
/* 112 */ this.howRecently = 0;
/* 113 */ this.maxAllockedRecently = this.numAllocked;
/* */ }
/* */
/* 116 */ this.numAllocked = 0;
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */ public Object alloc()
/* */ {
/* 125 */ assert (Main.isMainThread());
/* */
/* 127 */ if (this.numAllocked == this.numFilled) {
/* 128 */ return null;
/* */ }
/* 130 */ return this.list[(this.numAllocked++)];
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */ public void recycle(Object o)
/* */ {
/* 142 */ if (this.numFilled == this.list.length)
/* */ {
/* 144 */ resizeTo(this.list.length * 2);
/* */ }
/* 146 */ this.list[(this.numFilled++)] = o;
/* */ }
/* */ }
/* Location: C:\Program Files (x86)\Worlds Inc\WorldsPlayer - Win7\lib\worlds.jar!\NET\worlds\scape\Recycler.class
* Java compiler version: 6 (50.0)
* JD-Core Version: 0.7.1
*/
|