|
-
Jul 19th, 2006, 06:46 AM
#1
Re: [2005] Challenge: Faster Cursor Position
Split is the slowest thing since a stalled Morris minor. You are completely killing your ram usage with that.
There's no use using split to count the lines when all you have to do is loop through and count the number of vbLF's. This won't use any extra ram and will be infinitely faster.
You can get the total lines and the current cursor line in a single loop, the column position will be the difference between the absolute cursor position and the position of the vbLF just to the left of the cursor.
Easy peasy. 
I'll let you have a go at coding that yourself first.
I don't live here any more.
-
Jul 19th, 2006, 07:22 AM
#2
Thread Starter
Fanatic Member
Re: [2005] Challenge: Faster Cursor Position
I didn't know Split was slow, thanks Wossname. I now have this. It's faster, 90ms, but still a bit too slow.
VB Code:
Dim sText As String = Mid(EditorRichTextBox.Text, 1, _
EditorRichTextBox.SelectionStart)
Dim iLine As Integer = 0
Dim iIndex As Integer = 0
Do
iLine += 1
iIndex = InStr(iIndex + 1, sText, vbLf)
Loop While iIndex > 0
Dim iColumn As Integer = sText.Length - sText.LastIndexOf(vbLf)
Dim iTotalLines = EditorRichTextBox.Lines.Length
CursorPositionToolStripStatusLabel.Text = "Line " & iLine & "/" & _
iTotalLines & ", Column " & iColumn
No matter how fool-proof your program is, there will always be a better fool.
Was a post helpful to you? Rate it!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|