Home / Function/ compare() — netty Function Reference

compare() — netty Function Reference

Architecture documentation for the compare() function in ByteBufUtil.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  6be7b2df_f943_8703_84b5_3a297dd217a5["compare()"]
  920454f6_25f6_4a9b_3d32_9684c3e11f6c["ByteBufUtil"]
  6be7b2df_f943_8703_84b5_3a297dd217a5 -->|defined in| 920454f6_25f6_4a9b_3d32_9684c3e11f6c
  c4fcbc6c_e8c2_cce9_72e3_3385d517bd59["compareUintBigEndian()"]
  6be7b2df_f943_8703_84b5_3a297dd217a5 -->|calls| c4fcbc6c_e8c2_cce9_72e3_3385d517bd59
  7ab97d98_a4f3_251b_8fcf_05200d39a0ca["compareUintLittleEndian()"]
  6be7b2df_f943_8703_84b5_3a297dd217a5 -->|calls| 7ab97d98_a4f3_251b_8fcf_05200d39a0ca
  f13bbdbc_c746_d1d7_3f31_437bb0661349["compareUintBigEndianA()"]
  6be7b2df_f943_8703_84b5_3a297dd217a5 -->|calls| f13bbdbc_c746_d1d7_3f31_437bb0661349
  5a8ab0b2_ccfd_2ba2_b189_988c619b7e86["compareUintBigEndianB()"]
  6be7b2df_f943_8703_84b5_3a297dd217a5 -->|calls| 5a8ab0b2_ccfd_2ba2_b189_988c619b7e86
  style 6be7b2df_f943_8703_84b5_3a297dd217a5 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

buffer/src/main/java/io/netty/buffer/ByteBufUtil.java lines 430–470

    public static int compare(ByteBuf bufferA, ByteBuf bufferB) {
        if (bufferA == bufferB) {
            return 0;
        }
        final int aLen = bufferA.readableBytes();
        final int bLen = bufferB.readableBytes();
        final int minLength = Math.min(aLen, bLen);
        final int uintCount = minLength >>> 2;
        final int byteCount = minLength & 3;
        int aIndex = bufferA.readerIndex();
        int bIndex = bufferB.readerIndex();

        if (uintCount > 0) {
            boolean bufferAIsBigEndian = bufferA.order() == ByteOrder.BIG_ENDIAN;
            final long res;
            int uintCountIncrement = uintCount << 2;

            if (bufferA.order() == bufferB.order()) {
                res = bufferAIsBigEndian ? compareUintBigEndian(bufferA, bufferB, aIndex, bIndex, uintCountIncrement) :
                        compareUintLittleEndian(bufferA, bufferB, aIndex, bIndex, uintCountIncrement);
            } else {
                res = bufferAIsBigEndian ? compareUintBigEndianA(bufferA, bufferB, aIndex, bIndex, uintCountIncrement) :
                        compareUintBigEndianB(bufferA, bufferB, aIndex, bIndex, uintCountIncrement);
            }
            if (res != 0) {
                // Ensure we not overflow when cast
                return (int) Math.min(Integer.MAX_VALUE, Math.max(Integer.MIN_VALUE, res));
            }
            aIndex += uintCountIncrement;
            bIndex += uintCountIncrement;
        }

        for (int aEnd = aIndex + byteCount; aIndex < aEnd; ++aIndex, ++bIndex) {
            int comp = bufferA.getUnsignedByte(aIndex) - bufferB.getUnsignedByte(bIndex);
            if (comp != 0) {
                return comp;
            }
        }

        return aLen - bLen;
    }

Domain

Subdomains

Frequently Asked Questions

What does compare() do?
compare() is a function in the netty codebase, defined in buffer/src/main/java/io/netty/buffer/ByteBufUtil.java.
Where is compare() defined?
compare() is defined in buffer/src/main/java/io/netty/buffer/ByteBufUtil.java at line 430.
What does compare() call?
compare() calls 4 function(s): compareUintBigEndian, compareUintBigEndianA, compareUintBigEndianB, compareUintLittleEndian.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free