Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 359360

Summary: Micro-optimization : don't call consumedComponent.getRootFolder() twice in FlatVirtualComponent.consumeComponent(...)
Product: [WebTools] WTP Common Tools Reporter: Fred Bricon <fbricon>
Component: wst.commonAssignee: Rob Stryker <stryker>
Status: RESOLVED FIXED QA Contact: Carl Anderson <ccc>
Severity: minor    
Priority: P3 CC: cbridgha, stryker
Version: unspecified   
Target Milestone: 3.4 M5   
Hardware: PC   
OS: Linux   
Whiteboard:
Attachments:
Description Flags
Micro-optipatch ;) none

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