Skip to content

Commit a08cbe9

Browse files
committed
perf: use substring instead of split for line detection
1 parent b7ed5fb commit a08cbe9

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

src/index.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -808,9 +808,17 @@ export function mergeAgentsFiles(agentsFiles: string[]): string {
808808
result.push(content);
809809

810810
if (nextContent) {
811-
const currentLines = content.split('\n');
812-
const lastLine = currentLines[currentLines.length - 1];
813-
const nextFirstLine = nextContent.split('\n')[0];
811+
const lastNewLineIndex = content.lastIndexOf('\n');
812+
const lastLine =
813+
lastNewLineIndex === -1
814+
? content
815+
: content.substring(lastNewLineIndex + 1);
816+
817+
const firstNewLineIndex = nextContent.indexOf('\n');
818+
const nextFirstLine =
819+
firstNewLineIndex === -1
820+
? nextContent
821+
: nextContent.substring(0, firstNewLineIndex);
814822

815823
// If both blocks are part of an unordered list (starting with '- '),
816824
// skip the newline to merge them.

0 commit comments

Comments
 (0)