diff src/keymap.c @ 5182:2e528066e2fc

Move #'sort*, #'fill, #'merge to C from cl-seq.el. lisp/ChangeLog addition: 2010-04-01 Aidan Kehoe <kehoea@parhasard.net> * cl-seq.el (fill, sort*, merge): Move these functions to fns.c. (stable-sort): Make this docstring reflect the argument names used in the #'sort* docstring. * cl-macs.el (stable-sort): Make #'stable-sort exactly equivalent to #'sort* in compiled code. * bytecomp.el (byte-compile-maybe-add-*): New macro, for functions like #'sort and #'mapcar that, to be strictly compatible, should only take two args, but in our implementation can take more, because they're aliases of #'sort* and #'mapcar*. (byte-compile-mapcar, byte-compile-sort, byte-compile-fillarray): Use this new macro. (map-into): Add a byte-compile method for #'map-into in passing. * apropos.el (apropos-print): Use #'sort* with a :key argument, now it's in C. * compat.el (extent-at): Ditto. * register.el (list-registers): Ditto. * package-ui.el (pui-list-packages): Ditto. * help.el (sorted-key-descriptions): Ditto. src/ChangeLog addition: 2010-03-31 Aidan Kehoe <kehoea@parhasard.net> * fns.c (STRING_DATA_TO_OBJECT_ARRAY) (BIT_VECTOR_TO_OBJECT_ARRAY, c_merge_predicate_key) (c_merge_predicate_nokey, list_merge, array_merge) (list_array_merge_into_list, list_list_merge_into_array) (list_array_merge_into_array, CHECK_KEY_ARGUMENT, Fmerge) (list_sort, array_sort, FsortX): Move #'sort*, #'fill, #'merge from cl-seq.el to C, extending the implementations of Fsort, Ffillarray, and merge() to do so. * keymap.c (keymap_submaps, map_keymap_sort_predicate) (describe_map_sort_predicate): Change the calling semantics of the C sort predicates to return a non-nil Lisp object if the first argument is less than the second, rather than C integers. * fontcolor-msw.c (sort_font_list_function): * fileio.c (build_annotations): * dired.c (Fdirectory_files): * abbrev.c (Finsert_abbrev_table_description): Call list_sort instead of Fsort, list_merge instead of merge() in these functions. man/ChangeLog addition: 2010-04-01 Aidan Kehoe <kehoea@parhasard.net> * lispref/lists.texi (Rearrangement): Update the documentation of #'sort here, now that it accepts any type of sequence and the KEY keyword argument. (Though this is probably now the wrong place for this function, given that.)
author Aidan Kehoe <kehoea@parhasard.net>
date Thu, 01 Apr 2010 20:22:50 +0100
parents 88bd4f3ef8e4
children f283b08ff0c9
line wrap: on
line diff
--- a/src/keymap.c	Mon Mar 29 23:23:33 2010 -0500
+++ b/src/keymap.c	Thu Apr 01 20:22:50 2010 +0100
@@ -737,8 +737,10 @@
   return 0;
 }
 
-static int map_keymap_sort_predicate (Lisp_Object obj1, Lisp_Object obj2,
-                                      Lisp_Object pred);
+static Lisp_Object map_keymap_sort_predicate (Lisp_Object obj1,
+                                              Lisp_Object obj2,
+                                              Lisp_Object pred,
+                                              Lisp_Object key_func);
 
 static Lisp_Object
 keymap_submaps (Lisp_Object keymap)
@@ -761,9 +763,8 @@
       elisp_maphash (keymap_submaps_mapper, k->table,
 		     &keymap_submaps_closure);
       /* keep it sorted so that the result of accessible-keymaps is ordered */
-      k->sub_maps_cache = list_sort (result,
-				     Qnil,
-				     map_keymap_sort_predicate);
+      k->sub_maps_cache = list_sort (result, map_keymap_sort_predicate,
+                                     Qnil, Qidentity);
       UNGCPRO;
     }
   return k->sub_maps_cache;
@@ -2889,9 +2890,10 @@
 /* used by map_keymap_sorted(), describe_map_sort_predicate(),
    and keymap_submaps().
  */
