bpo-46848: Use stringlib/fastsearch in mmap (GH-31625)

Speed up mmap.find(). Add _PyBytes_Find() and _PyBytes_ReverseFind().
This commit is contained in:
Dennis Sweeney 2022-03-01 23:46:30 -05:00 committed by GitHub
parent 9833bb91e4
commit 6ddb09f35b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 53 additions and 19 deletions

View file

@ -116,3 +116,22 @@ PyAPI_FUNC(void*) _PyBytesWriter_WriteBytes(_PyBytesWriter *writer,
void *str,
const void *bytes,
Py_ssize_t size);
/* Substring Search.
Returns the index of the first occurence of
a substring ("needle") in a larger text ("haystack").
If the needle is not found, return -1.
If the needle is found, add offset to the index.
*/
PyAPI_FUNC(Py_ssize_t)
_PyBytes_Find(const char *haystack, Py_ssize_t len_haystack,
const char *needle, Py_ssize_t len_needle,
Py_ssize_t offset);
/* Same as above, but search right-to-left */
PyAPI_FUNC(Py_ssize_t)
_PyBytes_ReverseFind(const char *haystack, Py_ssize_t len_haystack,
const char *needle, Py_ssize_t len_needle,
Py_ssize_t offset);