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:
-
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.
- 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:
-
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.
- 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:
-
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.
- 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:
-
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.
- Be aware of static helper classes, like
Keywords
. You might find my former answer about it useful.