Skip to content

Commit 85fcf4e

Browse files
idelpivnitskiynormanmaurer
authored andcommitted
Use AppendableCharSequence.charAtUnsafe(int) in HttpObjectDecoder (netty#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`.
1 parent 3f6762e commit 85fcf4e

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

codec-http/src/main/java/io/netty/handler/codec/http/HttpObjectDecoder.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ private State readHeaders(ByteBuf buffer) {
575575
}
576576
if (line.length() > 0) {
577577
do {
578-
char firstChar = line.charAt(0);
578+
char firstChar = line.charAtUnsafe(0);
579579
if (name != null && (firstChar == ' ' || firstChar == '\t')) {
580580
//please do not make one line from below code
581581
//as it breaks +XX:OptimizeStringConcat optimization
@@ -643,7 +643,7 @@ private LastHttpContent readTrailingHeaders(ByteBuf buffer) {
643643
trailer = this.trailer = new DefaultLastHttpContent(Unpooled.EMPTY_BUFFER, validateHeaders);
644644
}
645645
while (line.length() > 0) {
646-
char firstChar = line.charAt(0);
646+
char firstChar = line.charAtUnsafe(0);
647647
if (lastHeader != null && (firstChar == ' ' || firstChar == '\t')) {
648648
List<String> current = trailer.trailingHeaders().getAll(lastHeader);
649649
if (!current.isEmpty()) {
@@ -727,14 +727,14 @@ private void splitHeader(AppendableCharSequence sb) {
727727

728728
nameStart = findNonWhitespace(sb, 0);
729729
for (nameEnd = nameStart; nameEnd < length; nameEnd ++) {
730-
char ch = sb.charAt(nameEnd);
730+
char ch = sb.charAtUnsafe(nameEnd);
731731
if (ch == ':' || Character.isWhitespace(ch)) {
732732
break;
733733
}
734734
}
735735

736736
for (colonEnd = nameEnd; colonEnd < length; colonEnd ++) {
737-
if (sb.charAt(colonEnd) == ':') {
737+
if (sb.charAtUnsafe(colonEnd) == ':') {
738738
colonEnd ++;
739739
break;
740740
}

0 commit comments

Comments
 (0)