Skip to content

Commit 34b37e6

Browse files
committed
Performance Improvement
1 parent 795863a commit 34b37e6

1 file changed

Lines changed: 13 additions & 13 deletions

File tree

Src/views/VwSelection.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5463,24 +5463,24 @@ bool VwTextSelection::ReplacementTextIsSingleParagraph(ITsString* replacementTst
54635463
int replacementCharCount;
54645464
SmartBstr replacementBstr;
54655465
CheckHr(replacementTstr->get_Length(&replacementCharCount));
5466+
if (replacementCharCount <= 0)
5467+
return false;
5468+
54665469
CheckHr(replacementTstr->get_Text(&replacementBstr));
54675470
const wchar* replacementText = replacementBstr.Chars();
5468-
for (int ii = 0; ii < replacementCharCount; ii++)
5471+
5472+
// A single paragraph must end with exactly one trailing '\n'.
5473+
if (replacementText[replacementCharCount - 1] != '\n')
5474+
return false;
5475+
5476+
// Ensure there are no other '\n' characters before the final one.
5477+
for (int ii = 0; ii < replacementCharCount - 1; ii++)
54695478
{
54705479
if (replacementText[ii] == '\n')
5471-
{
5472-
// The last character is a '\n' and there are no other '\n' characters in the string.
5473-
if (ii == replacementCharCount - 1)
5474-
{
5475-
return true;
5476-
}
5477-
else
5478-
{
5479-
break;
5480-
}
5481-
}
5480+
return false;
54825481
}
5483-
return false;
5482+
5483+
return true;
54845484
}
54855485

54865486
/*----------------------------------------------------------------------------------------------

0 commit comments

Comments
 (0)