ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change
on this file since b715c9a was
65cb413,
checked in by Aaron Moss <a3moss@…>, 7 years ago
|
Patch performance regression calling CFA stdlib delete in benchmark
|
-
Property mode set to
100644
|
File size:
1.4 KB
|
Rev | Line | |
---|
[d919f47] | 1 | #include <assert> |
---|
[309be81] | 2 | #include <stdlib> |
---|
| 3 | #include "cfa-stack.h" |
---|
| 4 | |
---|
| 5 | forall(otype T) struct stack_node { |
---|
| 6 | T value; |
---|
| 7 | stack_node(T)* next; |
---|
| 8 | }; |
---|
| 9 | |
---|
| 10 | forall(otype T) void ?{}(stack(T)* s) { |
---|
[122aecd] | 11 | (&s->head){ 0 }; |
---|
[309be81] | 12 | } |
---|
| 13 | |
---|
[d919f47] | 14 | forall(otype T) void copy(stack(T)* s, stack(T)* t) { |
---|
| 15 | stack_node(T)** crnt = &s->head; |
---|
| 16 | stack_node(T)* next = t->head; |
---|
| 17 | while ( next ) { |
---|
| 18 | *crnt = ((stack_node(T)*)malloc()){ next->value }; |
---|
| 19 | stack_node(T)* acrnt = *crnt; |
---|
| 20 | crnt = &acrnt->next; |
---|
| 21 | next = next->next; |
---|
| 22 | } |
---|
| 23 | *crnt = 0; |
---|
| 24 | } |
---|
| 25 | |
---|
[122aecd] | 26 | forall(otype T) void ?{}(stack(T)* s, stack(T) t) { |
---|
| 27 | stack_node(T)** crnt = &s->head; |
---|
| 28 | stack_node(T)* next = t.head; |
---|
[309be81] | 29 | while ( next ) { |
---|
[122aecd] | 30 | *crnt = ((stack_node(T)*)malloc()){ next->value }; |
---|
| 31 | stack_node(T)* acrnt = *crnt; |
---|
| 32 | crnt = &acrnt->next; |
---|
| 33 | next = next->next; |
---|
[309be81] | 34 | } |
---|
[122aecd] | 35 | *crnt = 0; |
---|
| 36 | } |
---|
| 37 | |
---|
| 38 | forall(otype T) stack(T) ?=?(stack(T)* s, stack(T) t) { |
---|
| 39 | if ( s->head == t.head ) return *s; |
---|
| 40 | clear(s); |
---|
| 41 | s{ t }; |
---|
| 42 | return *s; |
---|
| 43 | } |
---|
| 44 | |
---|
| 45 | forall(otype T) void ^?{}(stack(T)* s) { |
---|
| 46 | clear(s); |
---|
[309be81] | 47 | } |
---|
| 48 | |
---|
| 49 | forall(otype T) _Bool empty(const stack(T)* s) { |
---|
| 50 | return s->head == 0; |
---|
| 51 | } |
---|
| 52 | |
---|
| 53 | forall(otype T) void push(stack(T)* s, T value) { |
---|
[75ac87e] | 54 | s->head = ((stack_node(T)*)malloc()){ value, s->head }; |
---|
[309be81] | 55 | } |
---|
| 56 | |
---|
| 57 | forall(otype T) T pop(stack(T)* s) { |
---|
| 58 | stack_node(T)* n = s->head; |
---|
| 59 | s->head = n->next; |
---|
| 60 | T x = n->value; |
---|
[65cb413] | 61 | ^n{}; |
---|
| 62 | free(n); |
---|
[309be81] | 63 | return x; |
---|
| 64 | } |
---|
[122aecd] | 65 | |
---|
| 66 | forall(otype T) void clear(stack(T)* s) { |
---|
| 67 | stack_node(T)* next = s->head; |
---|
| 68 | while ( next ) { |
---|
| 69 | stack_node(T)* crnt = next; |
---|
| 70 | next = crnt->next; |
---|
| 71 | delete(crnt); |
---|
| 72 | } |
---|
[d919f47] | 73 | s->head = 0; |
---|
[122aecd] | 74 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.