Jump to content

HTML syntax highlight optimization?

- - - - -

  • Please log in to reply
No replies to this topic

#1
CommittedC0der

CommittedC0der

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,565 posts
Hello everyone, I have a HTML syntax highlighter pretty well working, but I know I used a inefficient way of highlighting and was wondering if there was a way to optimize it. here is some of my code:
public void Markup()
        {
            Regex rex = new Regex("<html>|</html>|<head.*?>|</head>|<body.*?>|</body>|<div.*?>|</div>|<span.*?>|</span>|<title.*?>|</title>|<style.*?>|</style>|<script.*?>|</script>|<link.*?/>|<meta.*?/>|<base.*?/>|<center.*?>|<center>|<a.*?>|</a>");
            int selectionstart = richTextBox1.SelectionStart;
            foreach (Match m in rex.Matches(richTextBox1.Text))
            {
                richTextBox1.Select(m.Index, m.Value.Length);
                richTextBox1.SelectionColor = Color.Blue;
                richTextBox1.Select(selectionstart, 0);
                richTextBox1.SelectionColor = Color.Black;
            }
        }
 
private void richTextBox1_TextChanged(object sender, EventArgs e)
        {
 
            int[] number = new int[] { 0 };
            foreach (int num in number)
            {
                    try
                    {
                        LockWindowUpdate(richTextBox1.Handle);//Stop flashing
                        Markup();
                        Elements();
                        TextMarkup();
                        FormsTabels();
                        Attributes();
                        Comments();
}
                    finally { LockWindowUpdate(IntPtr.Zero); }
 
                }
            }



As you can see I have quite a few more methods for highlighting which can really slow down my richTextBox so I tried running the methods in a foreach loops because I read it was able to process really fast but this did not help much, does any one else know of a way I could optimize this? Thanks. Posted Image
A man can be defined by what he does when no one is looking.
Science is only an educated theory, which we cannot disprove.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users