Skip to main content
Code Review

Return to Answer

replaced http://codereview.stackexchange.com/ with https://codereview.stackexchange.com/
Source Link

Currently the it's O(n) where n is the length of the text inside the JTextPane. You could reduce it if you process only the modified regions of the document in the event listener. I think DocumentEvent's getLength() and getOffset() method could help here.

Another notes:

  1. int index = 0, carriage = 0;
    

I'd put the variable declarations to separate lines. From Code Complete, 2nd Edition, p759:

With statements on their own lines, the code reads from top to bottom, instead of top to bottom and left to right. When you’re looking for a specific line of code, your eye should be able to follow the left margin of the code. It shouldn’t have to dip into each and every line just because a single line might contain two statements.

  1. Be aware of static helper classes, like Keywords. You might find my former answer about it my former answer about it useful.

Currently the it's O(n) where n is the length of the text inside the JTextPane. You could reduce it if you process only the modified regions of the document in the event listener. I think DocumentEvent's getLength() and getOffset() method could help here.

Another notes:

  1. int index = 0, carriage = 0;
    

I'd put the variable declarations to separate lines. From Code Complete, 2nd Edition, p759:

With statements on their own lines, the code reads from top to bottom, instead of top to bottom and left to right. When you’re looking for a specific line of code, your eye should be able to follow the left margin of the code. It shouldn’t have to dip into each and every line just because a single line might contain two statements.

  1. Be aware of static helper classes, like Keywords. You might find my former answer about it useful.

Currently the it's O(n) where n is the length of the text inside the JTextPane. You could reduce it if you process only the modified regions of the document in the event listener. I think DocumentEvent's getLength() and getOffset() method could help here.

Another notes:

  1. int index = 0, carriage = 0;
    

I'd put the variable declarations to separate lines. From Code Complete, 2nd Edition, p759:

With statements on their own lines, the code reads from top to bottom, instead of top to bottom and left to right. When you’re looking for a specific line of code, your eye should be able to follow the left margin of the code. It shouldn’t have to dip into each and every line just because a single line might contain two statements.

  1. Be aware of static helper classes, like Keywords. You might find my former answer about it useful.
Source Link
palacsint
  • 30.3k
  • 9
  • 82
  • 157

Currently the it's O(n) where n is the length of the text inside the JTextPane. You could reduce it if you process only the modified regions of the document in the event listener. I think DocumentEvent's getLength() and getOffset() method could help here.

Another notes:

  1. int index = 0, carriage = 0;
    

I'd put the variable declarations to separate lines. From Code Complete, 2nd Edition, p759:

With statements on their own lines, the code reads from top to bottom, instead of top to bottom and left to right. When you’re looking for a specific line of code, your eye should be able to follow the left margin of the code. It shouldn’t have to dip into each and every line just because a single line might contain two statements.

  1. Be aware of static helper classes, like Keywords. You might find my former answer about it useful.
lang-java

AltStyle によって変換されたページ (->オリジナル) /