Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use FreeBSD memmem function on MacOS and improve comments
Use FreeBSD memmem on MacOS, because although MacOS comes with a memmem, it is much slower than the FBSD one which implements Crochemore+Perrin two-way string matching. Also improve the comments to be more descriptive.
- Loading branch information
Showing
2 changed files
with
18 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,22 @@ | ||
#if defined _WIN32 | ||
/* On Linux we use glibc's memmem which uses the Knuth-Morris-Pratt algorithm. | ||
* We use FreeBSD's libc memmem on Windows and MacOS, which uses | ||
* Crochemore-Perrin two-way string matching. | ||
* Reasoning: | ||
* Windows, does not include any native memmem | ||
* MacOS has a memmem but is slower and originates from FreeBSD dated to 2005 */ | ||
|
||
#if defined(_WIN32) || defined(__APPLE__) || defined(__Darwin__) | ||
#include "../3rdparty/freebsd/memmem.c" | ||
#else | ||
/* On systems that use Glibc, you must defined _GNU_SOURCE before including string.h | ||
* to get access to memmem. On BSD and MacOS this is not needed, though if they | ||
* happen to be using glibc instead of libc, it shouldn't hurt have defined _GNU_SOURCE */ | ||
/* On systems that use glibc, you must define _GNU_SOURCE before including string.h | ||
* to get access to memmem. */ | ||
#define _GNU_SOURCE | ||
#endif | ||
#include <string.h> | ||
#endif | ||
|
||
void* MVM_memmem(const void *haystack, size_t haystacklen, const void *needle, size_t needlelen) { | ||
return memmem(haystack, haystacklen, needle, needlelen); | ||
} | ||
|
||
/* Extended info: | ||
* In glibc, the Knuth-Morris-Pratt algorithm was added as of git tag glibc-2.8-44-g0caca71ac9 */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters