Author: gabor Date: Wed Jul 4 16:25:11 2012 New Revision: 238108 URL: http://svn.freebsd.org/changeset/base/238108
Log: - Change --nthreads parameter to --parallel for GNU compatibility - Change default sort method to mergesort, which has a better worst case performance than qsort Submitted by: Oleg Moskalenko <oleg.moskale...@citrix.com> Modified: head/usr.bin/sort/file.c head/usr.bin/sort/file.h head/usr.bin/sort/radixsort.c head/usr.bin/sort/sort.1.in head/usr.bin/sort/sort.c Modified: head/usr.bin/sort/file.c ============================================================================== --- head/usr.bin/sort/file.c Wed Jul 4 14:25:14 2012 (r238107) +++ head/usr.bin/sort/file.c Wed Jul 4 16:25:11 2012 (r238108) @@ -1297,7 +1297,7 @@ sort_list_to_file(struct sort_list *list } if (sort_opts_vals.sort_method == SORT_DEFAULT) - sort_opts_vals.sort_method = SORT_QSORT; + sort_opts_vals.sort_method = DEFAULT_SORT_ALGORITHM; if (debug_sort) printf("sort_method=%s\n", @@ -1314,9 +1314,12 @@ sort_list_to_file(struct sort_list *list case SORT_HEAPSORT: mt_sort(list, heapsort, outfile); break; - default: + case SORT_QSORT: mt_sort(list, sort_qsort, outfile); break; + default: + mt_sort(list, DEFAULT_SORT_FUNC, outfile); + break; } } Modified: head/usr.bin/sort/file.h ============================================================================== --- head/usr.bin/sort/file.h Wed Jul 4 14:25:14 2012 (r238107) +++ head/usr.bin/sort/file.h Wed Jul 4 16:25:11 2012 (r238108) @@ -39,6 +39,9 @@ #define SORT_HEAPSORT 3 #define SORT_RADIXSORT 4 +#define DEFAULT_SORT_ALGORITHM SORT_HEAPSORT +#define DEFAULT_SORT_FUNC heapsort + /* * List of data to be sorted. */ Modified: head/usr.bin/sort/radixsort.c ============================================================================== --- head/usr.bin/sort/radixsort.c Wed Jul 4 14:25:14 2012 (r238107) +++ head/usr.bin/sort/radixsort.c Wed Jul 4 16:25:11 2012 (r238108) @@ -45,6 +45,8 @@ __FBSDID("$FreeBSD$"); #include "coll.h" #include "radixsort.h" +#define DEFAULT_SORT_FUNC_RADIXSORT mergesort + #define TINY_NODE(sl) ((sl)->tosort_num < 65) #define SMALL_NODE(sl) ((sl)->tosort_num < 5) @@ -349,7 +351,7 @@ run_sort_level_next(struct sort_level *s /* NOTREACHED */ err(2, "Radix sort error 3"); } else - qsort(sl->leaves, sl->leaves_num, + DEFAULT_SORT_FUNC_RADIXSORT(sl->leaves, sl->leaves_num, sizeof(struct sort_list_item *), (int(*)(const void *, const void *)) func); @@ -389,12 +391,12 @@ run_sort_level_next(struct sort_level *s sizeof(struct sort_list_item *), (int(*)(const void *, const void *)) list_coll); } else { - qsort(sl->leaves, sl->leaves_num, + DEFAULT_SORT_FUNC_RADIXSORT(sl->leaves, sl->leaves_num, sizeof(struct sort_list_item *), (int(*)(const void *, const void *)) list_coll); } } else if (!sort_opts_vals.sflag && sort_opts_vals.complex_sort) { - qsort(sl->leaves, sl->leaves_num, + DEFAULT_SORT_FUNC_RADIXSORT(sl->leaves, sl->leaves_num, sizeof(struct sort_list_item *), (int(*)(const void *, const void *)) list_coll_by_str_only); } @@ -541,12 +543,12 @@ run_top_sort_level(struct sort_level *sl sizeof(struct sort_list_item *), (int(*)(const void *, const void *)) list_coll); } else { - qsort(sl->leaves, sl->leaves_num, + DEFAULT_SORT_FUNC_RADIXSORT(sl->leaves, sl->leaves_num, sizeof(struct sort_list_item *), (int(*)(const void *, const void *)) list_coll); } } else if (!sort_opts_vals.sflag && sort_opts_vals.complex_sort) { - qsort(sl->leaves, sl->leaves_num, + DEFAULT_SORT_FUNC_RADIXSORT(sl->leaves, sl->leaves_num, sizeof(struct sort_list_item *), (int(*)(const void *, const void *)) list_coll_by_str_only); } Modified: head/usr.bin/sort/sort.1.in ============================================================================== --- head/usr.bin/sort/sort.1.in Wed Jul 4 14:25:14 2012 (r238107) +++ head/usr.bin/sort/sort.1.in Wed Jul 4 16:25:11 2012 (r238108) @@ -33,7 +33,7 @@ .\" .\" @(#)sort.1 8.1 (Berkeley) 6/6/93 .\" -.Dd May 25, 2012 +.Dd July 3, 2012 .Dt SORT 1 .Os .Sh NAME @@ -329,7 +329,7 @@ is used. .It Fl Fl debug Print some extra information about the sorting process to the standard output. -%%THREADS%%.It Fl Fl nthreads +%%THREADS%%.It Fl Fl parallel %%THREADS%%Set the maximum number of execution threads. %%THREADS%%Default number equals to the number of CPUs. .It Fl Fl files0-from Ns = Ns Ar filename Modified: head/usr.bin/sort/sort.c ============================================================================== --- head/usr.bin/sort/sort.c Wed Jul 4 14:25:14 2012 (r238107) +++ head/usr.bin/sort/sort.c Wed Jul 4 16:25:11 2012 (r238108) @@ -91,7 +91,7 @@ const char *nlsstr[] = { "", "[--heapsort] [--mergesort] [--radixsort] [--qsort] " "[--mmap] " #if defined(SORT_THREADS) - "[--nthreads thread_no] " + "[--parallel thread_no] " #endif "[--human-numeric-sort] " "[--version-sort] [--random-sort [--random-source file]] " @@ -132,7 +132,7 @@ enum VERSION_OPT, DEBUG_OPT, #if defined(SORT_THREADS) - NTHREADS_OPT, + PARALLEL_OPT, #endif RANDOMSOURCE_OPT, COMPRESSPROGRAM_OPT, @@ -171,7 +171,7 @@ struct option long_options[] = { { "numeric-sort", no_argument, NULL, 'n' }, { "output", required_argument, NULL, 'o' }, #if defined(SORT_THREADS) - { "nthreads", required_argument, NULL, NTHREADS_OPT }, + { "parallel", required_argument, NULL, PARALLEL_OPT }, #endif { "qsort", no_argument, NULL, QSORT_OPT }, { "radixsort", no_argument, NULL, RADIXSORT_OPT }, @@ -1119,7 +1119,7 @@ main(int argc, char **argv) } break; #if defined(SORT_THREADS) - case NTHREADS_OPT: + case PARALLEL_OPT: nthreads = (size_t)(atoi(optarg)); if (nthreads < 1) nthreads = 1; _______________________________________________ svn-src-head@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"