comparison src/core/ngx_string.c @ 1955:466fdc84c82d

use dynamically allocated buffer in ngx_sort()
author Igor Sysoev <igor@sysoev.ru>
date Sun, 23 Mar 2008 19:58:54 +0000
parents 286ff5ad4120
children cb8c0c8e0c27
comparison
equal deleted inserted replaced
1954:d85e291b99f9 1955:466fdc84c82d
1430 1430
1431 void 1431 void
1432 ngx_sort(void *base, size_t n, size_t size, 1432 ngx_sort(void *base, size_t n, size_t size,
1433 int (*cmp)(const void *, const void *)) 1433 int (*cmp)(const void *, const void *))
1434 { 1434 {
1435 u_char *p1, *p2; 1435 u_char *p1, *p2, *p;
1436 u_char buf[256]; 1436
1437 p = ngx_alloc(size, ngx_cycle->log);
1438 if (p == NULL) {
1439 return;
1440 }
1437 1441
1438 for (p1 = (u_char *) base + size; 1442 for (p1 = (u_char *) base + size;
1439 p1 < (u_char *) base + n * size; 1443 p1 < (u_char *) base + n * size;
1440 p1 += size) 1444 p1 += size)
1441 { 1445 {
1442 ngx_memcpy(buf, p1, size); 1446 ngx_memcpy(p, p1, size);
1443 1447
1444 for (p2 = p1; 1448 for (p2 = p1;
1445 p2 > (u_char *) base && cmp(p2 - size, buf) > 0; 1449 p2 > (u_char *) base && cmp(p2 - size, p) > 0;
1446 p2 -= size) 1450 p2 -= size)
1447 { 1451 {
1448 ngx_memcpy(p2, p2 - size, size); 1452 ngx_memcpy(p2, p2 - size, size);
1449 } 1453 }
1450 1454
1451 ngx_memcpy(p2, buf, size); 1455 ngx_memcpy(p2, p, size);
1452 } 1456 }
1457
1458 ngx_free(p);
1453 } 1459 }
1454 1460
1455 1461
1456 #if (NGX_MEMCPY_LIMIT) 1462 #if (NGX_MEMCPY_LIMIT)
1457 1463