Bug 145271

Summary: "if" check in PDOMSearchRe sult.computeContainedMatches() should be pulled into the outer loop.
Product: [Tools] CDT Reporter: Neeraj Bhope <neerajbhope>
Component: cdt-coreAssignee: Doug Schaefer <cdtdoug>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: recoskie
Version: 3.1Keywords: contributed
Target Milestone: 3.1.1   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
The needful. bjorn.freeman-benson: iplog+

Description Neeraj Bhope CLA 2006-06-05 00:38:15 EDT
This fix should give a minor perf improvement in cases where a search results in large number of matches.

Pasting mail sent to CDT dev and Doug's reply to it.

-----------
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@eclipse.org [mailto:cdt-dev-bounces@eclipse.org] On Behalf Of Neeraj U Bhope
Sent: Friday, June 02, 2006 5:56 AM
To: cdt-dev@eclipse.org
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()]); 
        } 
-------------
Comment 1 Neeraj Bhope CLA 2006-06-05 00:47:49 EDT
Created attachment 43430 [details]
The needful.
Comment 2 Doug Schaefer CLA 2006-07-11 16:49:11 EDT
I'll be mucking in here so I'll take a look.
Comment 3 Doug Schaefer CLA 2006-08-02 10:42:06 EDT
I have applied the patch. Thanks!