1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-08 10:16:03 +02:00

Optimizes C/C++ search without wild-cards, bug 272688

This commit is contained in:
Markus Schorn 2009-04-17 13:43:09 +00:00
parent dde5816f8e
commit c507baf019
3 changed files with 70 additions and 7 deletions

View file

@ -515,6 +515,21 @@ public class PDOM extends PlatformObject implements IPDOM {
if (monitor == null) { if (monitor == null) {
monitor= new NullProgressMonitor(); monitor= new NullProgressMonitor();
} }
// check for some easy cases
char[][] simpleNames= extractSimpleNames(pattern);
if (simpleNames != null) {
if (simpleNames.length == 1) {
return findBindings(simpleNames[0], isFullyQualified, filter, monitor);
} else if (isFullyQualified) {
return findBindings(simpleNames, filter, monitor);
}
}
char[] prefix= extractPrefix(pattern);
if (prefix != null) {
return findBindingsForPrefix(prefix, isFullyQualified, filter, monitor);
}
BindingFinder finder = new BindingFinder(pattern, isFullyQualified, filter, monitor); BindingFinder finder = new BindingFinder(pattern, isFullyQualified, filter, monitor);
for (PDOMLinkage linkage : getLinkageList()) { for (PDOMLinkage linkage : getLinkageList()) {
if (filter.acceptLinkage(linkage)) { if (filter.acceptLinkage(linkage)) {
@ -531,6 +546,38 @@ public class PDOM extends PlatformObject implements IPDOM {
return finder.getBindings(); return finder.getBindings();
} }
private char[][] extractSimpleNames(Pattern[] pattern) {
char[][] result= new char[pattern.length][];
int i= 0;
for (Pattern p : pattern) {
char[] input= p.pattern().toCharArray();
for (char c : input) {
if (!Character.isLetterOrDigit(c) && c != '_') {
return null;
}
}
result[i++]= input;
}
return result;
}
private char[] extractPrefix(Pattern[] pattern) {
if (pattern.length != 1)
return null;
String p= pattern[0].pattern();
if (p.endsWith(".*")) { //$NON-NLS-1$
char[] input= p.substring(0, p.length()-2).toCharArray();
for (char c : input) {
if (!Character.isLetterOrDigit(c) && c != '_') {
return null;
}
}
return input;
}
return null;
}
public IIndexFragmentBinding[] findMacroContainers(Pattern pattern, IndexFilter filter, IProgressMonitor monitor) throws CoreException { public IIndexFragmentBinding[] findMacroContainers(Pattern pattern, IndexFilter filter, IProgressMonitor monitor) throws CoreException {
if (monitor == null) { if (monitor == null) {
monitor= new NullProgressMonitor(); monitor= new NullProgressMonitor();

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2006, 2008 QNX Software Systems and others. * Copyright (c) 2006, 2009 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -34,6 +34,8 @@ import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener; import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.VerifyEvent;
import org.eclipse.swt.events.VerifyListener;
import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Button;
@ -340,10 +342,25 @@ public class PDOMSearchPage extends DialogPage implements ISearchPage {
// Pattern combo // Pattern combo
patternCombo = new Combo( result, SWT.SINGLE | SWT.BORDER ); patternCombo = new Combo( result, SWT.SINGLE | SWT.BORDER );
patternCombo.addSelectionListener( new SelectionAdapter() { patternCombo.addVerifyListener(new VerifyListener() {
@Override public void verifyText(VerifyEvent e) {
public void widgetSelected( SelectionEvent e ) { char[] chars= e.text.toCharArray();
//handlePatternSelected(); StringBuilder result= new StringBuilder(chars.length);
for (char c : chars) {
switch (c) {
case '_':
case ':': // scope operator
case '?': case '*': // wild cards
result.append(c);
break;
default:
if (Character.isLetterOrDigit(c)) {
result.append(c);
}
break;
}
e.text= result.toString();
}
} }
}); });

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2006, 2008 QNX Software Systems and others. * Copyright (c) 2006, 2009 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -96,7 +96,6 @@ public class PDOMSearchPatternQuery extends PDOMSearchQuery {
case '?': case '?':
buff.append('.'); buff.append('.');
break; break;
case '.':
case ':': case ':':
if (buff.length() > 0) { if (buff.length() > 0) {
if (isCaseSensitive) if (isCaseSensitive)