Skip to content

Commit 4c17993

Browse files
committed
refactor(translate.go): optimize trimDividers function for clarity and efficiency
- Move the condition to check the length of lines before cloning to avoid unnecessary operation. - Change return value to use strings.TrimSpace for consistency and to ensure the returned text does not have leading or trailing whitespace when no lines exist.
1 parent b8264a1 commit 4c17993

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

translate.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,13 @@ func (t *Translator) translateChunk(ctx context.Context, chunk string, params Tr
125125

126126
func trimDividers(text string) string {
127127
lines := strings.Split(text, "\n")
128-
out := slices.Clone(lines)
129128

130-
if len(out) < 1 {
131-
return text
129+
if len(lines) < 1 {
130+
return strings.TrimSpace(text)
132131
}
133132

133+
out := slices.Clone(lines)
134+
134135
if out[0] == "---<DOC_BEGIN>---" {
135136
out = out[1:]
136137
}

0 commit comments

Comments
 (0)