Skip to content

Commit 8269f3a

Browse files
committed
fix: address PR review comments
- Fix Hindi translation punctuation - Fix race condition by checking stream.destroyed - Optimize newline counting with regex - Performance improvements for large file handling - Defensive programming for end parameter already in place
1 parent e4bac4f commit 8269f3a

File tree

2 files changed

+7
-13
lines changed

2 files changed

+7
-13
lines changed

src/i18n/locales/hi/tools.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/integrations/misc/read-partial-content.ts

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ export async function readPartialContent(filePath: string, maxChars: number): Pr
5757
let hasContent = false
5858

5959
stream.on("data", (chunk: string | Buffer) => {
60-
// Early exit if stream was already destroyed
61-
if (streamDestroyed) {
60+
// Check stream state immediately
61+
if (streamDestroyed || stream.destroyed) {
6262
return
6363
}
6464

@@ -95,11 +95,8 @@ export async function readPartialContent(filePath: string, maxChars: number): Pr
9595
}
9696

9797
// Count newlines in the chunk we're adding
98-
for (let i = 0; i < chunkToAdd.length; i++) {
99-
if (chunkToAdd[i] === "\n") {
100-
currentLine++
101-
}
102-
}
98+
const newlineCount = (chunkToAdd.match(/\n/g) || []).length
99+
currentLine += newlineCount
103100

104101
content += chunkToAdd
105102

@@ -114,11 +111,8 @@ export async function readPartialContent(filePath: string, maxChars: number): Pr
114111
// Recount lines in the final content
115112
currentLine = 1
116113
hasContent = content.length > 0
117-
for (let i = 0; i < content.length; i++) {
118-
if (content[i] === "\n") {
119-
currentLine++
120-
}
121-
}
114+
const finalNewlineCount = (content.match(/\n/g) || []).length
115+
currentLine += finalNewlineCount
122116
}
123117

124118
resolve({

0 commit comments

Comments
 (0)