Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Keppler2018-09-14 04:39:17 +0000
committerMichael Keppler2018-09-24 06:42:53 +0000
commitc902eb5d3d9ecb59c2179ab178eff4220bb86b2d (patch)
treec63a4aa20cb7ea509b058b9efdfc83e3e419a050 /org.eclipse.jface.text
parent542f40e5776d928308fc6443fe6293463e2b5483 (diff)
downloadeclipse.platform.text-c902eb5d3d9ecb59c2179ab178eff4220bb86b2d.tar.gz
eclipse.platform.text-c902eb5d3d9ecb59c2179ab178eff4220bb86b2d.tar.xz
eclipse.platform.text-c902eb5d3d9ecb59c2179ab178eff4220bb86b2d.zip
Bug 538504 - Performance of FaceTextUtil.isShowingEntireContents()
For huge widgets avoid calculating all line heights to see whether scrolling is necessary in the widget. Instead calculate the last visible line and decide based on its index and visibility. This reduces the costly line height calculation to a small number, completely decoupled from the line count in the document. In my profiling use case with a 42.000 lines git diff editor (which has variable line height), the runtime of the changed method dropped from 640ms to less than 10ms, as measured in Yourkit. Change-Id: I25cd71587afcf2c266ec48255cb87cb35da6cce2 Signed-off-by: Michael Keppler <Michael.Keppler@gmx.de>
Diffstat (limited to 'org.eclipse.jface.text')
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/JFaceTextUtil.java15
1 files changed, 12 insertions, 3 deletions
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/JFaceTextUtil.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/JFaceTextUtil.java
index 4810cf5f4cb..2421c354d83 100644
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/JFaceTextUtil.java
+++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/JFaceTextUtil.java
@@ -305,12 +305,21 @@ public final class JFaceTextUtil {
* be vertically scrolled, <code>false</code> otherwise
*/
public static boolean isShowingEntireContents(StyledText widget) {
- if (widget.getTopPixel() != 0) // more efficient shortcut
+ if (widget.getTopPixel() != 0) {
+ // more efficient shortcut
return false;
+ }
int lastVisiblePixel= computeLastVisiblePixel(widget);
- int lastPossiblePixel= widget.getLinePixel(widget.getLineCount());
- return lastPossiblePixel <= lastVisiblePixel;
+ int bottom= widget.getLineIndex(lastVisiblePixel);
+ if (bottom + 1 < widget.getLineCount()) {
+ // There's definitely more lines below
+ return false;
+ }
+
+ // Check whether the last line is fully visible
+ int bottomLastPixel= getLinePixel(widget, bottom + 1) - 1;
+ return bottomLastPixel <= lastVisiblePixel;
}
/**

Back to the top