Browse Source

Order command in list

 + XXX The pattern matching case used is not exhaustive, will be fixed
 later.
 + Before, it was assumed that entries were ordered, which is yet the case.
 However, it is safer and more scalable this way.
 + The performance loss is not significant.

For instance, without ordering (i.e. with preceding commit), it takes roughly 4,49
seconds to list more than 9500 commands (output sent to /dev/null), whereas now
it takes 4,58 seconds.
Leo 9 years ago
parent
commit
cd456e78d7
1 changed files with 6 additions and 1 deletions
  1. 6 1
      src/list_rc.ml

+ 6 - 1
src/list_rc.ml

@@ -72,7 +72,6 @@ let truncate ?elength str =
 
 (* Generate list to feed the table, returning list of tuples
  * (number of a command in rc file, command, number of launch). *)
-(* XXX assuming all will be in the right order (from id 0 to 10) *)
 (* FIXME Remove ?rc or use it *)
 let generate_list ?rc ?elength log =
   let rc_numbered =
@@ -88,6 +87,12 @@ let generate_list ?rc ?elength log =
       truncate ?elength cmd;
       (Int.to_string number)
     ])
+  (* Make sure all will be in the right order (from id 0 to 10, for instance) *)
+  |> List.sort ~cmp:(fun entry1 entry2 ->
+     match entry1, entry2 with
+     | [ id1; _; _ ], [ id2; _; _ ] ->
+         Int.(compare (int_of_string id1) (int_of_string id2))
+     )
 ;;
 
 (* Function which list, rc would be automatically reread, this optional