@cmyr @raphlinus
I'm writing a parser for Org markup and I use xi-rope as underlying data structure.
There are numerous cases when I need to do a multilne regex search/match. Sometimes repeatedly. (Examples: poperty drawers are recognized by multiline regex)
In case of multiline regex search whole text of the rope is allocated into a temporary string.
https://github.com/xi-editor/xi-editor/blob/master/rust/rope/src/find.rs#L290
if is_multiline_regex(pat) {
// consume all of the text if regex is multi line matching
text = Cow::from(String::from_iter(lines));
} else {
match lines.next() {
Some(line) => text = line,
_ => return None,
}
}
With big files and repeated multiline searches this really becomes a huge tax on performance.
I understand that this is due to the nature of the data structure at hand -the text stored in a set of chunks that are not connected to each other.
There are 2 questions I have:
Cow::from(String::from_iter(lines)) to make it available for subsequent searches. But if I have to maintain a plain string alongside rope - what is the benefit of using a rope? That leads me to the next questionI will post the essence of my conversation with @cmyr and @raphlinus on zulip chat.
This is a known downside of the Rope data structure. By being a non-contiguous data storage it is not directly compatible with existing tools like regex engine. Regex engine operates on String, so allocation to a contiguous memory area is necessary.
Possible workarounds:
@ngortheone Should we keep this open? It's not clear that it's really actionable for us at this point.
@cmyr I don't think this is actionable at the moment.
This question may come up again, so it is worth adding it to FAQ of some sort
I will leave this here for reference
https://github.com/rust-lang/regex/issues/425
Most helpful comment
I will leave this here for reference
https://github.com/rust-lang/regex/issues/425