static int indexOf()

in src/main/java/software/aws/mcs/auth/SigV4AuthProvider.java [355:375]


    static int indexOf(byte[] target, byte[] pattern) {
        final int lastCheckIndex = target.length - pattern.length;

        for (int i = 0; i <= lastCheckIndex; i++) {
            if (pattern[0] == target[i]) {
                int inner = 0;
                int outer = i;
                // A tight loop over target, comparing indices
                for (; inner < pattern.length && pattern[inner] == target[outer];
                     inner++, outer++) {}

                // If the inner loop reached the end of the pattern, then we have found the index
                if (inner == pattern.length) {
                    return i;
                }
            }
        }

        // Loop exhaustion means we did not find it
        return -1;
    }