Results 1 to 6 of 6

Thread: [RESOLVED] [2005] Challenge: Faster Cursor Position

Hybrid View

  1. #1
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    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.

  2. #2

    Thread Starter
    Fanatic Member arsmakman's Avatar
    Join Date
    Dec 2001
    Location
    Leiden, Netherlands.
    Posts
    719

    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:
    1. Dim sText As String = Mid(EditorRichTextBox.Text, 1, _
    2.     EditorRichTextBox.SelectionStart)
    3. Dim iLine As Integer = 0
    4. Dim iIndex As Integer = 0
    5. Do
    6.     iLine += 1
    7.     iIndex = InStr(iIndex + 1, sText, vbLf)
    8. Loop While iIndex > 0
    9.  
    10. Dim iColumn As Integer = sText.Length - sText.LastIndexOf(vbLf)
    11. Dim iTotalLines = EditorRichTextBox.Lines.Length
    12.  
    13. CursorPositionToolStripStatusLabel.Text = "Line " & iLine & "/" & _
    14.     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
  •  



Click Here to Expand Forum to Full Width