Skip to content

Minor code efficiency issue, use of LineIsMultiLine() #1125

@msftrncs

Description

@msftrncs

While working on #1108, while proposing to have InsertLineAbove() utilize GetBeginningOfLinePos() since it performs the exact same loop backward through the buffer searching for a \n, I was almost going to leave the original reference to LineIsMultiLine() in InsertLineAbove(), though it also occurs in GetBeginningOfLinePos().

However when I look at the code for LineIsMultiLine() it is itself a search through the buffer for a \n. Statistically, if LineIsMultiLine() finds a \n then there is now going to be Ta + Tb time spent searching for \n instead of just Tb time spent, where Ta is time spent to find the first \n in the buffer and Tb is time spent to find a \n under the specific scenario of the function. In the case where no \n is found, LineIsMultiLine() will touch every character in the buffer to confirm that, where as in the specific scenario of the function will result in a variable number characters being checked, from 0 through all of them, depending on the scenario.

Is there a reason for this approach?

Is there a downside to removing the use of LineIsMultiLine() when making changes to such functions?

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions