Skip to content
Permalink
Browse files

Use `AppendableCharSequence.charAtUnsafe(int)` in `HttpObjectDecoder` (

…#9492)

Motivation:

`HttpObjectDecoder` pre-checks that it doesn't request characters
outside of the `AppendableCharSequence`'s length. `0` is always allowed
because the minimal length of `AppendableCharSequence` is `1`. We can
legally skip index check by using
`AppendableCharSequence.charAtUnsafe(int)` in all existing cases in
`HttpObjectDecoder`.

Modifications:

- Use `AppendableCharSequence.charAtUnsafe(int)` instead of
`AppendableCharSequence.charAt(int)` in `HttpObjectDecoder`.

Result:

No unnecessary index checks in `HttpObjectDecoder`.
  • Loading branch information...
idelpivnitskiy authored and normanmaurer committed Aug 22, 2019
1 parent 3f6762e commit 85fcf4e58164806645b79239d0e6bf00287e26dc
Showing with 4 additions and 4 deletions.
  1. +4 −4 codec-http/src/main/java/io/netty/handler/codec/http/HttpObjectDecoder.java
@@ -575,7 +575,7 @@ private State readHeaders(ByteBuf buffer) {
}
if (line.length() > 0) {
do {
char firstChar = line.charAt(0);
char firstChar = line.charAtUnsafe(0);
if (name != null && (firstChar == ' ' || firstChar == '\t')) {
//please do not make one line from below code
//as it breaks +XX:OptimizeStringConcat optimization
@@ -643,7 +643,7 @@ private LastHttpContent readTrailingHeaders(ByteBuf buffer) {
trailer = this.trailer = new DefaultLastHttpContent(Unpooled.EMPTY_BUFFER, validateHeaders);
}
while (line.length() > 0) {
char firstChar = line.charAt(0);
char firstChar = line.charAtUnsafe(0);
if (lastHeader != null && (firstChar == ' ' || firstChar == '\t')) {
List<String> current = trailer.trailingHeaders().getAll(lastHeader);
if (!current.isEmpty()) {
@@ -727,14 +727,14 @@ private void splitHeader(AppendableCharSequence sb) {

nameStart = findNonWhitespace(sb, 0);
for (nameEnd = nameStart; nameEnd < length; nameEnd ++) {
char ch = sb.charAt(nameEnd);
char ch = sb.charAtUnsafe(nameEnd);
if (ch == ':' || Character.isWhitespace(ch)) {
break;
}
}

for (colonEnd = nameEnd; colonEnd < length; colonEnd ++) {
if (sb.charAt(colonEnd) == ':') {
if (sb.charAtUnsafe(colonEnd) == ':') {
colonEnd ++;
break;
}

0 comments on commit 85fcf4e

Please sign in to comment.
You can’t perform that action at this time.