]> git.saurik.com Git - apple/libc.git/blame - stdlib/FreeBSD/radixsort.c.patch
Libc-763.11.tar.gz
[apple/libc.git] / stdlib / FreeBSD / radixsort.c.patch
CommitLineData
1f2f436a
A
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/
4 #include <stdlib.h>
5 #include <stddef.h>
6 #include <errno.h>
7+#include <pthread.h>
8
9 typedef struct {
10 const u_char **sa;
11@@ -60,11 +61,17 @@ typedef struct {
3d9156a7
A
12 } stack;
13
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);
1f2f436a
A
20
21+static int *r_sort_a_count;
22+static int *r_sort_b_count;
23+
24+static void r_sort_count_allocate(void);
25+static pthread_once_t r_sort_count_control = PTHREAD_ONCE_INIT;
26+
27 #define THRESHOLD 20 /* Divert to simplesort(). */
28 #define SIZE 512 /* Default stack size. */
29
30@@ -124,6 +131,12 @@ sradixsort(a, n, tab, endch)
31 return (0);
32 }
33
34+static void r_sort_count_allocate(void)
35+{
36+ r_sort_a_count = calloc(256, sizeof(int));
37+ r_sort_b_count = calloc(256, sizeof(int));
38+}
39+
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)
44 const u_char *tr;
45 u_int endch;
46 {
47- static int count[256], nc, bmin;
48+ static int *count, nc, bmin;
49 int c;
50 const u_char **ak, *r;
51 stack s[SIZE], *sp, *sp0, *sp1, temp;
52 int *cp, bigc;
53 const u_char **an, *t, **aj, **top[256];
54
55+ if (pthread_once(&r_sort_count_control, r_sort_count_allocate)) {
56+ return;
57+ }
58+
59+ count = r_sort_a_count;
60+
61 /* Set up stack. */
62 sp = s;
63 push(a, n, i);
64@@ -239,13 +258,19 @@ r_sort_b(a, ta, n, i, tr, endch)
65 const u_char *tr;
66 u_int endch;
67 {
68- static int count[256], nc, bmin;
69+ static int *count, nc, bmin;
70 int c;
71 const u_char **ak, **ai;
72 stack s[512], *sp, *sp0, *sp1, temp;
73 const u_char **top[256];
74 int *cp, bigc;
75
76+ if (pthread_once(&r_sort_count_control, r_sort_count_allocate)) {
77+ return;
78+ }
79+
80+ count = r_sort_b_count;
81+
82 sp = s;
83 push(a, n, i);
84 while (!empty(s)) {