mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-23 00:45:28 +02:00
Minor performance optimization.
This commit is contained in:
parent
33a2f3c025
commit
e4b3bce29b
1 changed files with 10 additions and 13 deletions
|
@ -7,6 +7,7 @@
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Markus Schorn - initial API and implementation
|
* Markus Schorn - initial API and implementation
|
||||||
|
* Sergey Prigogin (Google)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.core.parser.scanner;
|
package org.eclipse.cdt.internal.core.parser.scanner;
|
||||||
|
|
||||||
|
@ -19,6 +20,7 @@ import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTNodeLocation;
|
import org.eclipse.cdt.core.dom.ast.IASTNodeLocation;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit.IDependencyTree.IASTInclusionNode;
|
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit.IDependencyTree.IASTInclusionNode;
|
||||||
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
||||||
|
import org.eclipse.cdt.core.parser.util.IntArray;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base class for all location contexts that can contain children.
|
* Base class for all location contexts that can contain children.
|
||||||
|
@ -51,7 +53,7 @@ class LocationCtxContainer extends LocationCtx {
|
||||||
|
|
||||||
public void addChild(LocationCtx locationCtx) {
|
public void addChild(LocationCtx locationCtx) {
|
||||||
if (fChildren == null) {
|
if (fChildren == null) {
|
||||||
fChildren= new ArrayList<LocationCtx>();
|
fChildren= new ArrayList<>();
|
||||||
}
|
}
|
||||||
fChildren.add(locationCtx);
|
fChildren.add(locationCtx);
|
||||||
}
|
}
|
||||||
|
@ -74,7 +76,7 @@ class LocationCtxContainer extends LocationCtx {
|
||||||
public final int getSequenceNumberForOffset(int offset, boolean checkChildren) {
|
public final int getSequenceNumberForOffset(int offset, boolean checkChildren) {
|
||||||
int result= fSequenceNumber + fChildSequenceLength + offset;
|
int result= fSequenceNumber + fChildSequenceLength + offset;
|
||||||
if (checkChildren && fChildren != null) {
|
if (checkChildren && fChildren != null) {
|
||||||
for (int i= fChildren.size() - 1; i >= 0; i--) {
|
for (int i= fChildren.size(); --i >= 0;) {
|
||||||
final LocationCtx child= fChildren.get(i);
|
final LocationCtx child= fChildren.get(i);
|
||||||
if (child.fEndOffsetInParent > offset) { // Child was inserted behind the offset, adjust sequence number
|
if (child.fEndOffsetInParent > offset) { // Child was inserted behind the offset, adjust sequence number
|
||||||
result -= child.getSequenceLength();
|
result -= child.getSequenceLength();
|
||||||
|
@ -208,7 +210,7 @@ class LocationCtxContainer extends LocationCtx {
|
||||||
int upper= fChildren.size();
|
int upper= fChildren.size();
|
||||||
int lower= 0;
|
int lower= 0;
|
||||||
while (upper > lower) {
|
while (upper > lower) {
|
||||||
int middle= (upper + lower) / 2;
|
int middle= (upper + lower) >>> 1;
|
||||||
LocationCtx child= fChildren.get(middle);
|
LocationCtx child= fChildren.get(middle);
|
||||||
int childSequenceNumber= child.fSequenceNumber;
|
int childSequenceNumber= child.fSequenceNumber;
|
||||||
if (beforeReplacedChars) {
|
if (beforeReplacedChars) {
|
||||||
|
@ -254,18 +256,13 @@ class LocationCtxContainer extends LocationCtx {
|
||||||
}
|
}
|
||||||
|
|
||||||
private int[] computeLineOffsets() {
|
private int[] computeLineOffsets() {
|
||||||
ArrayList<Integer> offsets= new ArrayList<Integer>();
|
|
||||||
final int len= fSource.getLength();
|
final int len= fSource.getLength();
|
||||||
|
IntArray offsets= new IntArray(len / 10); // Assuming 10 characters per line on average.
|
||||||
for (int i = 0; i < len; i++) {
|
for (int i = 0; i < len; i++) {
|
||||||
if (fSource.get(i) == '\n') {
|
if (fSource.get(i) == '\n')
|
||||||
offsets.add(new Integer(i));
|
offsets.add(i);
|
||||||
}
|
}
|
||||||
}
|
return offsets.toArray();
|
||||||
int[] result= new int[offsets.size()];
|
|
||||||
for (int i = 0; i < result.length; i++) {
|
|
||||||
result[i]= offsets.get(i).intValue();
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Add table
Reference in a new issue