Bug 553125 - Reduce calls to Document.getLineOfOffset in
ProjectionRulerColumn

Change-Id: I0be673a16d6916b5fce74fd0e7146f906470bbc7
Signed-off-by: Paul Pazderski <paul-eclipse@ppazderski.de>
diff --git a/org.eclipse.jface.text/projection/org/eclipse/jface/text/source/projection/ProjectionRulerColumn.java b/org.eclipse.jface.text/projection/org/eclipse/jface/text/source/projection/ProjectionRulerColumn.java
index 8c53b21..f1db464 100644
--- a/org.eclipse.jface.text/projection/org/eclipse/jface/text/source/projection/ProjectionRulerColumn.java
+++ b/org.eclipse.jface.text/projection/org/eclipse/jface/text/source/projection/ProjectionRulerColumn.java
@@ -159,25 +159,27 @@
 		if (position.getOffset() > -1 && position.getLength() > -1) {
 			try {
 				int startLine= document.getLineOfOffset(position.getOffset());
-				int end= position.getOffset() + position.getLength();
-				// Bug 347628: this method expects that the offset after the position range is the
-				// offset of the first line after this projected line range. In other words position
-				// comprise the whole projected range including the last lines delimiter. If position
-				// ends at document end the next offset is not the next line because there is no more content.
-				int endLine= end != document.getLength() ? document.getLineOfOffset(end) : document.getNumberOfLines();
-				if (startLine <= line && line < endLine) {
-					if (annotation.isCollapsed()) {
-						int captionOffset;
-						if (position instanceof IProjectionPosition)
-							captionOffset= ((IProjectionPosition) position).computeCaptionOffset(document);
-						else
-							captionOffset= 0;
+				if (startLine <= line) {
+					int end= position.getOffset() + position.getLength();
+					// Bug 347628: this method expects that the offset after the position range is the
+					// offset of the first line after this projected line range. In other words position
+					// comprise the whole projected range including the last lines delimiter. If position
+					// ends at document end the next offset is not the next line because there is no more content.
+					int endLine= end != document.getLength() ? document.getLineOfOffset(end) : document.getNumberOfLines();
+					if (line < endLine) {
+						if (annotation.isCollapsed()) {
+							int captionOffset;
+							if (position instanceof IProjectionPosition)
+								captionOffset= ((IProjectionPosition) position).computeCaptionOffset(document);
+							else
+								captionOffset= 0;
 
-						int captionLine= document.getLineOfOffset(position.getOffset() + captionOffset);
-						if (startLine <= captionLine && captionLine < endLine)
-							return Math.abs(line - captionLine);
+							int captionLine= document.getLineOfOffset(position.getOffset() + captionOffset);
+							if (startLine <= captionLine && captionLine < endLine)
+								return Math.abs(line - captionLine);
+						}
+						return line - startLine;
 					}
-					return line - startLine;
 				}
 			} catch (BadLocationException x) {
 			}