-static int
+static Lisp_Object
 map_keymap_sort_predicate (Lisp_Object obj1, Lisp_Object obj2,
-                           Lisp_Object UNUSED (pred))
+                           Lisp_Object UNUSED (pred),
+                           Lisp_Object UNUSED (key_func))
 {
   /* obj1 and obj2 are conses with keysyms in their cars.  Cdrs are ignored.
    */
@@ -2904,7 +2906,7 @@
   obj2 = XCAR (obj2);
 
   if (EQ (obj1, obj2))
-    return -1;
+    return Qnil;
   bit1 = MODIFIER_HASH_KEY_BITS (obj1);
   bit2 = MODIFIER_HASH_KEY_BITS (obj2);
 
@@ -2934,7 +2936,7 @@
 
   /* all symbols (non-ASCIIs) come after characters (ASCIIs) */
   if (XTYPE (obj1) != XTYPE (obj2))
-    return SYMBOLP (obj2) ? 1 : -1;
+    return SYMBOLP (obj2) ? Qt : Qnil;
 
   if (! bit1 && CHARP (obj1)) /* they're both ASCII */
     {
@@ -2942,24 +2944,24 @@
       int o2 = XCHAR (obj2);
       if (o1 == o2 &&		/* If one started out as a symbol and the */
 	  sym1_p != sym2_p)	/* other didn't, the symbol comes last. */
-	return sym2_p ? 1 : -1;
-
-      return o1 < o2 ? 1 : -1;	/* else just compare them */
+	return sym2_p ? Qt : Qnil;
+
+      return o1 < o2 ? Qt : Qnil;	/* else just compare them */
     }
 
   /* else they're both symbols.  If they're both buckys, then order them. */
   if (bit1 && bit2)
-    return bit1 < bit2 ? 1 : -1;
+    return bit1 < bit2 ? Qt : Qnil;
 
   /* if only one is a bucky, then it comes later */
   if (bit1 || bit2)
-    return bit2 ? 1 : -1;
+    return bit2 ? Qt : Qnil;
 
   /* otherwise, string-sort them. */
   {
     Ibyte *s1 = XSTRING_DATA (XSYMBOL (obj1)->name);
     Ibyte *s2 = XSTRING_DATA (XSYMBOL (obj2)->name);
-    return 0 > qxestrcmp (s1, s2) ? 1 : -1;
+    return 0 > qxestrcmp (s1, s2) ? Qt : Qnil;
   }
 }
 
@@ -2987,7 +2989,7 @@
     c1.result_locative = &contents;
     elisp_maphash (map_keymap_sorted_mapper, keymap_table, &c1);
   }
-  contents = list_sort (contents, Qnil, map_keymap_sort_predicate);
+  contents = list_sort (contents, map_keymap_sort_predicate, Qnil, Qidentity);
   for (; !NILP (contents); contents = XCDR (contents))
     {
       Lisp_Object keysym = XCAR (XCAR (contents));
@@ -4080,9 +4082,9 @@
 }
 
 
-static int
+static Lisp_Object
 describe_map_sort_predicate (Lisp_Object obj1, Lisp_Object obj2,
-			     Lisp_Object pred)
+			     Lisp_Object pred, Lisp_Object key_func)
 {
   /* obj1 and obj2 are conses of the form
      ( ( <keysym> . <modifiers> ) . <binding> )
@@ -4094,9 +4096,9 @@
   bit1 = XINT (XCDR (obj1));
   bit2 = XINT (XCDR (obj2));
   if (bit1 != bit2)
-    return bit1 < bit2 ? 1 : -1;
+    return bit1 < bit2 ? Qt : Qnil;
   else
-    return map_keymap_sort_predicate (obj1, obj2, pred);
+    return map_keymap_sort_predicate (obj1, obj2, pred, key_func);
 }
 
 /* Elide 2 or more consecutive numeric keysyms bound to the same thing,
@@ -4204,7 +4206,7 @@
 
   if (!NILP (list))
     {
-      list = list_sort (list, Qnil, describe_map_sort_predicate);
+      list = list_sort (list, describe_map_sort_predicate, Qnil, Qidentity);
       buffer_insert_ascstring (buf, "\n");
       while (!NILP (list))
 	{