Extracted int-to-string conversion to ConversionUtil
This commit is contained in:
parent
bfc3b3999d
commit
0596aaac48
@ -24,6 +24,7 @@ import java.util.Map;
|
|||||||
|
|
||||||
import org.jboss.netty.logging.InternalLogger;
|
import org.jboss.netty.logging.InternalLogger;
|
||||||
import org.jboss.netty.logging.InternalLoggerFactory;
|
import org.jboss.netty.logging.InternalLoggerFactory;
|
||||||
|
import org.jboss.netty.util.internal.ConversionUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A {@link ChannelPipeline} that might perform better at the cost of
|
* 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
|
// FIXME Code duplication with DefaultChannelPipeline
|
||||||
static final InternalLogger logger = InternalLoggerFactory.getInstance(StaticChannelPipeline.class);
|
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 Channel channel;
|
||||||
private volatile ChannelSink sink;
|
private volatile ChannelSink sink;
|
||||||
private final StaticChannelHandlerContext[] contexts;
|
private final StaticChannelHandlerContext[] contexts;
|
||||||
@ -78,13 +73,7 @@ public class StaticChannelPipeline implements ChannelPipeline {
|
|||||||
throw new NullPointerException("handlers[" + i + ']');
|
throw new NullPointerException("handlers[" + i + ']');
|
||||||
}
|
}
|
||||||
|
|
||||||
String name;
|
String name = ConversionUtil.toString(i);
|
||||||
if (i < NAMES.length) {
|
|
||||||
name = NAMES[i];
|
|
||||||
} else {
|
|
||||||
name = Integer.toString(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
StaticChannelHandlerContext ctx =
|
StaticChannelHandlerContext ctx =
|
||||||
new StaticChannelHandlerContext(i, name, h);
|
new StaticChannelHandlerContext(i, name, h);
|
||||||
contexts[i] = ctx;
|
contexts[i] = ctx;
|
||||||
|
@ -70,10 +70,6 @@ public class ConversionUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private ConversionUtil() {
|
|
||||||
// Unused
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts the specified object into an array of strings.
|
* 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]");
|
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user