Skip to content

Commit 1b01b82

Browse files
rijnbclaude
andcommitted
perf: A3 — length-tracked result assembly in encoderEngine
strcpy + strcat + strcat each re-scans the destination from the start to find the null terminator. Replace with explicit strlen on each source plus a single memcpy to copy result (including NUL). Output bytes are unchanged. time ./unittest (best of 3, user): baseline = 114.13s after A3 = 113.19s delta = 0.82% cumulative Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 5246c79 commit 1b01b82

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

mapcodelib/mapcoder.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1542,8 +1542,12 @@ static void encoderEngine(const enum Territory ccode, const EncodeRec* enc, cons
15421542
}
15431543
else {
15441544
getTerritoryIsoName(s, ccodeFinal, 0);
1545-
strcat(s, " ");
1546-
strcat(s, result);
1545+
{
1546+
size_t isoLen = strlen(s);
1547+
size_t resultLen = strlen(result);
1548+
s[isoLen] = ' ';
1549+
memcpy(s + isoLen + 1, result, resultLen + 1); /* +1 includes NUL */
1550+
}
15471551
}
15481552
}
15491553
if (requiredEncoder == i) {

0 commit comments

Comments
 (0)