SWARUtil Class — netty Architecture
Architecture documentation for the SWARUtil class in SWARUtil.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD 42ee86cb_49f5_6d26_1f37_9aa45922bfe1["SWARUtil"] d110ad2e_ee0c_7996_632b_b10c1a0014ad["SWARUtil.java"] 42ee86cb_49f5_6d26_1f37_9aa45922bfe1 -->|defined in| d110ad2e_ee0c_7996_632b_b10c1a0014ad e8aec5db_04e8_7fd3_6bf7_46d738f7a158["compilePattern()"] 42ee86cb_49f5_6d26_1f37_9aa45922bfe1 -->|method| e8aec5db_04e8_7fd3_6bf7_46d738f7a158 e2efd92d_0c44_a8cb_5657_31b6cff4687f["applyPattern()"] 42ee86cb_49f5_6d26_1f37_9aa45922bfe1 -->|method| e2efd92d_0c44_a8cb_5657_31b6cff4687f 10a656df_ac6f_e714_5197_180098c1eaaa["getIndex()"] 42ee86cb_49f5_6d26_1f37_9aa45922bfe1 -->|method| 10a656df_ac6f_e714_5197_180098c1eaaa 4abd060d_3f20_7d88_268d_11e360f76723["applyUpperCasePattern()"] 42ee86cb_49f5_6d26_1f37_9aa45922bfe1 -->|method| 4abd060d_3f20_7d88_268d_11e360f76723 80ebba66_2d31_1fc8_2306_dd0d02c32430["applyLowerCasePattern()"] 42ee86cb_49f5_6d26_1f37_9aa45922bfe1 -->|method| 80ebba66_2d31_1fc8_2306_dd0d02c32430 f3d78f65_6cd7_0186_e670_bf08a9b7f61f["containsUpperCase()"] 42ee86cb_49f5_6d26_1f37_9aa45922bfe1 -->|method| f3d78f65_6cd7_0186_e670_bf08a9b7f61f ce78a69e_da7e_bf8a_ec73_565223ffb5ca["containsLowerCase()"] 42ee86cb_49f5_6d26_1f37_9aa45922bfe1 -->|method| ce78a69e_da7e_bf8a_ec73_565223ffb5ca cf12be09_4534_7ea0_a078_45d29026d5f5["toLowerCase()"] 42ee86cb_49f5_6d26_1f37_9aa45922bfe1 -->|method| cf12be09_4534_7ea0_a078_45d29026d5f5 be340ceb_e073_bee6_b99c_3503ae799dd2["toUpperCase()"] 42ee86cb_49f5_6d26_1f37_9aa45922bfe1 -->|method| be340ceb_e073_bee6_b99c_3503ae799dd2 efb9b4d3_104f_f802_9d7f_84e3e5c69870["SWARUtil()"] 42ee86cb_49f5_6d26_1f37_9aa45922bfe1 -->|method| efb9b4d3_104f_f802_9d7f_84e3e5c69870
Relationship Graph
Source Code
common/src/main/java/io/netty/util/internal/SWARUtil.java lines 21–176
public final class SWARUtil {
/**
* Compiles given byte into a long pattern suitable for SWAR operations.
*/
public static long compilePattern(byte byteToFind) {
return (byteToFind & 0xFFL) * 0x101010101010101L;
}
/**
* Applies a compiled pattern to given word.
* Returns a word where each byte that matches the pattern has the highest bit set.
*
* @param word the word to apply the pattern to
* @param pattern the pattern to apply
* @return a word where each byte that matches the pattern has the highest bit set
*/
public static long applyPattern(final long word, final long pattern) {
long input = word ^ pattern;
long tmp = (input & 0x7F7F7F7F7F7F7F7FL) + 0x7F7F7F7F7F7F7F7FL;
return ~(tmp | input | 0x7F7F7F7F7F7F7F7FL);
}
/**
* Returns the index of the first occurrence of byte that specificied in the pattern.
* If no pattern is found, returns 8.
*
* @param word the return value of {@link #applyPattern(long, long)}
* @param isBigEndian if true, if given word is big endian
* if false, if given word is little endian
* @return the index of the first occurrence of the specified pattern in the specified word.
* If no pattern is found, returns 8.
*/
public static int getIndex(final long word, final boolean isBigEndian) {
final int zeros = isBigEndian? Long.numberOfLeadingZeros(word) : Long.numberOfTrailingZeros(word);
return zeros >>> 3;
}
/**
* Returns a word where each ASCII uppercase byte has the highest bit set.
*/
private static long applyUpperCasePattern(final long word) {
// Inspired by https://github.com/facebook/folly/blob/add4049dd6c2371eac05b92b6fd120fd6dd74df5/folly/String.cpp
long rotated = word & 0x7F7F7F7F7F7F7F7FL;
rotated += 0x2525252525252525L;
rotated &= 0x7F7F7F7F7F7F7F7FL;
rotated += 0x1A1A1A1A1A1A1A1AL;
rotated &= ~word;
rotated &= 0x8080808080808080L;
return rotated;
}
/**
* Returns a word where each ASCII uppercase byte has the highest bit set.
*/
private static int applyUpperCasePattern(final int word) {
int rotated = word & 0x7F7F7F7F;
rotated += 0x25252525;
rotated &= 0x7F7F7F7F;
rotated += 0x1A1A1A1A;
rotated &= ~word;
rotated &= 0x80808080;
return rotated;
}
/**
* Returns a word where each ASCII lowercase byte has the highest bit set.
*/
private static long applyLowerCasePattern(final long word) {
long rotated = word & 0x7F7F7F7F7F7F7F7FL;
rotated += 0x0505050505050505L;
rotated &= 0x7F7F7F7F7F7F7F7FL;
rotated += 0x1A1A1A1A1A1A1A1AL;
rotated &= ~word;
rotated &= 0x8080808080808080L;
return rotated;
}
/**
* Returns a word where each lowercase ASCII byte has the highest bit set.
*/
Source
Frequently Asked Questions
What is the SWARUtil class?
SWARUtil is a class in the netty codebase, defined in common/src/main/java/io/netty/util/internal/SWARUtil.java.
Where is SWARUtil defined?
SWARUtil is defined in common/src/main/java/io/netty/util/internal/SWARUtil.java at line 21.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free