Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 336367 - Extract local could pull value outside loop
Summary: Extract local could pull value outside loop
Status: CLOSED WONTFIX
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.7   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: JDT-UI-Inbox CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
Depends on:
Blocks:
 
Reported: 2011-02-04 10:56 EST by John Arthorne CLA
Modified: 2020-02-19 20:01 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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.