Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 359360 - Micro-optimization : don't call consumedComponent.getRootFolder() twice in FlatVirtualComponent.consumeComponent(...)
Summary: Micro-optimization : don't call consumedComponent.getRootFolder() twice in Fl...
Status: RESOLVED FIXED
Alias: None
Product: WTP Common Tools
Classification: WebTools
Component: wst.common (show other bugs)
Version: unspecified   Edit
Hardware: PC Linux
: P3 minor (vote)
Target Milestone: 3.4 M5   Edit
Assignee: Rob Stryker CLA
QA Contact: Carl Anderson CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-09-29 03:59 EDT by Fred Bricon CLA
Modified: 2012-01-18 02:32 EST (History)
2 users (show)

See Also:


Attachments
Micro-optipatch ;) (1.44 KB, patch)
2012-01-17 04:15 EST, Rob Stryker CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Fred Bricon CLA 2011-09-29 03:59:37 EDT
Build Identifier: 20110916-0149

m2e-wtp uses a custom IVirtualComponent, OverlayVirtualComponent, to handle War Overlays à-la-Maven. 
OverlayVirtualComponent.getRootFolder() method is somewhat slow, as it treewalks the overlay graph to build it's resource tree -It may be a BAD thing, but that's not really the point-. However, I see that getRootFolder() method is called way more than necessary.

Turns out the current FlatVirtualComponent.consumeComponent(...) calls it twice, as you can see :

protected void consumeComponent(VirtualComponentFlattenUtility util, IPath root, IVirtualReference reference) throws CoreException {
  IVirtualComponent consumedComponent = reference.getReferencedComponent();
  if (consumedComponent.getRootFolder()!=null) {
    IVirtualFolder vFolder = consumedComponent.getRootFolder();
    util.addMembers(consumedComponent, vFolder, root.append(reference.getRuntimePath().makeRelative()));
    addConsumedReferences(util, consumedComponent, root.append(reference.getRuntimePath().makeRelative()));
    addUsedReferences(util, consumedComponent, root.append(reference.getRuntimePath().makeRelative()));
  }
}

I think it can safely be refactored to : 
protected void consumeComponent(VirtualComponentFlattenUtility util, IPath root, IVirtualReference reference) throws CoreException {
  IVirtualComponent consumedComponent = reference.getReferencedComponent();
  IVirtualFolder vFolder = consumedComponent.getRootFolder();
  if (vFolder!=null) {
    util.addMembers(consumedComponent, vFolder, root.append(reference.getRuntimePath().makeRelative()));
    addConsumedReferences(util, consumedComponent, root.append(reference.getRuntimePath().makeRelative()));
    addUsedReferences(util, consumedComponent, root.append(reference.getRuntimePath().makeRelative()));
  }
}


Reproducible: Always
Comment 1 Rob Stryker CLA 2012-01-17 04:15:58 EST
Created attachment 209606 [details]
Micro-optipatch ;)

Patch as per the comments by fred
Comment 2 Chuck Bridgham CLA 2012-01-17 14:26:07 EST
I like the change - thanks!
Comment 3 Rob Stryker CLA 2012-01-18 02:32:57 EST
Committed and released to head and 3.3.2