MCPcopy Create free account
hub / github.com/apache/arrow / InlinedNullLookup

Function InlinedNullLookup

cpp/src/arrow/util/trie_benchmark.cc:89–189  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

87#ifdef ARROW_WITH_BENCHMARKS_REFERENCE
88
89static inline bool InlinedNullLookup(std::string_view s) {
90 // An inlined version of trie lookup for a specific set of strings
91 // (see AllNulls())
92 auto size = s.length();
93 auto data = s.data();
94 if (size == 0) {
95 return false;
96 }
97 if (size == 1) {
98 return false;
99 }
100
101 auto chars = reinterpret_cast<const char*>(data);
102 auto first = chars[0];
103 auto second = chars[1];
104 switch (first) {
105 case 'N': {
106 // "NA", "N/A", "NaN", "NULL"
107 if (size == 2) {
108 return second == 'A';
109 }
110 auto third = chars[2];
111 if (size == 3) {
112 return (second == '/' && third == 'A') || (second == 'a' && third == 'N');
113 }
114 if (size == 4) {
115 return (second == 'U' && third == 'L' && chars[3] == 'L');
116 }
117 return false;
118 }
119 case 'n': {
120 // "n/a", "nan", "null"
121 if (size == 2) {
122 return false;
123 }
124 auto third = chars[2];
125 if (size == 3) {
126 return (second == '/' && third == 'a') || (second == 'a' && third == 'n');
127 }
128 if (size == 4) {
129 return (second == 'u' && third == 'l' && chars[3] == 'l');
130 }
131 return false;
132 }
133 case '1': {
134 // '1.#IND', '1.#QNAN'
135 if (size == 6) {
136 // '#' is the most unlikely char here, check it first
137 return (chars[2] == '#' && chars[1] == '.' && chars[3] == 'I' &&
138 chars[4] == 'N' && chars[5] == 'D');
139 }
140 if (size == 7) {
141 return (chars[2] == '#' && chars[1] == '.' && chars[3] == 'Q' &&
142 chars[4] == 'N' && chars[5] == 'A' && chars[6] == 'N');
143 }
144 return false;
145 }
146 case '-': {

Callers 1

Calls 2

lengthMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected