1 --- radixsort.c.orig 2010-06-21 14:05:02.000000000 -0700
2 +++ radixsort.c 2010-06-21 14:26:55.000000000 -0700
3 @@ -53,6 +53,7 @@ __FBSDID("$FreeBSD: src/lib/libc/stdlib/
11 @@ -60,11 +61,17 @@ typedef struct {
14 static inline void simplesort
15 -(const u_char **, int, int, const u_char *, u_int);
16 +(const u_char **, int, int, const u_char *, u_int) __attribute__((always_inline));
17 static void r_sort_a(const u_char **, int, int, const u_char *, u_int);
18 static void r_sort_b(const u_char **, const u_char **, int, int,
19 const u_char *, u_int);
21 +static int *r_sort_a_count;
22 +static int *r_sort_b_count;
24 +static void r_sort_count_allocate(void);
25 +static pthread_once_t r_sort_count_control = PTHREAD_ONCE_INIT;
27 #define THRESHOLD 20 /* Divert to simplesort(). */
28 #define SIZE 512 /* Default stack size. */
30 @@ -124,6 +131,12 @@ sradixsort(a, n, tab, endch)
34 +static void r_sort_count_allocate(void)
36 + r_sort_a_count = calloc(256, sizeof(int));
37 + r_sort_b_count = calloc(256, sizeof(int));
40 #define empty(s) (s >= sp)
41 #define pop(a, n, i) a = (--sp)->sa, n = sp->sn, i = sp->si
42 #define push(a, n, i) sp->sa = a, sp->sn = n, (sp++)->si = i
43 @@ -137,13 +150,19 @@ r_sort_a(a, n, i, tr, endch)
47 - static int count[256], nc, bmin;
48 + static int *count, nc, bmin;
50 const u_char **ak, *r;
51 stack s[SIZE], *sp, *sp0, *sp1, temp;
53 const u_char **an, *t, **aj, **top[256];
55 + if (pthread_once(&r_sort_count_control, r_sort_count_allocate)) {
59 + count = r_sort_a_count;
64 @@ -239,13 +258,19 @@ r_sort_b(a, ta, n, i, tr, endch)
68 - static int count[256], nc, bmin;
69 + static int *count, nc, bmin;
71 const u_char **ak, **ai;
72 stack s[512], *sp, *sp0, *sp1, temp;
73 const u_char **top[256];
76 + if (pthread_once(&r_sort_count_control, r_sort_count_allocate)) {
80 + count = r_sort_b_count;