1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Partial fix for Bug 90525 - [DOM AST] LocationMap search methods require optimization

This commit is contained in:
John Camelon 2005-04-12 20:58:19 +00:00
parent 9efdb0e7d9
commit 5553a5da68

View file

@ -974,10 +974,8 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
return parent; return parent;
} }
public boolean contains(int offset) { public final boolean contains(int offset) {
if (offset >= context_directive_start && offset <= context_ends) return (offset >= context_directive_start && offset <= context_ends);
return true;
return false;
} }
public boolean containsInDirective(int offset, int length) { public boolean containsInDirective(int offset, int length) {
@ -1057,28 +1055,65 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
public _Context findContextContainingOffset(int offset) { public _Context findContextContainingOffset(int offset) {
if (!hasSubContexts()) { if (!hasSubContexts()) {
if (contains(offset)) if (offset >= context_directive_start && offset <= context_ends)
return this; return this;
return null; return null;
} }
_Context[] l = getSubContexts(); _Context[] l = getSubContexts();
for (int i = 0; i < l.length; ++i) { int low = 0;
_Context c = l[i]; int high = l.length-1;
if (c.contains(offset)) {
if (c instanceof _CompositeContext) { while (low <= high) {
_Context trial = ((_CompositeContext) c) int mid = (low + high) >> 1;
.findContextContainingOffset(offset); _Context midVal = l[mid];
if (trial == null) int cmp;
if( (offset >= midVal.context_directive_start && offset <= midVal.context_ends) )
cmp = 0;
else if( midVal.context_directive_start > offset )
cmp = 1;
else
cmp = -1;
if (cmp < 0)
low = mid + 1;
else if (cmp > 0)
high = mid - 1;
else
{
if( midVal instanceof _CompositeContext )
{
_Context c = ((_CompositeContext)midVal).findContextContainingOffset(offset);
if( c != null )
return c; return c;
return trial;
} }
return c; return midVal;
} }
} }
if (contains(offset)) if (offset >= context_directive_start && offset <= context_ends)
return this; return this;
return null; return null;
// for (int i = 0; i < l.length; ++i) {
// _Context c = l[i];
// if (c.contains(offset)) {
// if (c instanceof _CompositeContext) {
// _Context trial = ((_CompositeContext) c)
// .findContextContainingOffset(offset);
// if (trial == null)
// return c;
// return trial;
// }
// return c;
// }
// }
//if no sub context contains this, do it this way
// if (contains(offset))
// return this;
// return null;
} }
public int getNumberOfContexts() { public int getNumberOfContexts() {
final _Context[] contextz = getSubContexts(); final _Context[] contextz = getSubContexts();
@ -1090,7 +1125,7 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
return result; return result;
} }
} }
protected static class _CompositeFileContext extends _CompositeContext { protected static class _CompositeFileContext extends _CompositeContext {
public CodeReader reader; public CodeReader reader;
@ -1586,7 +1621,8 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
if (tu == null) if (tu == null)
return EMPTY_LOCATION_ARRAY; return EMPTY_LOCATION_ARRAY;
_Context c = findContextForOffset(offset); _Context c = findContextForOffset(offset);
if (c.contains(offset + length)) { int offset1 = offset + length;
if ((offset1 >= c.context_directive_start && offset1 <= c.context_ends)) {
if (c instanceof _CompositeContext) { if (c instanceof _CompositeContext) {
_Context[] subz = ((_CompositeContext) c).getSubContexts(); _Context[] subz = ((_CompositeContext) c).getSubContexts();
boolean foundNested = false; boolean foundNested = false;