Skip to content

Commit 20b6827

Browse files
committed
XTC: simplified and reworked to be closer to original
* iterating through candidates from back to front makes it easy to keep the last of top tokens * some important commits from llama.cpp
1 parent 6b69d0b commit 20b6827

File tree

6 files changed

+148978
-148971
lines changed

6 files changed

+148978
-148971
lines changed

base/common.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -182,13 +182,19 @@ int get_math_cpu_count() {
182182

183183
void string_replace_all(std::string & s, const std::string & search, const std::string & replace) {
184184
if (search.empty()) {
185-
return; // Avoid infinite loop if 'search' is an empty string
185+
return;
186186
}
187+
std::string builder;
188+
builder.reserve(s.length());
187189
size_t pos = 0;
188-
while ((pos = s.find(search, pos)) != std::string::npos) {
189-
s.replace(pos, search.length(), replace);
190-
pos += replace.length();
191-
}
190+
size_t last_pos = 0;
191+
while ((pos = s.find(search, last_pos)) != std::string::npos) {
192+
builder.append(s, last_pos, pos - last_pos);
193+
builder.append(replace);
194+
last_pos = pos + search.length();
195+
}
196+
builder.append(s, last_pos, std::string::npos);
197+
s = std::move(builder);
192198
}
193199

194200
void process_escapes(std::string& input) {

0 commit comments

Comments
 (0)