Skip to content

Commit f59094a

Browse files
committed
Merge remote-tracking branch 'origin/gg/replace-all' into Nexes_Quants_Refac
2 parents b55349b + bddcc5f commit f59094a

File tree

3 files changed

+17
-21
lines changed

3 files changed

+17
-21
lines changed

Diff for: examples/baby-llama/baby-llama.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#include "ggml.h"
22
#include "train.h"
33

4-
#include <vector>
54
#include <cassert>
65
#include <cstdlib>
76
#include <cstring>

Diff for: flake.lock

+10-10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: src/llama.cpp

+7-10
Original file line numberDiff line numberDiff line change
@@ -122,17 +122,14 @@ static std::string trim(const std::string & str) {
122122
}
123123

124124
static void replace_all(std::string & s, const std::string & search, const std::string & replace) {
125-
std::string result;
126-
for (size_t pos = 0; ; pos += search.length()) {
127-
auto new_pos = s.find(search, pos);
128-
if (new_pos == std::string::npos) {
129-
result += s.substr(pos, s.size() - pos);
130-
break;
131-
}
132-
result += s.substr(pos, new_pos - pos) + replace;
133-
pos = new_pos;
125+
if (search.empty()) {
126+
return; // Avoid infinite loop if 'search' is an empty string
127+
}
128+
size_t pos = 0;
129+
while ((pos = s.find(search, pos)) != std::string::npos) {
130+
s.replace(pos, search.length(), replace);
131+
pos += replace.length();
134132
}
135-
s = std::move(result);
136133
}
137134

138135
static bool is_float_close(float a, float b, float abs_tol) {

0 commit comments

Comments
 (0)