mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Patch for David Daoust.
ArrayUtil.removeNulls() optimizations and LocationMap algorithm updates.
This commit is contained in:
parent
d4eb543b1c
commit
680530305f
2 changed files with 36 additions and 67 deletions
|
@ -202,16 +202,22 @@ public class ArrayUtil {
|
|||
if( array == null )
|
||||
return (Object[]) Array.newInstance( c, 0 );
|
||||
|
||||
int i = 0;
|
||||
int i;
|
||||
int validEntries = 0;
|
||||
for( i = 0; i < array.length; i++ ){
|
||||
if( array[i] != null ) validEntries++;
|
||||
}
|
||||
|
||||
if (array.length == validEntries)
|
||||
return array;
|
||||
|
||||
Object[] newArray = (Object[]) Array.newInstance(c, validEntries);
|
||||
int j = 0;
|
||||
Object[] newArray = new Object[array.length];
|
||||
for( ; i < array.length; i++ ){
|
||||
for( i = 0; i < array.length; i++ ){
|
||||
if( array[i] != null ) newArray[j++] = array[i];
|
||||
}
|
||||
|
||||
if (j<i) return ArrayUtil.trim(c, newArray);
|
||||
|
||||
return array;
|
||||
return newArray;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1047,11 +1047,11 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
|||
}
|
||||
|
||||
public void removeSubContext(_Context c) {
|
||||
_Context[] sub = getSubContexts();
|
||||
for (int i = 0; i < sub.length; ++i)
|
||||
if (sub[i] == c) {
|
||||
sub[i] = null;
|
||||
trimSubContexts();
|
||||
if (subContexts == null)
|
||||
return;
|
||||
for (int i = 0; i < subContexts.length; ++i)
|
||||
if (subContexts[i] == c) {
|
||||
subContexts[i] = null;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -1069,64 +1069,27 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
|||
}
|
||||
|
||||
public _Context findContextContainingOffset(int offset) {
|
||||
if (!hasSubContexts()) {
|
||||
if (offset >= context_directive_start && offset <= context_ends)
|
||||
return this;
|
||||
return null;
|
||||
if (subContexts != null)
|
||||
{
|
||||
for (int i = 0; i < subContexts.length; ++i) {
|
||||
_Context c = subContexts[i];
|
||||
if (c == null) continue;
|
||||
if ((offset >= c.context_directive_start && offset <= c.context_ends)) {
|
||||
if (c instanceof _CompositeContext) {
|
||||
_Context trial = ((_CompositeContext) c)
|
||||
.findContextContainingOffset(offset);
|
||||
if (trial == null)
|
||||
return c;
|
||||
return trial;
|
||||
}
|
||||
return c;
|
||||
}
|
||||
}
|
||||
}
|
||||
_Context[] l = getSubContexts();
|
||||
int low = 0;
|
||||
int high = l.length-1;
|
||||
|
||||
while (low <= high) {
|
||||
int mid = (low + high) >> 1;
|
||||
_Context midVal = l[mid];
|
||||
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 midVal;
|
||||
}
|
||||
}
|
||||
if (offset >= context_directive_start && offset <= context_ends)
|
||||
// if no sub context contains this, do it this way
|
||||
if ((offset >= context_directive_start && offset <= context_ends))
|
||||
return this;
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
@ -2347,7 +2310,7 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
|||
// check if a sub node of the macro is the selection // TODO
|
||||
// determine how this can be kept in sync with logic in
|
||||
// getAllPreprocessorStatements (i.e. 1:1 mapping)
|
||||
if (context.contains( globalOffset ) && context instanceof _MacroDefinition) {
|
||||
if ((globalOffset >= context.context_directive_start && globalOffset <= context.context_ends) && context instanceof _MacroDefinition) {
|
||||
if (globalOffset == ((_MacroDefinition) context).nameOffset
|
||||
&& length == ((_MacroDefinition) context).name.length)
|
||||
result = createASTMacroDefinition(
|
||||
|
|
Loading…
Add table
Reference in a new issue