Removed custom split method as it is not effective anymore.

This commit is contained in:
Dmitriy Dumanskiy 2016-08-01 12:17:05 +03:00 committed by Norman Maurer
parent 6bd810210d
commit a80ea46b8e
14 changed files with 44 additions and 132 deletions

View File

@ -87,7 +87,7 @@ public class DefaultDnsRecordEncoder implements DnsRecordEncoder {
return;
}
final String[] labels = StringUtil.split(name, '.');
final String[] labels = name.split("\\.");
for (String label : labels) {
final int labelLen = label.length();
if (labelLen == 0) {

View File

@ -20,7 +20,6 @@ import io.netty.handler.codec.haproxy.HAProxyProxiedProtocol.AddressFamily;
import io.netty.util.ByteProcessor;
import io.netty.util.CharsetUtil;
import io.netty.util.NetUtil;
import io.netty.util.internal.StringUtil;
/**
* Message container for decoded HAProxy proxy protocol parameters
@ -227,7 +226,7 @@ public final class HAProxyMessage {
throw new HAProxyProtocolException("header");
}
String[] parts = StringUtil.split(header, ' ');
String[] parts = header.split(" ");
int numParts = parts.length;
if (numParts < 2) {

View File

@ -19,7 +19,6 @@ import static io.netty.handler.codec.http.CookieUtil.firstInvalidCookieNameOctet
import static io.netty.handler.codec.http.CookieUtil.firstInvalidCookieValueOctet;
import static io.netty.handler.codec.http.CookieUtil.unwrapValue;
import io.netty.handler.codec.http.cookie.CookieHeaderNames;
import io.netty.util.internal.StringUtil;
import io.netty.util.internal.logging.InternalLogger;
import io.netty.util.internal.logging.InternalLoggerFactory;
@ -65,8 +64,6 @@ public final class CookieDecoder {
private static final String VERSION = "Version";
private static final char COMMA = ',';
private final boolean strict;
public static Set<Cookie> decode(String header) {
@ -169,7 +166,7 @@ public final class CookieDecoder {
} else if (VERSION.equalsIgnoreCase(name)) {
version = Integer.parseInt(value);
} else if (PORT.equalsIgnoreCase(name)) {
String[] portList = StringUtil.split(value, COMMA);
String[] portList = value.split(",");
for (String s1: portList) {
try {
ports.add(Integer.valueOf(s1));

View File

@ -19,7 +19,6 @@ import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.embedded.EmbeddedChannel;
import io.netty.handler.codec.compression.ZlibCodecFactory;
import io.netty.handler.codec.compression.ZlibWrapper;
import io.netty.util.internal.StringUtil;
/**
* Compresses an {@link HttpMessage} and an {@link HttpContent} in {@code gzip} or
@ -136,7 +135,7 @@ public class HttpContentCompressor extends HttpContentEncoder {
float starQ = -1.0f;
float gzipQ = -1.0f;
float deflateQ = -1.0f;
for (String encoding: StringUtil.split(acceptEncoding, ',')) {
for (String encoding : acceptEncoding.split(",")) {
float q = 1.0f;
int equalsPos = encoding.indexOf('=');
if (equalsPos != -1) {

View File

@ -19,7 +19,6 @@ import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufUtil;
import io.netty.handler.codec.Headers;
import io.netty.util.AsciiString;
import io.netty.util.internal.StringUtil;
import java.text.ParseException;
import java.util.Calendar;
@ -1591,7 +1590,7 @@ public abstract class HttpHeaders implements Iterable<Map.Entry<String, String>>
}
private static boolean contains(String value, CharSequence expected, boolean ignoreCase) {
String[] parts = StringUtil.split(value, ',');
String[] parts = value.split(",");
if (ignoreCase) {
for (String s: parts) {
if (AsciiString.contentEqualsIgnoreCase(expected, s.trim())) {

View File

@ -704,7 +704,7 @@ public class HttpPostMultipartRequestDecoder implements InterfaceHttpPostRequest
if (checkSecondArg) {
// read next values and store them in the map as Attribute
for (int i = 2; i < contents.length; i++) {
String[] values = StringUtil.split(contents[i], '=', 2);
String[] values = contents[i].split("=", 2);
Attribute attribute;
try {
String name = cleanString(values[0]);
@ -1825,7 +1825,7 @@ public class HttpPostMultipartRequestDecoder implements InterfaceHttpPostRequest
if (svalue.indexOf(';') >= 0) {
values = splitMultipartHeaderValues(svalue);
} else {
values = StringUtil.split(svalue, ',');
values = svalue.split(",");
}
for (String value : values) {
headers.add(value.trim());

View File

@ -34,7 +34,6 @@ import io.netty.handler.codec.http.HttpResponse;
import io.netty.handler.codec.http.HttpResponseDecoder;
import io.netty.handler.codec.http.HttpScheme;
import io.netty.util.ReferenceCountUtil;
import io.netty.util.internal.StringUtil;
import io.netty.util.internal.ThrowableUtil;
import java.net.URI;
@ -224,7 +223,7 @@ public abstract class WebSocketClientHandshaker {
setActualSubprotocol(expectedSubprotocol); // null or "" - we echo what the user requested
} else if (!expectedProtocol.isEmpty() && receivedProtocol != null && !receivedProtocol.isEmpty()) {
// We require a subprotocol and received one -> verify it
for (String protocol : StringUtil.split(expectedSubprotocol, ',')) {
for (String protocol : expectedProtocol.split(",")) {
if (protocol.trim().equals(receivedProtocol)) {
protocolValid = true;
setActualSubprotocol(receivedProtocol);

View File

@ -33,7 +33,6 @@ import io.netty.handler.codec.http.HttpResponseEncoder;
import io.netty.handler.codec.http.HttpServerCodec;
import io.netty.util.ReferenceCountUtil;
import io.netty.util.internal.EmptyArrays;
import io.netty.util.internal.StringUtil;
import io.netty.util.internal.ThrowableUtil;
import io.netty.util.internal.logging.InternalLogger;
import io.netty.util.internal.logging.InternalLoggerFactory;
@ -85,7 +84,7 @@ public abstract class WebSocketServerHandshaker {
this.version = version;
this.uri = uri;
if (subprotocols != null) {
String[] subprotocolArray = StringUtil.split(subprotocols, ',');
String[] subprotocolArray = subprotocols.split(",");
for (int i = 0; i < subprotocolArray.length; i++) {
subprotocolArray[i] = subprotocolArray[i].trim();
}
@ -344,7 +343,7 @@ public abstract class WebSocketServerHandshaker {
return null;
}
String[] requestedSubprotocolArray = StringUtil.split(requestedSubprotocols, ',');
String[] requestedSubprotocolArray = requestedSubprotocols.split(",");
for (String p: requestedSubprotocolArray) {
String requestedSubprotocol = p.trim();

View File

@ -18,7 +18,6 @@ package io.netty.handler.codec.http.websocketx.extensions;
import io.netty.handler.codec.http.HttpHeaderNames;
import io.netty.handler.codec.http.HttpHeaderValues;
import io.netty.handler.codec.http.HttpHeaders;
import io.netty.util.internal.StringUtil;
import java.util.ArrayList;
import java.util.Collections;
@ -31,8 +30,8 @@ import java.util.regex.Pattern;
public final class WebSocketExtensionUtil {
private static final char EXTENSION_SEPARATOR = ',';
private static final char PARAMETER_SEPARATOR = ';';
private static final String EXTENSION_SEPARATOR = ",";
private static final String PARAMETER_SEPARATOR = ";";
private static final char PARAMETER_EQUAL = '=';
private static final Pattern PARAMETER = Pattern.compile("^([^=]+)(=[\\\"]?([^\\\"]+)[\\\"]?)?$");
@ -43,11 +42,11 @@ public final class WebSocketExtensionUtil {
}
public static List<WebSocketExtensionData> extractExtensions(String extensionHeader) {
String[] rawExtensions = StringUtil.split(extensionHeader, EXTENSION_SEPARATOR);
String[] rawExtensions = extensionHeader.split(EXTENSION_SEPARATOR);
if (rawExtensions.length > 0) {
List<WebSocketExtensionData> extensions = new ArrayList<WebSocketExtensionData>(rawExtensions.length);
for (String rawExtension : rawExtensions) {
String[] extensionParameters = StringUtil.split(rawExtension, PARAMETER_SEPARATOR);
String[] extensionParameters = rawExtension.split(PARAMETER_SEPARATOR);
String name = extensionParameters[0].trim();
Map<String, String> parameters;
if (extensionParameters.length > 1) {
@ -60,7 +59,7 @@ public final class WebSocketExtensionUtil {
}
}
} else {
parameters = Collections.<String, String>emptyMap();
parameters = Collections.emptyMap();
}
extensions.add(new WebSocketExtensionData(name, parameters));
}
@ -74,19 +73,14 @@ public final class WebSocketExtensionUtil {
Map<String, String> extensionParameters) {
StringBuilder newHeaderValue = new StringBuilder(
currentHeaderValue != null ? currentHeaderValue.length() : 0 + extensionName.length() + 1);
currentHeaderValue != null ? currentHeaderValue.length() : extensionName.length() + 1);
if (currentHeaderValue != null && !currentHeaderValue.trim().isEmpty()) {
newHeaderValue.append(currentHeaderValue);
newHeaderValue.append(EXTENSION_SEPARATOR);
}
newHeaderValue.append(extensionName);
boolean isFirst = true;
for (Entry<String, String> extensionParameter : extensionParameters.entrySet()) {
if (isFirst) {
newHeaderValue.append(PARAMETER_SEPARATOR);
} else {
isFirst = false;
}
newHeaderValue.append(extensionParameter.getKey());
if (extensionParameter.getValue() != null) {
newHeaderValue.append(PARAMETER_EQUAL);

View File

@ -24,7 +24,6 @@ import io.netty.handler.codec.ReplayingDecoder;
import io.netty.handler.codec.TooLongFrameException;
import io.netty.handler.codec.stomp.StompSubframeDecoder.State;
import io.netty.util.internal.AppendableCharSequence;
import io.netty.util.internal.StringUtil;
import java.util.List;
import java.util.Locale;
@ -212,7 +211,7 @@ public class StompSubframeDecoder extends ReplayingDecoder<State> {
for (;;) {
String line = readLine(buffer, maxLineLength);
if (!line.isEmpty()) {
String[] split = StringUtil.split(line, ':');
String[] split = line.split(":");
if (split.length == 2) {
headers.add(split[0], split[1]);
}

View File

@ -68,91 +68,6 @@ public final class StringUtil {
// Unused.
}
/**
* Splits the specified {@link String} with the specified delimiter. This operation is a simplified and optimized
* version of {@link String#split(String)}.
*/
public static String[] split(String value, char delim) {
final int end = value.length();
final List<String> res = InternalThreadLocalMap.get().arrayList();
int start = 0;
for (int i = 0; i < end; i ++) {
if (value.charAt(i) == delim) {
if (start == i) {
res.add(EMPTY_STRING);
} else {
res.add(value.substring(start, i));
}
start = i + 1;
}
}
if (start == 0) { // If no delimiter was found in the value
res.add(value);
} else {
if (start != end) {
// Add the last element if it's not empty.
res.add(value.substring(start, end));
} else {
// Truncate trailing empty elements.
for (int i = res.size() - 1; i >= 0; i --) {
if (res.get(i).isEmpty()) {
res.remove(i);
} else {
break;
}
}
}
}
return res.toArray(new String[res.size()]);
}
/**
* Splits the specified {@link String} with the specified delimiter in maxParts maximum parts.
* This operation is a simplified and optimized
* version of {@link String#split(String, int)}.
*/
public static String[] split(String value, char delim, int maxParts) {
final int end = value.length();
final List<String> res = InternalThreadLocalMap.get().arrayList();
int start = 0;
int cpt = 1;
for (int i = 0; i < end && cpt < maxParts; i ++) {
if (value.charAt(i) == delim) {
if (start == i) {
res.add(EMPTY_STRING);
} else {
res.add(value.substring(start, i));
}
start = i + 1;
cpt++;
}
}
if (start == 0) { // If no delimiter was found in the value
res.add(value);
} else {
if (start != end) {
// Add the last element if it's not empty.
res.add(value.substring(start, end));
} else {
// Truncate trailing empty elements.
for (int i = res.size() - 1; i >= 0; i --) {
if (res.get(i).isEmpty()) {
res.remove(i);
} else {
break;
}
}
}
}
return res.toArray(new String[res.size()]);
}
/**
* Get the item after one char delim if the delim is found (else null).
* This operation is a simplified and optimized

View File

@ -15,9 +15,10 @@
*/
package io.netty.util.internal;
import java.util.Arrays;
import org.junit.Test;
import java.util.Arrays;
import static io.netty.util.internal.StringUtil.*;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
@ -49,33 +50,48 @@ public class StringUtilTest {
@Test
public void splitSimple() {
assertArrayEquals(new String[] { "foo", "bar" }, split("foo:bar", ':'));
assertArrayEquals(new String[] { "foo", "bar" }, "foo:bar".split(":"));
}
@Test
public void splitWithTrailingDelimiter() {
assertArrayEquals(new String[] { "foo", "bar" }, split("foo,bar,", ','));
assertArrayEquals(new String[] { "foo", "bar" }, "foo,bar,".split(","));
}
@Test
public void splitWithTrailingDelimiters() {
assertArrayEquals(new String[] { "foo", "bar" }, split("foo!bar!!", '!'));
assertArrayEquals(new String[] { "foo", "bar" }, "foo!bar!!".split("!"));
}
@Test
public void splitWithTrailingDelimitersDot() {
assertArrayEquals(new String[] { "foo", "bar" }, "foo.bar..".split("\\."));
}
@Test
public void splitWithTrailingDelimitersEq() {
assertArrayEquals(new String[] { "foo", "bar" }, "foo=bar==".split("="));
}
@Test
public void splitWithTrailingDelimitersSpace() {
assertArrayEquals(new String[] { "foo", "bar" }, "foo bar ".split(" "));
}
@Test
public void splitWithConsecutiveDelimiters() {
assertArrayEquals(new String[] { "foo", "", "bar" }, split("foo$$bar", '$'));
assertArrayEquals(new String[] { "foo", "", "bar" }, "foo$$bar".split("\\$"));
}
@Test
public void splitWithDelimiterAtBeginning() {
assertArrayEquals(new String[] { "", "foo", "bar" }, split("#foo#bar", '#'));
assertArrayEquals(new String[] { "", "foo", "bar" }, "#foo#bar".split("#"));
}
@Test
public void splitMaxPart() {
assertArrayEquals(new String[] { "foo", "bar:bar2" }, split("foo:bar:bar2", ':', 2));
assertArrayEquals(new String[] { "foo", "bar", "bar2" }, split("foo:bar:bar2", ':', 3));
assertArrayEquals(new String[] { "foo", "bar:bar2" }, "foo:bar:bar2".split(":", 2));
assertArrayEquals(new String[] { "foo", "bar", "bar2" }, "foo:bar:bar2".split(":", 3));
}
@Test

View File

@ -29,13 +29,10 @@ import io.netty.handler.codec.http.FullHttpResponse;
import io.netty.handler.codec.http.HttpHeaderNames;
import io.netty.handler.codec.http.HttpMethod;
import io.netty.handler.codec.http.HttpObjectAggregator;
import io.netty.handler.codec.http.HttpRequestDecoder;
import io.netty.handler.codec.http.HttpResponseEncoder;
import io.netty.handler.codec.http.HttpResponseStatus;
import io.netty.handler.codec.http.HttpServerCodec;
import io.netty.handler.codec.http.HttpVersion;
import io.netty.util.CharsetUtil;
import io.netty.util.internal.StringUtil;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
@ -89,7 +86,7 @@ final class HttpProxyServer extends ProxyServer {
if (username != null) {
CharSequence authz = req.headers().get(HttpHeaderNames.PROXY_AUTHORIZATION);
if (authz != null) {
String[] authzParts = StringUtil.split(authz.toString(), ' ', 2);
String[] authzParts = authz.toString().split(" ", 2);
ByteBuf authzBuf64 = Unpooled.copiedBuffer(authzParts[1], CharsetUtil.US_ASCII);
ByteBuf authzBuf = Base64.decode(authzBuf64);

View File

@ -27,7 +27,6 @@ import io.netty.testsuite.util.TestUtils;
import io.netty.util.NetUtil;
import io.netty.util.ReferenceCountUtil;
import io.netty.util.ResourceLeakDetector;
import io.netty.util.internal.StringUtil;
import org.junit.Assert;
import org.junit.Assume;
import org.junit.Ignore;
@ -53,7 +52,7 @@ public class EpollReuseAddrTest {
if (index > -1) {
kernelVersion = kernelVersion.substring(0, index);
}
String[] versionParts = StringUtil.split(kernelVersion, '.');
String[] versionParts = kernelVersion.split("\\.");
if (versionParts.length <= 3) {
MAJOR = Integer.parseInt(versionParts[0]);
MINOR = Integer.parseInt(versionParts[1]);