What about a pure Ruby implementation like this:

```ruby
sort_order.sort!{|x,y| @all_desktops[x]["order"] <=> @all_desktops[y]["order"] }
```

Could you try it? Would that work as expected? That would even avoid the `deep_copy` used in the builtin...