Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
RE: [cdt-dev] Pulling an if check out of the loop in PDOMSearchRe sult.computeContainedMatches()

Maybe. This code was written before I made the elements include the filename. Feel free to raise a bug.

 

Doug Schaefer, QNX Software Systems

Eclipse CDT Project Lead, Tools PMC member

http://cdtdoug.blogspot.com

 


From: cdt-dev-bounces@xxxxxxxxxxx [mailto:cdt-dev-bounces@xxxxxxxxxxx] On Behalf Of Neeraj U Bhope
Sent: Friday, June 02, 2006 5:56 AM
To: cdt-dev@xxxxxxxxxxx
Subject: [cdt-dev] Pulling an if check out of the loop in PDOMSearchResult.computeContainedMatches()

 


In the following piece of code, could the "if (filename.equals(mfilename))" check be moved out into the outer loop using
((PDOMSearchElement) elements[i]).getFileName() to populate mfileName? The inner loop would then be entered only for the required file? If not why not?

        private Match[] computeContainedMatches(AbstractTextSearchResult result, String filename) throws CoreException {
                List list = new ArrayList();
                Object[] elements = result.getElements();
                for (int i = 0; i < elements.length; ++i) {
                        Match[] matches = result.getMatches(elements[i]);
                        for (int j = 0; j < matches.length; ++j) {
                                if (matches[j] instanceof PDOMSearchMatch) {
                                        String mfilename = ((PDOMSearchMatch)matches[j]).getFileName();
                                        if (filename.equals(mfilename))
                                                list.add(matches[j]);
                                }
                        }
                }
                return (Match[])list.toArray(new Match[list.size()]);
        }
--
neeraj


Back to the top