/* */ 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 */