Skip to content

Commit f898476

Browse files
committed
Micro-optimization to reduce byte[] range checks
1 parent 818cee8 commit f898476

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/main/java/io/vertx/core/http/impl/HttpUtils.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import io.netty.handler.codec.http2.Http2Settings;
2020
import io.netty.util.AsciiString;
2121
import io.netty.util.CharsetUtil;
22+
import io.netty.util.internal.PlatformDependent;
2223
import io.vertx.core.AsyncResult;
2324
import io.vertx.core.Future;
2425
import io.vertx.core.Handler;
@@ -882,7 +883,9 @@ private static void validateAsciiHeaderValue(AsciiString value) {
882883
int off = value.arrayOffset();
883884
int end = off + length;
884885

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

0 commit comments

Comments
 (0)