RE: insertString(int,String,AttributeSet) method in the Document Class ?

Discussion in 'Java' started by pvii007, Dec 10, 2005.

  1. pvii007

    pvii007 Guest

    I wrote the code to realize lighting specific code in the Document Object.
    ( this function is similar with the syntax light in the IDE)

    I use insertString(int,String,AttributeSet) method in the Document Class to
    add the light to the specific text.

    My algorithm is

    1. search the specific word in the Document Object which is got from the
    StyledDocument

    2. delete the specific word because it lack of the color attribute

    3. insert the specific word combined with the color attribute into the
    document at the original position

    4. search next specific word. If it exist, goto Step 2. Otherwise program is
    end.

    But the efficiency of my algorith is too low.

    When the program is running, the useage of CPU is 100%.

    I debug the code and find out that the problem seems to be at the Step 2 and
    3 which occupy over 80% time at the whole program!!!

    It occur at me that the problem will be worse if the text in the Document is
    very long.

    How to implement it( like syntax light)?

    How do JBuilder realize this function?
    pvii007, Dec 10, 2005
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Schnoffos
    Replies:
    2
    Views:
    1,206
    Martien Verbruggen
    Jun 27, 2003
  2. Hal Styli
    Replies:
    14
    Views:
    1,625
    Old Wolf
    Jan 20, 2004
  3. arun
    Replies:
    8
    Views:
    450
    Dave Thompson
    Jul 31, 2006
  4. aling
    Replies:
    8
    Views:
    942
    Jim Langston
    Oct 20, 2005
  5. Replies:
    9
    Views:
    428
    James Kanze
    Apr 17, 2007
Loading...

Share This Page