diff options
| author | Fuwn <[email protected]> | 2021-05-03 16:38:41 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2021-05-03 16:38:41 -0700 |
| commit | e1e781bb2135ef78592226f1a3eaba4925702f1f (patch) | |
| tree | 8a5b590463ed413e1c6eabb719130e701b95ca63 /NET/worlds/scape/Recycler.java | |
| download | worlds.jar-main.tar.xz worlds.jar-main.zip | |
Diffstat (limited to 'NET/worlds/scape/Recycler.java')
| -rw-r--r-- | NET/worlds/scape/Recycler.java | 154 |
1 files changed, 154 insertions, 0 deletions
diff --git a/NET/worlds/scape/Recycler.java b/NET/worlds/scape/Recycler.java new file mode 100644 index 0000000..3f5988c --- /dev/null +++ b/NET/worlds/scape/Recycler.java @@ -0,0 +1,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 + */
\ No newline at end of file |