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

Bug 336367

Summary: Extract local could pull value outside loop
Product: [Eclipse Project] JDT Reporter: John Arthorne <john.arthorne>
Component: UIAssignee: JDT-UI-Inbox <jdt-ui-inbox>
Status: CLOSED WONTFIX QA Contact:
Severity: normal    
Priority: P3    
Version: 3.7   
Target Milestone: ---   
Hardware: PC   
OS: Windows 7   
Whiteboard: stalebug

Description John Arthorne CLA 2011-02-04 10:56:48 EST
3.7 M5

Given this code:

	for (int i = 0; i < 10; i++) {
		doSomething(expensiveMethod());
	}

If I select "expensiveMethod()" and perform extract local variable I get:

	for (int i = 0; i < 10; i++) {
		String expensiveMethod = expensiveMethod();
		doSomething(expensiveMethod);
	}

However since expensiveMethod is not influenced by i, it would be more efficient as:

	String expensiveMethod = expensiveMethod();
	for (int i = 0; i < 10; i++) {
		doSomething(expensiveMethod);
	}

Note if there are calls to expensiveMethod outside the for loop, then it will correctly place the local variable outside the loop.
Comment 1 Eclipse Genie CLA 2020-02-19 20:01:48 EST
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. As such, we're closing this bug.

If you have further information on the current state of the bug, please add it and reopen this bug. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.