-
Notifications
You must be signed in to change notification settings - Fork 1.3k
ReHighlightStates: sanity-check startline value
#3237
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ReHighlightStates: sanity-check startline value
#3237
Conversation
Check if startline value is valid before passing it to input.State(), to prevent a theoretically possible race when the number of lines changes in the meantime, causing an out of bounds access. Actually this race cannot happen: ReHighlightStates() is only called from the main goroutine, and the line array is modified, again, only by the main goroutine. So for now this change is rather cosmetic: it is just to make the highligher API implementation self-sufficiently safe without assumptions about which goroutines are using which API functions and how.
JoeKar
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A different cosmetic style (one if-indentation less; startline must be read anyway)...
input.Lock()
if startline > 0 && startline-1 < input.LinesNum() {
h.lastRegion = input.State(startline - 1)
}
input.Unlock()
...but your proposal does the job the same and is ok too. :)
|
In my version we avoid unneeded locking if |
|
Yes, it "affects" the performance and should weight more...and readability is a matter of perspective. |
|
Hmm... BTW what about the access to
should be fine, since the incorrect highlighting done at step 3 should be "overwritten" by correct highlighting at steps 4 and 5. But, since both these async highlighting and sync rehighlighting rely on the shared value of I guess this could be easily fixed by changing ...Actually it seems it would be even better if we made the very concept of "line state" local as well, i.e. if we combined |
I've recalled you already did that in #3127 (for performance reasons). So, there seems to be more than one good reason to do that. |
Yes, this should be improved...
...as suggested.
Definitely, it makes it less complicated and thus much easier to understand. So this is definitely worth spending the effort. I don't think that we should spend that much more effort in the current base, since we already found out the limitations of the present approach. Edit:
Hm, in case we need to re-highlight from line 3..5, we need this info from line 2. We've to start from 0 (even when we should do that beginning from 3) in the moment we don't store this globally, otherwise we've no chance to shorten that path by directly asking for the state before. Because we don't know, when this state/ |
Hmm, right. Yeah, I was mistaken, we should keep storing those states globally. But So for now we can just make |
Yes, at least kind of. I already tried that in the local state of my rework, but it isn't that easy as it looks in the first place.
Fully ACK.
Yep, this is already done...just |
Hm, yeah, I've recalled that you added it back in 22de1d3 for some reason... I don't really understand for what reason, and what is "bottom up changes". |
Well, yes...hm...I can only assume, that my scenario was to remove the end of an region, which afterwards wasn't properly highlighted downwards. From my perspective it's correct to have fixed boundaries for the real highlighting, but these slightly faster state checks need to scan er certain region probably behind the initial PS: |
|
Well yeah, that's what I was thinking of when I was thinking of a combined
Do we really need this differentiation? Can't we scan beyond We have just 2 cases anyway:
And even if there were more cases, highlighting up to the last lines that requires it, without leaving lines past |
Reasonable perspective.
Yes, I would say so, since the "scanning" still does the
I will consider it in the rework...so there is only one interface to be used for conventional highlighting any longer.
Yep, here you're right...we should prevent broken highlighting anyway, so there is no real usage for Edit:
I decided against it (see #3127 resp dfbfd0a), since |
Check if
startlinevalue is valid before passing it toinput.State(), to prevent a theoretically possible race when the number of lines changes in the meantime, causing an out of bounds access.Actually this race cannot happen:
ReHighlightStates()is only called from the main goroutine, and the line array is modified, again, only by the main goroutine. So for now this change is rather cosmetic: it is just to make the highligher API implementation self-sufficiently safe without assumptions about which goroutines are using which API functions and how.