|
From: | Dmitry Gutov |
Subject: | bug#60953: The :match predicate with large regexp in tree-sitter font-lock seems inefficient |
Date: | Mon, 30 Jan 2023 19:15:07 +0200 |
User-agent: | Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2 |
On 30/01/2023 17:08, Eli Zaretskii wrote:
Date: Mon, 30 Jan 2023 16:47:01 +0200 Cc:casouri@gmail.com,60953@debbugs.gnu.org From: Dmitry Gutov<dgutov@yandex.ru> On 30/01/2023 16:06, Eli Zaretskii wrote:But why do you need to narrow there? fast_looking_at will not go beyond end_pos/end_byte anyway, there's no need to restrict it.The reason for that is to be able to support the \` and \' markers in REGEXP. I haven't found any alternative approach that doesn't call 'substring'.fast_looking_at already does an anchored match, so I'm not sure I follow. I don't even understand why you need th \` part, when the match will either always start from the first position or fail.
The regexp might include the anchors, or it might not. It might also use a different anchor like ^ or $ or \b. See these examples from the documentation: ((_) @bob (#match \"^B.b$\" @bob)) '(( (compound_expression :anchor (_) @@first (_) :* @@rest) (:match "love" @@first) ))
And for \', just compare the length of the match returned by fast_looking_at with the length of the text.
This seems to work, i.e. even when before "carpet", (and (looking-at (regexp-opt '("car" "cardigan" "carpet"))) (match-string 0))returns the full match. I was expecting that it could return just "car" -- not sure why it doesn't stop there.
But again, to find out whether we need to use the end anchor at all, we'd have to parse the regexp, remove the actual anchor before calling fast_looking_at, and then add the above check.
One possible alternative, I suppose, would be to create a raw pointer to a part of the buffer text and call re_search directly specifying the known length of the node in bytes. If buffer text is one contiguous region in memory, that is. This way we would regexp test against a string (not a buffer), but without creating a separate string object.
[Prev in Thread] | Current Thread | [Next in Thread] |