You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@jakarta.apache.org by bu...@apache.org on 2012/01/05 21:29:45 UTC
DO NOT REPLY [Bug 52433] New: Why using unstable sort at
MethodGen.getLocalVariables() ?
https://issues.apache.org/bugzilla/show_bug.cgi?id=52433
Bug #: 52433
Summary: Why using unstable sort at
MethodGen.getLocalVariables() ?
Product: BCEL
Version: 5.3
Platform: PC
OS/Version: Linux
Status: NEW
Severity: enhancement
Priority: P2
Component: Main
AssignedTo: notifications@jakarta.apache.org
ReportedBy: thiagobart@gmail.com
Classification: Unclassified
I noticed that MethodGen.getLocalVariables sorts the local variables by index.
However, it uses a hand written sort algorithm that is unstable. That is, it
does not guarantee that variables with the same index are kept in the same
order. In fact, it always swaps them.
This does not cause a major problem apart from having a different order of
variables in the local variables table when a class is simply parsed and
dumped.
A simple enhancement is to use java's own merge sort implementation (available
in version 1.3, which seems to be the target platform). In getLocalVariables(),
instead of calling:
sort(lg, 0, size - 1);
use something like (maybe remove generics):
Arrays.sort(lg, new Comparator<LocalVariableGen>() {
public int compare(LocalVariableGen o1, LocalVariableGen o2) {
return o1.getIndex() - o2.getIndex();
}
});
The advantage, besides using a stable sort, is that this is less code to
maintain, compared to the trick sort method.
--
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@jakarta.apache.org
For additional commands, e-mail: notifications-help@jakarta.apache.org
DO NOT REPLY [Bug 52433] Why using unstable sort at
MethodGen.getLocalVariables() ?
Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=52433
--- Comment #1 from Torsten Curdt <tc...@apache.org> 2012-02-04 19:55:02 UTC ---
Indeed. Good suggestion.
--
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@jakarta.apache.org
For additional commands, e-mail: notifications-help@jakarta.apache.org