mirror of
https://github.com/nginx/nginx.git
synced 2025-02-25 18:55:26 -06:00
ngx_sort
This commit is contained in:
parent
2517fbf2b8
commit
35921283df
@ -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)
|
#if (NGX_MEMCPY_LIMIT)
|
||||||
|
|
||||||
void *
|
void *
|
||||||
|
@ -150,6 +150,8 @@ uintptr_t ngx_escape_uri(u_char *dst, u_char *src, size_t size,
|
|||||||
void ngx_unescape_uri(u_char **dst, u_char **src, size_t size, ngx_uint_t type);
|
void ngx_unescape_uri(u_char **dst, u_char **src, size_t size, ngx_uint_t type);
|
||||||
|
|
||||||
|
|
||||||
|
void ngx_sort(void *base, size_t n, size_t size,
|
||||||
|
int (*cmp)(const void *, const void *));
|
||||||
#define ngx_qsort qsort
|
#define ngx_qsort qsort
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user