There is a more efficient way to sort results from listbuilder.
Use the procedure template::list::orderby_clause to generate an order by clause to add to a query.
Most instances just call the procedure directly from the XQL file in the query text.
So you would have
select * from my_table
[template::list::orderby_clause -name my_list -orderby]
as your query.
I suspect this will be much faster than sorting the rows with lsort in tcl.
It also simplifies your code as you don't have to check for asc/desc at all.
I am pretty sure this has been addressed before in the forums. Now, if your multirow is not generated from the database, it looks like a good solution.