diff --git a/vtm/src/org/oscim/renderer/MapRenderer.java b/vtm/src/org/oscim/renderer/MapRenderer.java index 299d4ad7..02c748e7 100644 --- a/vtm/src/org/oscim/renderer/MapRenderer.java +++ b/vtm/src/org/oscim/renderer/MapRenderer.java @@ -74,12 +74,12 @@ public class MapRenderer { } public BufferItem get(int size) { - BufferItem b = pool; + BufferItem b = mPool; if (b == null) { b = new BufferItem(); } else { - pool = b.next; + mPool = b.next; b.next = null; } if (b.tmpBufferSize < size) diff --git a/vtm/src/org/oscim/renderer/elements/SymbolItem.java b/vtm/src/org/oscim/renderer/elements/SymbolItem.java index 5f764b0b..375ad886 100644 --- a/vtm/src/org/oscim/renderer/elements/SymbolItem.java +++ b/vtm/src/org/oscim/renderer/elements/SymbolItem.java @@ -24,7 +24,7 @@ import org.oscim.utils.pool.SyncPool; public class SymbolItem extends Inlist { - public final static SyncPool pool = new SyncPool() { + public final static SyncPool pool = new SyncPool(128) { @Override protected SymbolItem createItem() { diff --git a/vtm/src/org/oscim/utils/pool/Inlist.java b/vtm/src/org/oscim/utils/pool/Inlist.java index 020b67fd..d2bfca4e 100644 --- a/vtm/src/org/oscim/utils/pool/Inlist.java +++ b/vtm/src/org/oscim/utils/pool/Inlist.java @@ -30,9 +30,11 @@ import javax.annotation.CheckReturnValue; */ public class Inlist> { /** UNTESTED */ - public static class List> implements Iterable { - T head; - T cur; + + @SuppressWarnings({ "rawtypes", "unchecked" }) + public static class List> implements Iterable { + Inlist head; + Inlist cur; Iterator mIterator = new Iterator() { @Override @@ -45,14 +47,14 @@ public class Inlist> { if (cur == null) throw new IllegalStateException(); - T tmp = cur; + Inlist tmp = cur; cur = cur.next; - return tmp; + return (T) tmp; } @Override public void remove() { - T tmp = cur.next; + T tmp = (T) cur.next; head = Inlist.remove(head, cur); cur = tmp; } @@ -65,7 +67,7 @@ public class Inlist> { } public void push(T it) { - it.next = head; + ((Inlist) it).next = head; head = it; } @@ -75,19 +77,23 @@ public class Inlist> { } public T clear() { - T ret = head; + Inlist ret = head; head = null; cur = null; - return ret; + return (T) ret; } public T getHead() { - return head; + return (T) head; } } public T next; + public T next() { + return next; + } + /** * Push 'item' onto 'list'. * diff --git a/vtm/src/org/oscim/utils/pool/Pool.java b/vtm/src/org/oscim/utils/pool/Pool.java index cc84fa32..4e623288 100644 --- a/vtm/src/org/oscim/utils/pool/Pool.java +++ b/vtm/src/org/oscim/utils/pool/Pool.java @@ -18,11 +18,11 @@ package org.oscim.utils.pool; import javax.annotation.CheckReturnValue; -public abstract class Pool> { - - protected T pool; - protected int limit; - protected int fill; +@SuppressWarnings({ "rawtypes", "unchecked" }) +public abstract class Pool> { + protected T mPool; + protected int mLimit; + protected int mFill; /** * @param item release resources @@ -47,8 +47,8 @@ public abstract class Pool> { if (!clearItem(item)) return null; - item.next = pool; - pool = item; + ((Inlist) item).next = mPool; + mPool = item; return null; } @@ -65,12 +65,13 @@ public abstract class Pool> { return null; while (list != null) { - T next = list.next; + + T next = (T) list.next; clearItem(list); - list.next = pool; - pool = list; + ((Inlist) list).next = mPool; + mPool = list; list = next; } @@ -84,21 +85,21 @@ public abstract class Pool> { clearItem(item); - Inlist.remove(list, item); + Inlist.remove((Inlist) list, item); return list; } /** get an item from pool */ public T get() { - if (pool == null) + if (mPool == null) return createItem(); - T ret = pool; - pool = pool.next; + Inlist ret = mPool; + mPool = (T) mPool.next; ret.next = null; - return ret; + return (T) ret; } protected abstract T createItem(); diff --git a/vtm/src/org/oscim/utils/pool/SyncPool.java b/vtm/src/org/oscim/utils/pool/SyncPool.java index fe8cd4f7..4a704d10 100644 --- a/vtm/src/org/oscim/utils/pool/SyncPool.java +++ b/vtm/src/org/oscim/utils/pool/SyncPool.java @@ -18,24 +18,25 @@ package org.oscim.utils.pool; import javax.annotation.CheckReturnValue; -public abstract class SyncPool> { - protected final int maxFill; - protected int fill; +public abstract class SyncPool> { + protected final int mMaxFill; + protected final boolean mClearItems; - protected T pool; - - public SyncPool() { - maxFill = 100; - fill = 0; - } + protected int mFill; + protected T mPool; public SyncPool(int maxItemsInPool) { - maxFill = maxItemsInPool; - fill = 0; + this(maxItemsInPool, true); + } + + public SyncPool(int maxItemsInPool, boolean clearItems) { + mMaxFill = maxItemsInPool; + mFill = 0; + mClearItems = clearItems; } public int getFill() { - return fill; + return mFill; } /** @@ -45,8 +46,8 @@ public abstract class SyncPool> { * number of initial items */ public void init(int items) { - fill = 0; - pool = null; + mFill = 0; + mPool = null; } /** @@ -80,24 +81,25 @@ public abstract class SyncPool> { * Usage item = pool.release(item), to ensure to not keep a reference to * item! */ + @SuppressWarnings({ "rawtypes", "unchecked" }) @CheckReturnValue public T release(T item) { if (item == null) return null; - if (!clearItem(item)) { + if (mClearItems && !clearItem(item)) { // dont add back to pool freeItem(item); return null; } - if (fill < maxFill) { + if (mFill < mMaxFill) { synchronized (this) { - fill++; + mFill++; - item.next = pool; - pool = item; + ((Inlist) item).next = (T) mPool; + mPool = item; } - } else { + } else if (mClearItems) { freeItem(item); } return null; @@ -109,35 +111,38 @@ public abstract class SyncPool> { * Usage list = pool.releaseAll(list), to ensure to not keep a reference to * list! */ + @SuppressWarnings({ "unchecked", "rawtypes" }) @CheckReturnValue public T releaseAll(T item) { if (item == null) return null; - if (fill > maxFill) { + if (mFill > mMaxFill) { while (item != null) { - clearItem(item); - freeItem(item); - item = item.next; + if (mClearItems) { + clearItem(item); + freeItem(item); + } + item = (T) item.next; } return null; } synchronized (this) { while (item != null) { - T next = item.next; + T next = (T) item.next; - if (!clearItem(item)) { + if (mClearItems && !clearItem(item)) { // dont add back to pool freeItem(item); item = next; continue; } - fill++; + mFill++; - item.next = pool; - pool = item; + ((Inlist) item).next = (T) mPool; + mPool = item; item = next; } @@ -151,17 +156,18 @@ public abstract class SyncPool> { * * @return the item */ + @SuppressWarnings("unchecked") public T get() { synchronized (this) { - if (pool == null) { + if (mPool == null) { return createItem(); } - fill--; + mFill--; - T ret = pool; - pool = pool.next; + T ret = mPool; + mPool = (T) mPool.next; ret.next = null; return ret;