public void measureGetLine(PerformanceMeter meter) throws BadLocationException { fTextStore.set(FAUST1); ILineTracker tracker = new DefaultLineTracker(); tracker.set(FAUST1); int lines = tracker.getNumberOfLines(); meter.start(); for (int times = 0; times < 100; times++) { for (int line = 0; line < lines; line++) { IRegion lineInfo = tracker.getLineInformation(line); fTextStore.get(lineInfo.getOffset(), lineInfo.getLength()); } } meter.stop(); }
/** * Creates a new comment region. * * @param document the document which contains the comment region * @param position the position of this comment region in the document * @param formatter the given code formatter */ public CommentRegion( final IDocument document, final Position position, final CodeFormatterVisitor formatter) { super(position.getOffset(), position.getLength()); this.preferences = formatter.preferences; fDelimiter = this.preferences.line_separator; fDocument = document; fTabSize = DefaultCodeFormatterOptions.SPACE == this.preferences.tab_char ? this.preferences.indentation_size : this.preferences.tab_size; this.scribe = formatter.scribe; final ILineTracker tracker = new DefaultLineTracker(); IRegion range = null; CommentLine line = null; tracker.set(getText(0, getLength())); final int lines = tracker.getNumberOfLines(); fSingleLine = lines == 1; try { for (int index = 0; index < lines; index++) { range = tracker.getLineInformation(index); line = createLine(); line.append(new CommentRange(range.getOffset(), range.getLength())); fLines.add(line); } } catch (BadLocationException exception) { // Should not happen } }