<commit_before>
#ifndef STRING_MATCH_MY_MEMMEM_H
#define STRING_MATCH_MY_MEMMEM_H

#if defined(_MSC_VER) && (_MSC_VER >= 1020)
#pragma once
#endif

#include "basic/stdint.h"
#include <assert.h>

#include "StringMatch.h"
#include "AlgorithmWrapper.h"

//
// memmem()
//
// See: http://man7.org/linux/man-pages/man3/memmem.3.html
//

namespace StringMatch {

#if 1
template <typename char_type>
static inline
const char_type * my_memmem(const char_type * haystack_start, size_t haystack_len,
                            const char_type * needle_start, size_t needle_len) {
    /* The first occurrence of the empty string is deemed to occur at
       the beginning of the string. */
    if (likely(needle_len != 0)) {
        /* Sanity check, otherwise the loop might search through the whole memory. */
        if (likely(haystack_len >= needle_len)) {
            const char_type * haystack = haystack_start;
            const char_type * needle = needle_start;
            const char_type * haystack_end = haystack + haystack_len - needle_len;
            const char_type * needle_end = needle + needle_len;
            while (likely(haystack <= haystack_end)) {
                const char_type * n = needle;
                while (likely(*haystack != *n)) {
                    haystack++;
                    if (likely(haystack <= haystack_end))
						continue;
					else
                        return nullptr;
                }

				const char_type * h = haystack;
                do {
                    h++;
                    n++;
                    if (likely(n < needle_end)) {
						if (likely(*h != *n)) {
							haystack++;
							break;
						}
					}
					else {
                        return haystack;
					}
                } while (1);
            }
        }
        return nullptr;
    }
    else {
        return haystack_start;
    }
}
#elif 1
template <typename char_type>
static inline
const char_type * my_memmem(const char_type * haystack_start, size_t haystack_len,
                            const char_type * needle_start, size_t needle_len) {
    /* The first occurrence of the empty string is deemed to occur at
       the beginning of the string. */
    if (likely(needle_len != 0)) {
        /* Sanity check, otherwise the loop might search through the whole memory. */
        if (likely(haystack_len >= needle_len)) {
            const char_type * haystack = haystack_start;
            const char_type * needle = needle_start;
            const char_type * haystack_end = haystack + haystack_len - needle_len;
            const char_type * needle_end = needle + needle_len;
            for (;;) {
                const char_type * h = haystack;
                const char_type * n = needle;
                while (likely(*h != *n)) {<commit_msg>小改动;<commit_after>
#ifndef STRING_MATCH_MY_MEMMEM_H
#define STRING_MATCH_MY_MEMMEM_H

#if defined(_MSC_VER) && (_MSC_VER >= 1020)
#pragma once
#endif

#include "basic/stdint.h"
#include <assert.h>

#include "StringMatch.h"
#include "AlgorithmWrapper.h"

//
// memmem()
//
// See: http://man7.org/linux/man-pages/man3/memmem.3.html
//

namespace StringMatch {

#if 1
template <typename char_type>
static inline
const char_type * my_memmem(const char_type * haystack_start, size_t haystack_len,
                            const char_type * needle_start, size_t needle_len) {
    /* The first occurrence of the empty string is deemed to occur at
       the beginning of the string. */
    if (likely(needle_len != 0)) {
        /* Sanity check, otherwise the loop might search through the whole memory. */
        if (likely(haystack_len >= needle_len)) {
            const char_type * haystack = haystack_start;
            const char_type * needle = needle_start;
            const char_type * haystack_end = haystack + haystack_len - needle_len;
            const char_type * needle_end = needle + needle_len;
            do {
                const char_type * n = needle;
                while (likely(*haystack != *n)) {
                    haystack++;
                    if (likely(haystack <= haystack_end))
						continue;
					else
                        return nullptr;
                }

				const char_type * h = haystack;
                do {
                    h++;
                    n++;
                    if (likely(n < needle_end)) {
						if (likely(*h != *n)) {
							haystack++;
							break;
						}
					}
					else {
                        return haystack;
					}
                } while (1);
            } while (likely(haystack <= haystack_end));
        }
        return nullptr;
    }
    else {
        return haystack_start;
    }
}
#elif 1
template <typename char_type>
static inline
const char_type * my_memmem(const char_type * haystack_start, size_t haystack_len,
                            const char_type * needle_start, size_t needle_len) {
    /* The first occurrence of the empty string is deemed to occur at
       the beginning of the string. */
    if (likely(needle_len != 0)) {
        /* Sanity check, otherwise the loop might search through the whole memory. */
        if (likely(haystack_len >= needle_len)) {
            const char_type * haystack = haystack_start;
            const char_type * needle = needle_start;
            const char_type * haystack_end = haystack + haystack_len - needle_len;
            const char_type * needle_end = needle + needle_len;
            for (;;) {
                const char_type * h = haystack;
                const char_type * n = needle;
                while (likely(*h != *n)) {
{'fraction_non_alphanumeric': 0.09340758038440812, 'fraction_numerical': 0.00431111909466499, 'mean_word_length': 1.8524590163934427, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '900720', 'n_tokens_mistral': 1739, 'n_tokens_neox': 1575, 'n_words': 449}