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:
parent
9efdb0e7d9
commit
5553a5da68
1 changed files with 53 additions and 17 deletions
|
@ -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,29 +1055,66 @@ 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();
|
||||||
int result = contextz.length;
|
int result = contextz.length;
|
||||||
|
@ -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;
|
||||||
|
|
Loading…
Add table
Reference in a new issue