magento/magento2 — pull request #49 by IvanChepurnyi (2012-07-24 17:25:29+00:00)
Title: Fix of wrong ordering logic for totals

During custom development, there were discovered a bug with ordering process.

If you create custom total like this one:
```xml

Full_Total_Class_Name
shipping
tax

Full_Total_Class_Name
tax_shipping
tax

```
It will not be placed between tax and tax_shipping totals, the actual result was like the following:
```
Array
(
[0] => nominal
[1] => subtotal
[2] => tax_subtotal
[6] => freeshipping
[7] => handling_tax
[8] => handling
[9] => weee
[10] => shipping
[11] => tax_shipping
[12] => discount
[14] => tax
[17] => grand_total
[19] => msrp
)
```
The problem itself in sorting method that were used. Since only close items were compared to each other and if you have total that is not next to desired one, its before and after attributes get ignored.

Apparently this commit not only fixes an issue with sorting, it also works 3 times faster then current method in core. The test was done on 1000 iteration five times and average results are the following:
* Current core functionality 0.83539700508118 seconds
* Patched functionality 0.26063299179077 seconds