Skip to content

Commit 1f41368

Browse files
committed
perf: replace fastsearch with std::boyer_moore_searcher
Our benchmarks show that `std::boyer_moore_searcher` is faster than the custom `fastsearch` implementation, and it also simplifies the codebase.
1 parent 1a3ba7b commit 1f41368

4 files changed

Lines changed: 14 additions & 71 deletions

File tree

src/fastsearch.cc

Lines changed: 0 additions & 60 deletions
This file was deleted.

src/fastsearch.h

Lines changed: 0 additions & 8 deletions
This file was deleted.

src/utils.cc

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <cstdio>
1212
#include <cstring>
1313
#include <cwctype>
14+
#include <functional>
1415
#include <optional>
1516
#include <ranges>
1617
#include <string>
@@ -165,7 +166,19 @@ std::wstring JoinArgsString(const std::vector<std::wstring>& lines,
165166

166167
// Search memory.
167168
uint8_t* memmem(uint8_t* src, int n, const uint8_t* sub, int m) {
168-
return const_cast<uint8_t*>(FastSearch(src, n, sub, m));
169+
if (!src || !sub || n < m) {
170+
return nullptr;
171+
}
172+
if (m == 0) {
173+
return src;
174+
}
175+
auto it = std::search(src, src + n, std::boyer_moore_searcher(sub, sub + m));
176+
177+
// 3. 检查是否找到
178+
if (it != src + n) {
179+
return it;
180+
}
181+
return nullptr;
169182
}
170183

171184
std::wstring GetIniString(std::wstring_view section,

src/utils.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
#include <string_view>
99
#include <vector>
1010

11-
#include "fastsearch.h"
12-
1311
// Global variable declaration
1412
extern HMODULE hInstance;
1513

0 commit comments

Comments
 (0)