diff src/core/ngx_string.c @ 302:9b7db0df50f0 NGINX_0_5_21

nginx 0.5.21 *) Bugfix: if server has more than about ten locations, then regex locations might be choosen not in that order as they were specified. *) Bugfix: a worker process may got caught in an endless loop on 64-bit platform, if the 33-rd or next in succession backend has failed. Thanks to Anton Povarov. *) Bugfix: a bus error might occur on Solaris/sparc64 if the PCRE library was used. Thanks to Andrei Nigmatulin. *) Bugfix: in the HTTPS protocol in the "proxy_pass" directive.
author Igor Sysoev <http://sysoev.ru>
date Mon, 28 May 2007 00:00:00 +0400
parents 5bef04fc3fd5
children 95183808f549
line wrap: on
line diff
--- a/src/core/ngx_string.c
+++ b/src/core/ngx_string.c
@@ -1202,6 +1202,33 @@ done:
 }
 
 
+/* ngx_sort() is implemented as insertion sort because we need stable sort */
+
+void
+ngx_sort(void *base, size_t n, size_t size,
+    int (*cmp)(const void *, const void *))
+{
+    u_char  *p1, *p2;
+    u_char   buf[256];
+
+    for (p1 = (u_char *) base + size;
+         p1 < (u_char *) base + n * size;
+         p1 += size)
+    {
+        ngx_memcpy(buf, p1, size);
+
+        for (p2 = p1;
+             p2 > (u_char *) base && cmp(p2 - size, buf) > 0;
+             p2 -= size)
+        {
+            ngx_memcpy(p2, p2 - size, size);
+        }
+
+        ngx_memcpy(p2, buf, size);
+    }
+}
+
+
 #if (NGX_MEMCPY_LIMIT)
 
 void *