public
Description: New and ultra-turbo-crazy-fast backend for Thin
Homepage: http://code.macournoyer.com/thin/
Clone URL: git://github.com/macournoyer/thin-turbo.git
Search Repo:
Remove unused array.c
macournoyer (author)
Wed Apr 30 13:28:37 -0700 2008
commit  9df329be7c5ba0f634f063086f12f4b7859454a6
tree    d4c414546bc044804f8025be1d1b38a91326257e
parent  27e1ec0dc404092affefa8f67f43e1325e28931d
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0
@@ -1,57 +1 @@
0
-#include "array.h"
0
-
0
-array_t * array_create(uint num, size_t size)
0
-{
0
- array_t *a = (array_t *) malloc(sizeof(array_t));
0
- if (a == NULL)
0
- return NULL;
0
-
0
- a->size = size;
0
- a->nalloc = num;
0
- a->nitems = 0;
0
- a->items = malloc(num * size);
0
-
0
- if (a->items == NULL) {
0
- free(a);
0
- return NULL;
0
- }
0
-
0
- return a;
0
-}
0
-
0
-void * array_push(array_t *a)
0
-{
0
- void *item;
0
-
0
- if (a->nitems == a->nalloc) {
0
- /* array is full, double the size */
0
-
0
- void *new;
0
- size_t size;
0
-
0
- size = a->size * a->nalloc;
0
-
0
- new = realloc(a->items, 2 * size);
0
- if (new == NULL)
0
- return NULL;
0
-
0
- a->items = new;
0
- a->nalloc *= 2;
0
- }
0
-
0
- item = (u_char *) a->items + a->size * a->nitems;
0
- a->nitems++;
0
-
0
- return item;
0
-}
0
-
0
-void array_destroy(array_t *a)
0
-{
0
- void *items;
0
-
0
- items = a->items;
0
-
0
- free(items);
0
- free(a);
0
-}
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0
@@ -1,29 +1 @@
0
-#ifndef _ARRAY_H_
0
-#define _ARRAY_H_
0
-
0
-#include <stdlib.h>
0
-#include <string.h>
0
-#include <stdarg.h>
0
-#include <sys/types.h>
0
-
0
-typedef struct array_s array_t;
0
-
0
-struct array_s {
0
- size_t size;
0
- uint nalloc;
0
- uint nitems;
0
- void *items;
0
-};
0
-
0
-/* Create an dynamic array of initialy +num+ items */
0
-array_t * array_create(uint num, size_t size);
0
-
0
-/* Push a new item to the array returning its ref.
0
- * If the array is not big enought its size is doubled. */
0
-void * array_push(array_t *a);
0
-
0
-/* Destroy the array and frees the memory */
0
-void array_destroy(array_t *a);
0
-
0
-#endif /* _ARRAY_H_ */

Comments

    No one has commented yet.