Java Code Examples for io.netty.util.AsciiString#hashCode()

The following examples show how to use io.netty.util.AsciiString#hashCode() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HpackEncoder.java    From netty-4.1.22 with Apache License 2.0 6 votes vote down vote up
/**
 * Add the header field to the dynamic table. Entries are evicted from the dynamic table until
 * the size of the table and the new header field is less than the table's maxHeaderTableSize. If the size
 * of the new entry is larger than the table's maxHeaderTableSize, the dynamic table will be cleared.
 */
private void add(CharSequence name, CharSequence value, long headerSize) {
    // Clear the table if the header field size is larger than the maxHeaderTableSize.
    if (headerSize > maxHeaderTableSize) {
        clear();
        return;
    }

    // Evict oldest entries until we have enough maxHeaderTableSize.
    while (maxHeaderTableSize - size < headerSize) {
        remove();
    }

    int h = AsciiString.hashCode(name);
    int i = index(h);
    HeaderEntry old = headerFields[i];
    HeaderEntry e = new HeaderEntry(h, name, value, head.before.index - 1, old);
    headerFields[i] = e;
    e.addBefore(head);
    size += headerSize;
}
 
Example 2
Source File: ReadOnlyHttp2Headers.java    From netty-4.1.22 with Apache License 2.0 6 votes vote down vote up
private void calculateNext() {
    for (; i < current.length; i += 2) {
        AsciiString roName = current[i];
        if (roName.hashCode() == nameHash && roName.contentEqualsIgnoreCase(name)) {
            next = current[i + 1];
            i += 2;
            return;
        }
    }
    if (i >= current.length && current == pseudoHeaders) {
        i = 0;
        current = otherHeaders;
        calculateNext();
    } else {
        next = null;
    }
}
 
Example 3
Source File: ReadOnlyHttpHeaders.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
private CharSequence get0(CharSequence name) {
    final int nameHash = AsciiString.hashCode(name);
    for (int i = 0; i < nameValuePairs.length; i += 2) {
        CharSequence roName = nameValuePairs[i];
        if (AsciiString.hashCode(roName) == nameHash && contentEqualsIgnoreCase(roName, name)) {
            return nameValuePairs[i + 1];
        }
    }
    return null;
}
 
Example 4
Source File: ReadOnlyHttpHeaders.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
@Override
public List<String> getAll(String name) {
    if (isEmpty()) {
        return Collections.emptyList();
    }
    final int nameHash = AsciiString.hashCode(name);
    List<String> values = new ArrayList<String>(4);
    for (int i = 0; i < nameValuePairs.length; i += 2) {
        CharSequence roName = nameValuePairs[i];
        if (AsciiString.hashCode(roName) == nameHash && contentEqualsIgnoreCase(roName, name)) {
            values.add(nameValuePairs[i + 1].toString());
        }
    }
    return values;
}
 
Example 5
Source File: ReadOnlyHttpHeaders.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
private int findNextValue() {
    for (int i = nextNameIndex; i < nameValuePairs.length; i += 2) {
        final CharSequence roName = nameValuePairs[i];
        if (nameHash == AsciiString.hashCode(roName) && contentEqualsIgnoreCase(name, roName)) {
            return i;
        }
    }
    return -1;
}
 
Example 6
Source File: ReadOnlyHttpHeaders.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
private int findNextValue() {
    for (int i = nextNameIndex; i < nameValuePairs.length; i += 2) {
        final CharSequence roName = nameValuePairs[i];
        if (nameHash == AsciiString.hashCode(roName) && contentEqualsIgnoreCase(name, roName)) {
            return i;
        }
    }
    return -1;
}
 
Example 7
Source File: HpackEncoder.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the header entry with the lowest index value for the header field. Returns null if
 * header field is not in the dynamic table.
 */
private HeaderEntry getEntry(CharSequence name, CharSequence value) {
    if (length() == 0 || name == null || value == null) {
        return null;
    }
    int h = AsciiString.hashCode(name);
    int i = index(h);
    for (HeaderEntry e = headerFields[i]; e != null; e = e.next) {
        // To avoid short circuit behavior a bitwise operator is used instead of a boolean operator.
        if (e.hash == h && (equalsConstantTime(name, e.name) & equalsConstantTime(value, e.value)) != 0) {
            return e;
        }
    }
    return null;
}
 
Example 8
Source File: HpackEncoder.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the lowest index value for the header field name in the dynamic table. Returns -1 if
 * the header field name is not in the dynamic table.
 */
private int getIndex(CharSequence name) {
    if (length() == 0 || name == null) {
        return -1;
    }
    int h = AsciiString.hashCode(name);
    int i = index(h);
    for (HeaderEntry e = headerFields[i]; e != null; e = e.next) {
        if (e.hash == h && equalsConstantTime(name, e.name) != 0) {
            return getIndex(e.index);
        }
    }
    return -1;
}
 
Example 9
Source File: ReadOnlyHttp2Headers.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
@Override
public boolean contains(CharSequence name, CharSequence value, boolean caseInsensitive) {
    final int nameHash = AsciiString.hashCode(name);
    final HashingStrategy<CharSequence> strategy =
            caseInsensitive ? CASE_INSENSITIVE_HASHER : CASE_SENSITIVE_HASHER;
    final int valueHash = strategy.hashCode(value);

    return contains(name, nameHash, value, valueHash, strategy, otherHeaders)
            || contains(name, nameHash, value, valueHash, strategy, pseudoHeaders);
}
 
Example 10
Source File: ReadOnlyHttp2Headers.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
private static boolean contains(CharSequence name, int nameHash, CharSequence value, int valueHash,
                                HashingStrategy<CharSequence> hashingStrategy, AsciiString[] headers) {
    final int headersEnd = headers.length - 1;
    for (int i = 0; i < headersEnd; i += 2) {
        AsciiString roName = headers[i];
        AsciiString roValue = headers[i + 1];
        if (roName.hashCode() == nameHash && roValue.hashCode() == valueHash &&
            roName.contentEqualsIgnoreCase(name) && hashingStrategy.equals(roValue, value)) {
            return true;
        }
    }
    return false;
}
 
Example 11
Source File: ReadOnlyHttpHeaders.java    From netty-4.1.22 with Apache License 2.0 4 votes vote down vote up
ReadOnlyStringValueIterator(CharSequence name) {
    this.name = name;
    nameHash = AsciiString.hashCode(name);
    nextNameIndex = findNextValue();
}
 
Example 12
Source File: ReadOnlyHttpHeaders.java    From netty-4.1.22 with Apache License 2.0 4 votes vote down vote up
ReadOnlyValueIterator(CharSequence name) {
    this.name = name;
    nameHash = AsciiString.hashCode(name);
    nextNameIndex = findNextValue();
}
 
Example 13
Source File: ReadOnlyHttp2Headers.java    From netty-4.1.22 with Apache License 2.0 4 votes vote down vote up
ReadOnlyValueIterator(CharSequence name) {
    nameHash = AsciiString.hashCode(name);
    this.name = name;
    calculateNext();
}
 
Example 14
Source File: ArmeriaHttpUtil.java    From armeria with Apache License 2.0 4 votes vote down vote up
@Override
public int hashCode(AsciiString o) {
    return o.hashCode();
}
 
Example 15
Source File: HttpHeadersBase.java    From armeria with Apache License 2.0 4 votes vote down vote up
@Override
int hashName(CharSequence name) {
    return AsciiString.hashCode(name);
}