Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Conversation

maxbrunsfeld
Copy link
Contributor

@maxbrunsfeld maxbrunsfeld commented Dec 16, 2016

Most of the time when searching a buffer, the search regex can only match within a single line. This is the case whenever the regex doesn't contain an explicit line ending character (\n or \r) or a negated character class (e.g. [^\w]). In this situation, we can avoid two inefficient aspects of the current search algorithm:

  1. We can avoid joining the buffer's text into a single string to pass to Regex.exec and then translating the resulting match positions back into 2-dimensional buffer ranges with the BufferOffsetIndex. Instead we can search each line individually, keeping track of the row as we go, so that we can provide the ranges with no cost.

  2. When searching backwards, there's no need for the back-off algorithm that we currently use to avoid searching from the beginning of the text. We can simply iterate through the lines in reverse.

/cc @nathansobo

@maxbrunsfeld maxbrunsfeld merged commit a48918c into master Dec 20, 2016
@maxbrunsfeld maxbrunsfeld deleted the mb-optimize-scan branch December 20, 2016 21:32
@nathansobo
Copy link
Contributor

This looks great.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants