Stable sort because we really ought to avoid normal sort if we want
reproducible builds, and a Schwartzian transform because we sometimes
sort with fairly computation-heavy sort keys. Better have that to
make it easy to DTRT.
"SCALE-DOUBLE-FLOAT"
#!+long-float "SCALE-LONG-FLOAT"
"SCALE-SINGLE-FLOAT"
+ "SCHWARTZIAN-STABLE-SORT-LIST"
"SCRUB-POWER-CACHE"
"SEQUENCEP" "SEQUENCE-COUNT" "SEQUENCE-END"
"SEQUENCE-OF-CHECKED-LENGTH-GIVEN-TYPE"
(list (list :line lineno)
(list :column colno)
(list :file-position pos)))))))
+
+(declaim (inline schwartzian-stable-sort-list))
+(defun schwartzian-stable-sort-list (list comparator &key key)
+ (if (null key)
+ (stable-sort (copy-list list) comparator)
+ (let* ((key (if (functionp key)
+ key
+ (symbol-function key)))
+ (wrapped (mapcar (lambda (x)
+ (cons x (funcall key x)))
+ list))
+ (sorted (stable-sort wrapped comparator :key #'cdr)))
+ (map-into sorted #'car sorted))))