Skip to content

Commit

Permalink
simplify OptionUtil#prefixEndOf (#5833)
Browse files Browse the repository at this point in the history
* simplify OptionUtil#prefixEndOf

* remove Unused import
  • Loading branch information
GungnirLaevatain committed Apr 12, 2021
1 parent 0f5040b commit 8c291f8
Showing 1 changed file with 3 additions and 8 deletions.
Expand Up @@ -20,21 +20,16 @@
import io.grpc.Status;
import io.netty.handler.codec.http2.Http2Exception;

import java.util.Arrays;

public class OptionUtil {

public static final byte[] NO_PREFIX_END = {0};

public static final ByteSequence prefixEndOf(ByteSequence prefix) {
byte[] endKey = prefix.getBytes().clone();
for (int i = endKey.length - 1; i >= 0; i--) {
if (endKey[i] < 0xff) {
endKey[i] = (byte) (endKey[i] + 1);
return ByteSequence.from(Arrays.copyOf(endKey, i + 1));
}
if (prefix.size() > 0) {
endKey[endKey.length - 1] = (byte) (endKey[endKey.length - 1] + 1);
return ByteSequence.from(endKey);
}

return ByteSequence.from(NO_PREFIX_END);
}

Expand Down

0 comments on commit 8c291f8

Please sign in to comment.