Home / Function/ equalsConstantTime() — netty Function Reference

equalsConstantTime() — netty Function Reference

Architecture documentation for the equalsConstantTime() function in PlatformDependent0.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  cfcfd2bb_1c34_ac00_e6e9_14b4b9901427["equalsConstantTime()"]
  be4c38f2_d236_e498_c295_1033d2617879["PlatformDependent0"]
  cfcfd2bb_1c34_ac00_e6e9_14b4b9901427 -->|defined in| be4c38f2_d236_e498_c295_1033d2617879
  38a30d65_70d7_6436_1c5b_e8e8c0fba12a["getLong()"]
  cfcfd2bb_1c34_ac00_e6e9_14b4b9901427 -->|calls| 38a30d65_70d7_6436_1c5b_e8e8c0fba12a
  e289516f_3edf_77ef_9640_a4fb14c256d3["getInt()"]
  cfcfd2bb_1c34_ac00_e6e9_14b4b9901427 -->|calls| e289516f_3edf_77ef_9640_a4fb14c256d3
  ea70c928_8d30_7e64_dac0_25553c54a73b["getByte()"]
  cfcfd2bb_1c34_ac00_e6e9_14b4b9901427 -->|calls| ea70c928_8d30_7e64_dac0_25553c54a73b
  style cfcfd2bb_1c34_ac00_e6e9_14b4b9901427 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

common/src/main/java/io/netty/util/internal/PlatformDependent0.java lines 971–994

    static int equalsConstantTime(byte[] bytes1, int startPos1, byte[] bytes2, int startPos2, int length) {
        long result = 0;
        long remainingBytes = length & 7;
        final long baseOffset1 = BYTE_ARRAY_BASE_OFFSET + startPos1;
        final long end = baseOffset1 + remainingBytes;
        final long diff = startPos2 - startPos1;
        for (long i = baseOffset1 - 8 + length; i >= end; i -= 8) {
            result |= UNSAFE.getLong(bytes1, i) ^ UNSAFE.getLong(bytes2, i + diff);
        }
        if (remainingBytes >= 4) {
            result |= UNSAFE.getInt(bytes1, baseOffset1) ^ UNSAFE.getInt(bytes2, baseOffset1 + diff);
            remainingBytes -= 4;
        }
        if (remainingBytes >= 2) {
            long pos = end - remainingBytes;
            result |= UNSAFE.getChar(bytes1, pos) ^ UNSAFE.getChar(bytes2, pos + diff);
            remainingBytes -= 2;
        }
        if (remainingBytes == 1) {
            long pos = end - 1;
            result |= UNSAFE.getByte(bytes1, pos) ^ UNSAFE.getByte(bytes2, pos + diff);
        }
        return ConstantTimeUtils.equalsConstantTime(result, 0);
    }

Domain

Subdomains

Frequently Asked Questions

What does equalsConstantTime() do?
equalsConstantTime() is a function in the netty codebase, defined in common/src/main/java/io/netty/util/internal/PlatformDependent0.java.
Where is equalsConstantTime() defined?
equalsConstantTime() is defined in common/src/main/java/io/netty/util/internal/PlatformDependent0.java at line 971.
What does equalsConstantTime() call?
equalsConstantTime() calls 3 function(s): getByte, getInt, getLong.

Analyze Your Own Codebase

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

Try Supermodel Free