Skip to content

Commit

Permalink
optimize JoinInner()
Browse files Browse the repository at this point in the history
  • Loading branch information
kjk committed May 24, 2024
1 parent 5e57138 commit bff4bc0
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/utils/StrVec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,22 @@ static int CalcCapForJoin(const StrVec& v, const char* joint) {

static char* JoinInner(const StrVec& v, const char* joint, str::Str& res) {
int len = v.Size();
size_t jointLen = str::Len(joint);
int jointLen = str::Leni(joint);
// TODO: possibly not handling null values in the middle. need to add more tests and fix
int firstForJoint = 0;
for (int i = 0; i < len; i++) {
char* s = v.At(i);
if (!s) {
int i = 0;
for (auto it = v.begin(); it != v.end(); it++) {
auto s = it.Span();
if (!s.Str()) {
firstForJoint++;
i++;
continue;
}
if (i > firstForJoint && jointLen > 0) {
res.Append(joint, jointLen);
}
res.Append(s);
res.Append(s.Str(), s.Len());
i++;
}
return res.StealData();
}
Expand Down

0 comments on commit bff4bc0

Please sign in to comment.