Mercurial > hg > nginx-quic
comparison src/core/ngx_string.c @ 1208:5eae5751507f
ngx_sort
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Mon, 21 May 2007 14:05:23 +0000 |
parents | db7c468c447d |
children | 4ec0bc95172b |
comparison
equal
deleted
inserted
replaced
1207:103988cef757 | 1208:5eae5751507f |
---|---|
1200 *dst = d; | 1200 *dst = d; |
1201 *src = s; | 1201 *src = s; |
1202 } | 1202 } |
1203 | 1203 |
1204 | 1204 |
1205 /* ngx_sort() is implemented as insertion sort because we need stable sort */ | |
1206 | |
1207 void | |
1208 ngx_sort(void *base, size_t n, size_t size, | |
1209 int (*cmp)(const void *, const void *)) | |
1210 { | |
1211 u_char *p1, *p2; | |
1212 u_char buf[256]; | |
1213 | |
1214 for (p1 = (u_char *) base + size; | |
1215 p1 < (u_char *) base + n * size; | |
1216 p1 += size) | |
1217 { | |
1218 ngx_memcpy(buf, p1, size); | |
1219 | |
1220 for (p2 = p1; | |
1221 p2 > (u_char *) base && cmp(p2 - size, buf) > 0; | |
1222 p2 -= size) | |
1223 { | |
1224 ngx_memcpy(p2, p2 - size, size); | |
1225 } | |
1226 | |
1227 ngx_memcpy(p2, buf, size); | |
1228 } | |
1229 } | |
1230 | |
1231 | |
1205 #if (NGX_MEMCPY_LIMIT) | 1232 #if (NGX_MEMCPY_LIMIT) |
1206 | 1233 |
1207 void * | 1234 void * |
1208 ngx_memcpy(void *dst, void *src, size_t n) | 1235 ngx_memcpy(void *dst, void *src, size_t n) |
1209 { | 1236 { |