diff --git a/src/main/java/org/jboss/netty/channel/StaticChannelPipeline.java b/src/main/java/org/jboss/netty/channel/StaticChannelPipeline.java index b80a4ed393..0cd709161e 100644 --- a/src/main/java/org/jboss/netty/channel/StaticChannelPipeline.java +++ b/src/main/java/org/jboss/netty/channel/StaticChannelPipeline.java @@ -24,6 +24,7 @@ import java.util.Map; import org.jboss.netty.logging.InternalLogger; import org.jboss.netty.logging.InternalLoggerFactory; +import org.jboss.netty.util.internal.ConversionUtil; /** * A {@link ChannelPipeline} that might perform better at the cost of @@ -42,12 +43,6 @@ public class StaticChannelPipeline implements ChannelPipeline { // FIXME Code duplication with DefaultChannelPipeline static final InternalLogger logger = InternalLoggerFactory.getInstance(StaticChannelPipeline.class); - // The names of the first 16 handlers to avoid int->string conversion cost - private static final String[] NAMES = { - "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", - "10","11","12","13","14","15", - }; - private volatile Channel channel; private volatile ChannelSink sink; private final StaticChannelHandlerContext[] contexts; @@ -78,13 +73,7 @@ public class StaticChannelPipeline implements ChannelPipeline { throw new NullPointerException("handlers[" + i + ']'); } - String name; - if (i < NAMES.length) { - name = NAMES[i]; - } else { - name = Integer.toString(i); - } - + String name = ConversionUtil.toString(i); StaticChannelHandlerContext ctx = new StaticChannelHandlerContext(i, name, h); contexts[i] = ctx; diff --git a/src/main/java/org/jboss/netty/util/internal/ConversionUtil.java b/src/main/java/org/jboss/netty/util/internal/ConversionUtil.java index fba5c401f7..57a673736c 100644 --- a/src/main/java/org/jboss/netty/util/internal/ConversionUtil.java +++ b/src/main/java/org/jboss/netty/util/internal/ConversionUtil.java @@ -70,10 +70,6 @@ public class ConversionUtil { } } - private ConversionUtil() { - // Unused - } - /** * Converts the specified object into an array of strings. */ @@ -96,4 +92,21 @@ public class ConversionUtil { return String.valueOf(value).split("[, \\t\\n\\r\\f\\e\\a]"); } + + private static final String[] INTEGERS = { + "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", + "10","11","12","13","14","15", + }; + + public static String toString(int value) { + if (value >= 0 && value < INTEGERS.length) { + return INTEGERS[value]; + } else { + return Integer.toString(value); + } + } + + private ConversionUtil() { + // Unused + } }