aligrudi / neatvi

A small vi/ex editor for editing bidirectional UTF-8 text

Home Page:http://litcave.rudi.ir/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

rstr is bugged (^$ enclosed match)

kyx0r opened this issue · comments

commented

Hello Ali,
Hope all is well.
Yesterday I've taken a look at some other optimization option like rstr.
I've successfully implemented rstr as an optional patch for nextvi.
I even made a multi threaded version too.
[1] https://github.com/kyx0r/nextvi/blob/patches/rstr.patch

As I was testing, I found a bug. Searches like ^int$ do not work correctly.
I have fixed the problem in the patch above, never mind the macro craziness though
(Yes I am that hardcore and determined to optimize constant if statements out the
hot loops)

Basically my implementation fixes the bug by running 2 separate loops one for ^ and last one
for $, if ^ loop matched and $ is set the execution is handed to the $ loop for another round
of verification.
This solution may not be in realm of neatvi's standards but I haven't thought of any other ways.
I just made it work and efficiently.

Offtopic:
I have made another cool patch for my needs, this one is like grep implementation in nextvi
[2] https://github.com/kyx0r/nextvi/blob/patches/grep.patch

From our last discussion I have came up with some even better solutions and optimizations
to led_render() function, basically this is a good as it will ever get. I guess the truly genius
part was how I reassign the hl attributes after the led_bounds() call.
Now I can actually give a proper answer as to why this problem is so damn hard,
and it's hard because any character can be at any arbitrary screen position out
of sequence, this is the definition of pure chaos that no algorithm can really
solve efficiently and with the same results as naive approach.
I even tried some other genius idea I had, that was to try min - max the pointers
of chrs array that will get placed on the screen, then try to run a bound from
min to max pointer. This does work for the most part except when characters
get reordered in such a way that the computed character at chrs[0] and chrs[n]
both can meet on the same screen. When something like this happens obviously
the bound will not be a bound anymore, it will be exact copy of entire string. It will
be impossible to highlight a line that gets reordered like that without processing
entire string, which sadly is utterly slow. That is why current solution in led.c
relies on a guaranteed string, but it's not going to be exactly the same when
text is in reverse. Still it's way better than anything I ever had before and very
well defined behavior.

Kind Regards,
Kyryl.

commented