Index: devel.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/devel/devel.module,v
retrieving revision 1.363
diff -u -r1.363 devel.module
--- devel.module	14 Oct 2009 14:44:26 -0000	1.363
+++ devel.module	16 Oct 2009 18:02:31 -0000
@@ -647,7 +647,8 @@
       $users = db_query_range("SELECT DISTINCT u.uid, u.name, u.access FROM {users} u LEFT JOIN {users_roles} r ON u.uid = r.uid WHERE $where_sql ORDER BY u.access DESC", 0, $list_size);
     }
     foreach ($users as $user) {
-      $links[$user->uid] = array(
+      $uids[] = $user->uid;
+      $links[$user->access][$user->uid] = array(
         'title' => theme('placeholder', $user->name),
         'href' => 'devel/switch/'. $user->name,
         'query' => $dest,
@@ -658,12 +659,12 @@
     $num_links = count($links);
     if ($num_links < $list_size) {
       // If we don't have enough, add distinct uids until we hit $list_size.
-      $users = db_query_range('SELECT uid, name, access FROM {users} WHERE uid > 0 AND uid NOT IN ('. implode(',', array_keys($links)) .') ORDER BY access DESC', 0, $list_size - $num_links);
+      $users = db_query_range('SELECT uid, name, access FROM {users} WHERE uid > 0 AND uid NOT IN ('. implode(',', $uids) .') ORDER BY access DESC', 0, $list_size - $num_links);
       foreach ($users as $user) {
         if (count($links) >= $list_size) {
           break;
         }
-        $links[$user->uid] = array(
+        $links[$user->access][$user->uid] = array(
           'title' => $user->name ? $user->name : 'anon',
           'href' => 'devel/switch/'. $user->name,
           'query' => $dest,
@@ -671,8 +672,14 @@
         );
       }
     }
+    krsort($links);
+    foreach ($links as $link_by_uid) {
+      foreach ($link_by_uid as $uid => $link) {
+        $sorted_links[$uid] = $link;
+      }
+    }
   }
-  return $links;
+  return $sorted_links;
 }
 
 function devel_phpinfo() {
