Typing performance improvement#7193
Conversation
|
Great catch! |
There was a problem hiding this comment.
What if tabSize is 0?
There was a problem hiding this comment.
We don't let the tab size be 0, but if we just return 0 when it is 0, then this code won't break if we ever let it be 0. We know that the column will always be zero if the tabsize is 0.
Does CM, lets you use 0, for tabsize? If so, maybe we can fix other issues like this and make the min be 0.
There was a problem hiding this comment.
I fixed the code so that if anyone did set tabSize to 0, then we wouldn't retrieve pref on every Tab char.
I can't think of any reason why you'd want tabSize to be 0. Someone recently did something similar (#7020) but it was a hack that should have been done differently. Until I hear of a valid reason for doing it, then I think the minimum tabSize should be 1.
There was a problem hiding this comment.
It would be just for consistency. After the validation code is merged, we could assume that the tab size will be always be a value between 1 and 10. But here you assume that it can be 0, but if it is 0, then (column % tabSize) = NaN, and the code will return NaN, which isn't what you expect. Maybe we can just add if (tabSize = 0) { return 0; }?
There was a problem hiding this comment.
Good catch. I didn't notice that. Fixed.
|
That looks and feels good to me. Do you want to add another test case for the "unlikely" cases of |
|
As soon as the Validate Preferences pull request is merged, then it won't be possible to set a negative value for tabSize, so I don't think this is worth trying to test. |
Typing performance improvement
I discovered this when implementing editor preference validation. For
EditorStatusBarto display the cursor position, it callsEditor.getCursorPos()withexpandTabsoption. This causes the "tabSize" preference to be retrieved on every keystroke. This really sucks in a document that doesn't have any Tab characters!This changes it so the "tabSize" pref is not retrieved until a until a Tab char is found.
This value could be cached to improve it for docs with Tab chars since it rarely changes.