MCPcopy Create free account
hub / github.com/LadybugDB/ladybug / find

Method find

src/function/find_function.cpp:95–127  ·  view source on GitHub ↗

Returns the position of the first occurrence of needle in the haystack. If haystack doesn't contain needle, it returns -1.

Source from the content-addressed store, hash-verified

93// Returns the position of the first occurrence of needle in the haystack. If haystack doesn't
94// contain needle, it returns -1.
95int64_t Find::find(const uint8_t* haystack, uint32_t haystackLen, const uint8_t* needle,
96 uint32_t needleLen) {
97 auto firstMatchCharPos = (uint8_t*)memchr(haystack, needle[0], haystackLen);
98 if (firstMatchCharPos == nullptr) {
99 return -1;
100 }
101 auto firstMatchCharOffset = firstMatchCharPos - haystack;
102 auto numCharsToMatch = haystackLen - firstMatchCharOffset;
103 switch (needleLen) {
104 case 1:
105 return firstMatchCharOffset;
106 case 2:
107 return alignedNeedleSizeFind<uint16_t>(firstMatchCharPos, numCharsToMatch, needle,
108 firstMatchCharOffset);
109 case 3:
110 return unalignedNeedleSizeFind<uint32_t>(firstMatchCharPos, numCharsToMatch, needle, 3,
111 firstMatchCharOffset);
112 case 4:
113 return alignedNeedleSizeFind<uint32_t>(firstMatchCharPos, numCharsToMatch, needle,
114 firstMatchCharOffset);
115 case 5:
116 case 6:
117 case 7:
118 return unalignedNeedleSizeFind<uint64_t>(firstMatchCharPos, numCharsToMatch, needle,
119 needleLen, firstMatchCharOffset);
120 case 8:
121 return alignedNeedleSizeFind<uint64_t>(firstMatchCharPos, numCharsToMatch, needle,
122 firstMatchCharOffset);
123 default:
124 return genericFind(firstMatchCharPos, numCharsToMatch, needle, needleLen,
125 firstMatchCharOffset);
126 }
127}
128
129} // namespace function
130} // namespace lbug

Callers 15

performSearchFunction · 0.45
completionFunction · 0.45
printErrorMessageMethod · 0.45
initMethod · 0.45
getTokenTypeFunction · 0.45
createTableInfoMethod · 0.45
rewriteTestFileMethod · 0.45
TEST_FFunction · 0.45
TEST_FFunction · 0.45
TEST_FFunction · 0.45

Calls

no outgoing calls

Tested by 14

getTokenTypeFunction · 0.36
rewriteTestFileMethod · 0.36
TEST_FFunction · 0.36
TEST_FFunction · 0.36
TEST_FFunction · 0.36
TEST_FFunction · 0.36
TEST_FFunction · 0.36
TEST_FFunction · 0.36
TESTFunction · 0.36
TEST_FFunction · 0.36
executeScriptMethod · 0.36