From d04c80adb4d570527e0d4bfc7b476e22948ac181 Mon Sep 17 00:00:00 2001 From: NathanSweet Date: Tue, 11 Nov 2014 17:41:48 +0100 Subject: [PATCH] Pool skin keys to avoid allocation. --- .../src/com/esotericsoftware/spine/Skin.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/spine-libgdx/src/com/esotericsoftware/spine/Skin.java b/spine-libgdx/src/com/esotericsoftware/spine/Skin.java index 296575251..3fdc10980 100644 --- a/spine-libgdx/src/com/esotericsoftware/spine/Skin.java +++ b/spine-libgdx/src/com/esotericsoftware/spine/Skin.java @@ -30,11 +30,11 @@ package com.esotericsoftware.spine; -import com.esotericsoftware.spine.attachments.Attachment; - import com.badlogic.gdx.utils.Array; import com.badlogic.gdx.utils.ObjectMap; import com.badlogic.gdx.utils.ObjectMap.Entry; +import com.badlogic.gdx.utils.Pool; +import com.esotericsoftware.spine.attachments.Attachment; /** Stores attachments by slot index and attachment name. */ public class Skin { @@ -42,6 +42,11 @@ public class Skin { final String name; final ObjectMap attachments = new ObjectMap(); + final Pool keyPool = new Pool(64) { + protected Object newObject () { + return new Key(); + } + }; public Skin (String name) { if (name == null) throw new IllegalArgumentException("name cannot be null."); @@ -51,7 +56,7 @@ public class Skin { public void addAttachment (int slotIndex, String name, Attachment attachment) { if (attachment == null) throw new IllegalArgumentException("attachment cannot be null."); if (slotIndex < 0) throw new IllegalArgumentException("slotIndex must be >= 0."); - Key key = new Key(); + Key key = keyPool.obtain(); key.set(slotIndex, name); attachments.put(key, attachment); } @@ -78,6 +83,8 @@ public class Skin { } public void clear () { + for (Key key : attachments.keys()) + keyPool.free(key); attachments.clear(); }