Skip to content

Commit

Permalink
Micro-optimization to reduce byte[] range checks
Browse files Browse the repository at this point in the history
  • Loading branch information
franz1981 committed Nov 18, 2024
1 parent 818cee8 commit f898476
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/main/java/io/vertx/core/http/impl/HttpUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import io.netty.handler.codec.http2.Http2Settings;
import io.netty.util.AsciiString;
import io.netty.util.CharsetUtil;
import io.netty.util.internal.PlatformDependent;
import io.vertx.core.AsyncResult;
import io.vertx.core.Future;
import io.vertx.core.Handler;
Expand Down Expand Up @@ -882,7 +883,9 @@ private static void validateAsciiHeaderValue(AsciiString value) {
int off = value.arrayOffset();
int end = off + length;

for (int index = off; index < end; index++) {
// DON'T REMOVE 'off == 0? 0 : off' as it's a micro-optimization to reduce the range checks
// since AsciiString(s) often (if not always) have offset == 0
for (int index = off == 0? 0 : off; index < end; index++) {
int latinChar = asciiChars[index] & 0xFF;
if (latinChar == 0x7F) {
throw new IllegalArgumentException("a header value contains a prohibited character '127': " + value);
Expand Down

0 comments on commit f898476

Please sign in to comment.