diff lisp/cl-seq.el @ 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 6afe991b8135
children 2d0937dc83cf
line wrap: on
line diff
--- a/lisp/cl-seq.el	Mon Mar 29 23:23:33 2010 -0500
+++ b/lisp/cl-seq.el	Thu Apr 01 20:22:50 2010 +0100
@@ -176,26 +176,6 @@
 				  (cl-check-key (pop cl-seq))))))
       cl-accum)))
 
-(defun fill (seq item &rest cl-keys)
-  "Fill the elements of SEQ with ITEM.
-Keywords supported:  :start :end
-:start and :end specify a subsequence of SEQ; see `remove*' for more
-information."
-  (cl-parsing-keywords ((:start 0) :end) ()
-    (if (listp seq)
-	(let ((p (nthcdr cl-start seq))
-	      (n (if cl-end (- cl-end cl-start) 8000000)))
-	  (while (and p (>= (setq n (1- n)) 0))
-	    (setcar p item)
-	    (setq p (cdr p))))
-      (or cl-end (setq cl-end (length seq)))
-      (if (and (= cl-start 0) (= cl-end (length seq)))
-	  (fillarray seq item)
-	(while (< cl-start cl-end)
-	  (aset seq cl-start item)
-	  (setq cl-start (1+ cl-start)))))
-    seq))
-
 (defun replace (cl-seq1 cl-seq2 &rest cl-keys)
   "Replace the elements of SEQ1 with the elements of SEQ2.
 SEQ1 is destructively modified, then returned.
@@ -670,49 +650,16 @@
 	  (if cl-from-end (setq cl-end2 cl-pos) (setq cl-start2 (1+ cl-pos))))
 	(and (< cl-start2 cl-end2) cl-pos)))))
 
-(defun sort* (cl-seq cl-pred &rest cl-keys)
-  "Sort the argument SEQUENCE according to PREDICATE.
-This is a destructive function; it reuses the storage of SEQUENCE if possible.
-Keywords supported:  :key
-:key specifies a one-argument function that transforms elements of SEQUENCE
-into \"comparison keys\" before the test predicate is applied.  See
-`member*' for more information."
-  (if (nlistp cl-seq)
-      (replace cl-seq (apply 'sort* (append cl-seq nil) cl-pred cl-keys))
-    (cl-parsing-keywords (:key) ()
-      (if (memq cl-key '(nil identity))
-	  (sort cl-seq cl-pred)
-	(sort cl-seq (function (lambda (cl-x cl-y)
-				 (funcall cl-pred (funcall cl-key cl-x)
-					  (funcall cl-key cl-y)))))))))
-
 (defun stable-sort (cl-seq cl-pred &rest cl-keys)
   "Sort the argument SEQUENCE stably according to PREDICATE.
 This is a destructive function; it reuses the storage of SEQUENCE if possible.
 Keywords supported:  :key
 :key specifies a one-argument function that transforms elements of SEQUENCE
 into \"comparison keys\" before the test predicate is applied.  See
-`member*' for more information."
-  (apply 'sort* cl-seq cl-pred cl-keys))
+`member*' for more information.
 
-(defun merge (cl-type cl-seq1 cl-seq2 cl-pred &rest cl-keys)
-  "Destructively merge the two sequences to produce a new sequence.
-TYPE is the sequence type to return, SEQ1 and SEQ2 are the two
-argument sequences, and PRED is a `less-than' predicate on the elements.
-Keywords supported:  :key
-:key specifies a one-argument function that transforms elements of SEQ1 and
-SEQ2 into \"comparison keys\" before the test predicate is applied.  See
-`member*' for more information."
-  (or (listp cl-seq1) (setq cl-seq1 (append cl-seq1 nil)))
-  (or (listp cl-seq2) (setq cl-seq2 (append cl-seq2 nil)))
-  (cl-parsing-keywords (:key) ()
-    (let ((cl-res nil))
-      (while (and cl-seq1 cl-seq2)
-	(if (funcall cl-pred (cl-check-key (car cl-seq2))
-		     (cl-check-key (car cl-seq1)))
-	    (push (pop cl-seq2) cl-res)
-	  (push (pop cl-seq1) cl-res)))
-      (coerce (nconc (nreverse cl-res) cl-seq1 cl-seq2) cl-type))))
+arguments: (SEQUENCE PREDICATE &key (KEY #'IDENTITY))"
+  (apply 'sort* cl-seq cl-pred cl-keys))
 
 ;;; See compiler macro in cl-macs.el
 (defun member* (cl-item cl-list &rest cl-keys)