I need Advice for my code's optimization....

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sukatoa
    Contributor
    • Nov 2007
    • 539

    #1

    I need Advice for my code's optimization....

    The code below,

    //I need help here....
    public void processChangedL ines(int offset, int length) throws BadLocationExce ption {
    String text = getText();
    ResetColor();

    Set<String> syntax = keywords.keySet ();
    Color color ;Pattern p;Matcher m;

    for (String keyword : syntax) {
    color = keywords.get(ke yword);
    p = Pattern.compile ("\\b" + keyword + "\\b");
    m = p.matcher(text) ;
    while(m.find()) {
    StyleConstants. setForeground(s tyle,col);
    setCharacterAtt ributes(m.start (),keyword.leng th(),style,fals e);
    }
    }
    }
    //I've tested the code below with all keywords in a line x 10000 lines (it is fast).... No problem here...
    private void ResetColor(){
    StyleConstants. setForeground(s tyle,Color.blac k);
    setCharacterAtt ributes(0,getLe ngth(),style,fa lse);
    }

    }

    are the methods for coloring syntax, im currently doing my notepad that supports syntax highlighting...

    I call that method when any key is pressed... " key events"

    The method's performance will slow after 400 lines

    I suspect the m = p.matcher(text) ; but i don't know the other alternatives for it....

    Can anyone here advice me how to reimplement, optimize and/or give me some algorithms for that method's optimization?

    Any reply will be appreciated...
    A beginner, Sukatoa..
  • sukatoa
    Contributor
    • Nov 2007
    • 539

    #2
    I need help please?!!!

    My codes above implements an algorithm that states,

    "compare each keyword from database to all words in the textPane"....

    New algorithm "compare each word from textpane to all keywords in database"...

    I believe that it is faster enough than the old one...

    But the big problem is that, "I really don't know how to implement it"...
    Can anyone guide me or give me some ideas, hints or classes to implement?

    I really feel bad about the performance...

    Any reply will be appreciated...

    Michael "sukatoa".. ..

    Comment

    Working...