Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[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