[ 
https://issues.apache.org/jira/browse/BCEL-160?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Emmanuel Bourg updated BCEL-160:
--------------------------------

         Priority: Blocker
    Fix Version/s: 6.0

> Why using unstable sort at MethodGen.getLocalVariables() ?
> ----------------------------------------------------------
>
>                 Key: BCEL-160
>                 URL: https://issues.apache.org/jira/browse/BCEL-160
>             Project: Commons BCEL
>          Issue Type: Improvement
>          Components: Main
>    Affects Versions: 5.3
>         Environment: Operating System: Linux
> Platform: PC
>            Reporter: Thiago
>            Assignee: Apache Commons Developers
>            Priority: Blocker
>             Fix For: 6.0
>
>
> 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.



--
This message was sent by Atlassian JIRA
(v6.2#6252)

Reply via email to