line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#include |
2
|
|
|
|
|
|
|
#include |
3
|
|
|
|
|
|
|
#include "glog.h" |
4
|
|
|
|
|
|
|
#include "gmem.h" |
5
|
|
|
|
|
|
|
#include "plist.h" |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
static void plist_grow(PList* plist); |
8
|
|
|
|
|
|
|
|
9
|
181
|
|
|
|
|
|
PList* plist_create(void) { |
10
|
181
|
|
|
|
|
|
PList* p = 0; |
11
|
181
|
|
|
|
|
|
GMEM_NEW(p, PList*, sizeof(PList)); |
12
|
181
|
50
|
|
|
|
|
if (!p) { |
13
|
0
|
|
|
|
|
|
return 0; |
14
|
|
|
|
|
|
|
} |
15
|
|
|
|
|
|
|
|
16
|
181
|
|
|
|
|
|
plist_init(p); |
17
|
181
|
|
|
|
|
|
return p; |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
181
|
|
|
|
|
|
void plist_destroy(PList* plist) { |
21
|
181
|
50
|
|
|
|
|
if (!plist) { |
22
|
0
|
|
|
|
|
|
return; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
181
|
|
|
|
|
|
plist_clear(plist); |
26
|
181
|
|
|
|
|
|
GMEM_DEL(plist, PList*, sizeof(PList)); |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
46
|
|
|
|
|
|
PList* plist_clone(PList* plist) { |
30
|
46
|
50
|
|
|
|
|
if (!plist) { |
31
|
0
|
|
|
|
|
|
return 0; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
46
|
|
|
|
|
|
PList* p = plist_create(); |
35
|
|
|
|
|
|
|
int j; |
36
|
104
|
100
|
|
|
|
|
for (j = 0; j < plist->ulen; ++j) { |
37
|
58
|
|
|
|
|
|
plist_grow(p); |
38
|
58
|
|
|
|
|
|
p->data[j].ptr = plist->data[j].ptr; |
39
|
58
|
|
|
|
|
|
++p->ulen; |
40
|
|
|
|
|
|
|
} |
41
|
46
|
|
|
|
|
|
return p; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
378
|
|
|
|
|
|
void plist_init(PList* plist) { |
45
|
378
|
50
|
|
|
|
|
if (!plist) { |
46
|
0
|
|
|
|
|
|
return; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
378
|
|
|
|
|
|
plist->data = 0; |
50
|
378
|
|
|
|
|
|
plist->alen = plist->ulen = 0; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
197
|
|
|
|
|
|
void plist_clear(PList* plist) { |
54
|
197
|
50
|
|
|
|
|
if (!plist) { |
55
|
0
|
|
|
|
|
|
return; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
197
|
|
|
|
|
|
GMEM_DELARR(plist->data, PNode*, plist->alen, sizeof(PNode)); |
59
|
197
|
|
|
|
|
|
plist_init(plist); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
182
|
|
|
|
|
|
int plist_size(const PList* plist) |
63
|
|
|
|
|
|
|
{ |
64
|
182
|
50
|
|
|
|
|
return plist ? plist->ulen : 0; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
169
|
|
|
|
|
|
PNode* plist_add(PList* plist, const void* obj) |
68
|
|
|
|
|
|
|
{ |
69
|
169
|
50
|
|
|
|
|
if (!plist) { |
70
|
0
|
|
|
|
|
|
return 0; |
71
|
|
|
|
|
|
|
} |
72
|
169
|
100
|
|
|
|
|
if (!obj) { |
73
|
56
|
|
|
|
|
|
return 0; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
113
|
|
|
|
|
|
PNode* n = 0; |
77
|
113
|
|
|
|
|
|
plist_grow(plist); |
78
|
113
|
|
|
|
|
|
n = &plist->data[plist->ulen++]; |
79
|
113
|
|
|
|
|
|
n->ptr = obj; |
80
|
113
|
|
|
|
|
|
return n; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
0
|
|
|
|
|
|
void plist_dump(const PList* plist, FILE* fp) |
84
|
|
|
|
|
|
|
{ |
85
|
0
|
0
|
|
|
|
|
if (!plist) { |
86
|
0
|
|
|
|
|
|
return; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
int j; |
90
|
0
|
0
|
|
|
|
|
for (j = 0; j < plist->ulen; ++j) { |
91
|
0
|
|
|
|
|
|
fprintf(fp, "%4d: %p\n", j, plist->data[j].ptr); |
92
|
|
|
|
|
|
|
} |
93
|
0
|
|
|
|
|
|
fflush(fp); |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
|
97
|
171
|
|
|
|
|
|
static void plist_grow(PList* plist) { |
98
|
171
|
50
|
|
|
|
|
if (!plist) { |
99
|
0
|
|
|
|
|
|
return; |
100
|
|
|
|
|
|
|
} |
101
|
171
|
100
|
|
|
|
|
if (plist->ulen < plist->alen) { |
102
|
25
|
|
|
|
|
|
return; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
146
|
100
|
|
|
|
|
int count = plist->alen == 0 ? PLIST_INITIAL_SIZE : 2*plist->alen; |
106
|
|
|
|
|
|
|
GLOG(("=C= Growing PList from %d to %d", plist->alen, count)); |
107
|
146
|
|
|
|
|
|
GMEM_REALLOC(plist->data, PNode*, sizeof(PNode) * plist->alen, sizeof(PNode) * count); |
108
|
146
|
|
|
|
|
|
plist->alen = count; |
109
|
|
|
|
|
|
|
} |