diff options
| author | 2018-12-10 02:20:24 +0100 | |
|---|---|---|
| committer | 2018-12-10 02:22:15 +0100 | |
| commit | 4de329327ce4aa175e8496d1bff8604bffb6c574 (patch) | |
| tree | 0c5fce7e138756a2479acab5a3098fa12ea6971b /libcnary | |
| parent | 71dd25e14616bd261c3b6c80ff990cd1078266f6 (diff) | |
| download | libplist-4de329327ce4aa175e8496d1bff8604bffb6c574.tar.gz libplist-4de329327ce4aa175e8496d1bff8604bffb6c574.tar.bz2 | |
Remove node_iterator and operate on node list directly to improve memory usage
Diffstat (limited to 'libcnary')
| -rw-r--r-- | libcnary/Makefile.am | 4 | ||||
| -rw-r--r-- | libcnary/include/iterator.h | 49 | ||||
| -rw-r--r-- | libcnary/include/node_iterator.h | 55 | ||||
| -rw-r--r-- | libcnary/iterator.c | 61 | ||||
| -rw-r--r-- | libcnary/node.c | 6 | ||||
| -rw-r--r-- | libcnary/node_iterator.c | 80 |
6 files changed, 1 insertions, 254 deletions
diff --git a/libcnary/Makefile.am b/libcnary/Makefile.am index bba9ada..5a26fb5 100644 --- a/libcnary/Makefile.am +++ b/libcnary/Makefile.am | |||
| @@ -8,11 +8,7 @@ libcnary_la_SOURCES = \ | |||
| 8 | node.c \ | 8 | node.c \ |
| 9 | list.c \ | 9 | list.c \ |
| 10 | node_list.c \ | 10 | node_list.c \ |
| 11 | iterator.c \ | ||
| 12 | node_iterator.c \ | ||
| 13 | include/node.h \ | 11 | include/node.h \ |
| 14 | include/list.h \ | 12 | include/list.h \ |
| 15 | include/node_list.h \ | 13 | include/node_list.h \ |
| 16 | include/iterator.h \ | ||
| 17 | include/node_iterator.h \ | ||
| 18 | include/object.h | 14 | include/object.h |
diff --git a/libcnary/include/iterator.h b/libcnary/include/iterator.h deleted file mode 100644 index a33c4ff..0000000 --- a/libcnary/include/iterator.h +++ /dev/null | |||
| @@ -1,49 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * iterator.h | ||
| 3 | * | ||
| 4 | * Created on: Mar 8, 2011 | ||
| 5 | * Author: posixninja | ||
| 6 | * | ||
| 7 | * Copyright (c) 2011 Joshua Hill. All Rights Reserved. | ||
| 8 | * | ||
| 9 | * This library is free software; you can redistribute it and/or | ||
| 10 | * modify it under the terms of the GNU Lesser General Public | ||
| 11 | * License as published by the Free Software Foundation; either | ||
| 12 | * version 2.1 of the License, or (at your option) any later version. | ||
| 13 | * | ||
| 14 | * This library is distributed in the hope that it will be useful, | ||
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 17 | * Lesser General Public License for more details. | ||
| 18 | * | ||
| 19 | * You should have received a copy of the GNU Lesser General Public | ||
| 20 | * License along with this library; if not, write to the Free Software | ||
| 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 22 | */ | ||
| 23 | |||
| 24 | #ifndef ITERATOR_H_ | ||
| 25 | #define ITERATOR_H_ | ||
| 26 | |||
| 27 | struct list_t; | ||
| 28 | struct object_t; | ||
| 29 | |||
| 30 | typedef struct iterator_t { | ||
| 31 | struct object_t*(*next)(struct iterator_t* iterator); | ||
| 32 | int(*bind)(struct iterator_t* iterator, struct list_t* list); | ||
| 33 | |||
| 34 | unsigned int count; | ||
| 35 | unsigned int position; | ||
| 36 | |||
| 37 | struct list_t* list; | ||
| 38 | struct object_t* end; | ||
| 39 | struct object_t* begin; | ||
| 40 | struct object_t* value; | ||
| 41 | } iterator_t; | ||
| 42 | |||
| 43 | void iterator_destroy(struct iterator_t* iterator); | ||
| 44 | struct iterator_t* iterator_create(struct list_t* list); | ||
| 45 | |||
| 46 | struct object_t* iterator_next(struct iterator_t* iterator); | ||
| 47 | int iterator_bind(struct iterator_t* iterator, struct list_t* list); | ||
| 48 | |||
| 49 | #endif /* ITERATOR_H_ */ | ||
diff --git a/libcnary/include/node_iterator.h b/libcnary/include/node_iterator.h deleted file mode 100644 index d3bce3a..0000000 --- a/libcnary/include/node_iterator.h +++ /dev/null | |||
| @@ -1,55 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * node_iterator.h | ||
| 3 | * | ||
| 4 | * Created on: Mar 8, 2011 | ||
| 5 | * Author: posixninja | ||
| 6 | * | ||
| 7 | * Copyright (c) 2011 Joshua Hill. All Rights Reserved. | ||
| 8 | * | ||
| 9 | * This library is free software; you can redistribute it and/or | ||
| 10 | * modify it under the terms of the GNU Lesser General Public | ||
| 11 | * License as published by the Free Software Foundation; either | ||
| 12 | * version 2.1 of the License, or (at your option) any later version. | ||
| 13 | * | ||
| 14 | * This library is distributed in the hope that it will be useful, | ||
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 17 | * Lesser General Public License for more details. | ||
| 18 | * | ||
| 19 | * You should have received a copy of the GNU Lesser General Public | ||
| 20 | * License along with this library; if not, write to the Free Software | ||
| 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 22 | */ | ||
| 23 | |||
| 24 | #ifndef NODE_ITERATOR_H_ | ||
| 25 | #define NODE_ITERATOR_H_ | ||
| 26 | |||
| 27 | #include "iterator.h" | ||
| 28 | #include "node_list.h" | ||
| 29 | |||
| 30 | // This class implements the abstract iterator class | ||
| 31 | typedef struct node_iterator_t { | ||
| 32 | // Super class | ||
| 33 | struct iterator_t super; | ||
| 34 | |||
| 35 | // Local members | ||
| 36 | struct node_t*(*next)(struct node_iterator_t* iterator); | ||
| 37 | int(*bind)(struct node_iterator_t* iterator, struct node_list_t* list); | ||
| 38 | |||
| 39 | unsigned int count; | ||
| 40 | unsigned int position; | ||
| 41 | |||
| 42 | struct node_list_t* list; | ||
| 43 | struct node_t* end; | ||
| 44 | struct node_t* begin; | ||
| 45 | struct node_t* value; | ||
| 46 | |||
| 47 | } node_iterator_t; | ||
| 48 | |||
| 49 | void node_iterator_destroy(node_iterator_t* iterator); | ||
| 50 | node_iterator_t* node_iterator_create(node_list_t* list); | ||
| 51 | |||
| 52 | struct node_t* node_iterator_next(struct node_iterator_t* iterator); | ||
| 53 | int node_iterator_bind(struct node_iterator_t* iterator, struct node_list_t* list); | ||
| 54 | |||
| 55 | #endif /* NODE_ITERATOR_H_ */ | ||
diff --git a/libcnary/iterator.c b/libcnary/iterator.c deleted file mode 100644 index 492a8ae..0000000 --- a/libcnary/iterator.c +++ /dev/null | |||
| @@ -1,61 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * iterator.c | ||
| 3 | * | ||
| 4 | * Created on: Mar 8, 2011 | ||
| 5 | * Author: posixninja | ||
| 6 | * | ||
| 7 | * Copyright (c) 2011 Joshua Hill. All Rights Reserved. | ||
| 8 | * | ||
| 9 | * This library is free software; you can redistribute it and/or | ||
| 10 | * modify it under the terms of the GNU Lesser General Public | ||
| 11 | * License as published by the Free Software Foundation; either | ||
| 12 | * version 2.1 of the License, or (at your option) any later version. | ||
| 13 | * | ||
| 14 | * This library is distributed in the hope that it will be useful, | ||
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 17 | * Lesser General Public License for more details. | ||
| 18 | * | ||
| 19 | * You should have received a copy of the GNU Lesser General Public | ||
| 20 | * License along with this library; if not, write to the Free Software | ||
| 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 22 | */ | ||
| 23 | |||
| 24 | #include <stdio.h> | ||
| 25 | #include <stdlib.h> | ||
| 26 | #include <string.h> | ||
| 27 | |||
| 28 | #include "list.h" | ||
| 29 | #include "object.h" | ||
| 30 | #include "iterator.h" | ||
| 31 | |||
| 32 | void iterator_destroy(iterator_t* iterator) { | ||
| 33 | if(iterator) { | ||
| 34 | free(iterator); | ||
| 35 | } | ||
| 36 | } | ||
| 37 | |||
| 38 | iterator_t* iterator_create(list_t* list) { | ||
| 39 | iterator_t* iterator = (iterator_t*) malloc(sizeof(iterator_t)); | ||
| 40 | if(iterator == NULL) { | ||
| 41 | return NULL; | ||
| 42 | } | ||
| 43 | memset(iterator, '\0', sizeof(iterator_t)); | ||
| 44 | |||
| 45 | if(list != NULL) { | ||
| 46 | // Create and bind to list | ||
| 47 | |||
| 48 | } else { | ||
| 49 | // Empty Iterator | ||
| 50 | } | ||
| 51 | |||
| 52 | return iterator; | ||
| 53 | } | ||
| 54 | |||
| 55 | object_t* iterator_next(iterator_t* iterator) { | ||
| 56 | return NULL; | ||
| 57 | } | ||
| 58 | |||
| 59 | int iterator_bind(iterator_t* iterator, list_t* list) { | ||
| 60 | return -1; | ||
| 61 | } | ||
diff --git a/libcnary/node.c b/libcnary/node.c index 4b550dd..c24ca7a 100644 --- a/libcnary/node.c +++ b/libcnary/node.c | |||
| @@ -26,7 +26,6 @@ | |||
| 26 | 26 | ||
| 27 | #include "node.h" | 27 | #include "node.h" |
| 28 | #include "node_list.h" | 28 | #include "node_list.h" |
| 29 | #include "node_iterator.h" | ||
| 30 | 29 | ||
| 31 | void node_destroy(node_t* node) { | 30 | void node_destroy(node_t* node) { |
| 32 | if(!node) return; | 31 | if(!node) return; |
| @@ -114,7 +113,6 @@ int node_insert(node_t* parent, unsigned int node_index, node_t* child) | |||
| 114 | static void _node_debug(node_t* node, unsigned int depth) { | 113 | static void _node_debug(node_t* node, unsigned int depth) { |
| 115 | unsigned int i = 0; | 114 | unsigned int i = 0; |
| 116 | node_t* current = NULL; | 115 | node_t* current = NULL; |
| 117 | node_iterator_t* iter = NULL; | ||
| 118 | for(i = 0; i < depth; i++) { | 116 | for(i = 0; i < depth; i++) { |
| 119 | printf("\t"); | 117 | printf("\t"); |
| 120 | } | 118 | } |
| @@ -128,11 +126,9 @@ static void _node_debug(node_t* node, unsigned int depth) { | |||
| 128 | if(node->parent) { | 126 | if(node->parent) { |
| 129 | printf("NODE\n"); | 127 | printf("NODE\n"); |
| 130 | } | 128 | } |
| 131 | iter = node_iterator_create(node->children); | 129 | for (current = node_first_child(node); current; current = node_next_sibling(current)) { |
| 132 | while ((current = iter->next(iter))) { | ||
| 133 | _node_debug(current, depth+1); | 130 | _node_debug(current, depth+1); |
| 134 | } | 131 | } |
| 135 | node_iterator_destroy(iter); | ||
| 136 | } | 132 | } |
| 137 | 133 | ||
| 138 | } | 134 | } |
diff --git a/libcnary/node_iterator.c b/libcnary/node_iterator.c deleted file mode 100644 index e629b73..0000000 --- a/libcnary/node_iterator.c +++ /dev/null | |||
| @@ -1,80 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * node_iterator.c | ||
| 3 | * | ||
| 4 | * Created on: Mar 8, 2011 | ||
| 5 | * Author: posixninja | ||
| 6 | * | ||
| 7 | * Copyright (c) 2011 Joshua Hill. All Rights Reserved. | ||
| 8 | * | ||
| 9 | * This library is free software; you can redistribute it and/or | ||
| 10 | * modify it under the terms of the GNU Lesser General Public | ||
| 11 | * License as published by the Free Software Foundation; either | ||
| 12 | * version 2.1 of the License, or (at your option) any later version. | ||
| 13 | * | ||
| 14 | * This library is distributed in the hope that it will be useful, | ||
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 17 | * Lesser General Public License for more details. | ||
| 18 | * | ||
| 19 | * You should have received a copy of the GNU Lesser General Public | ||
| 20 | * License along with this library; if not, write to the Free Software | ||
| 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 22 | */ | ||
| 23 | |||
| 24 | #include <stdio.h> | ||
| 25 | #include <stdlib.h> | ||
| 26 | #include <string.h> | ||
| 27 | |||
| 28 | #include "node.h" | ||
| 29 | #include "node_list.h" | ||
| 30 | #include "node_iterator.h" | ||
| 31 | |||
| 32 | void node_iterator_destroy(node_iterator_t* iterator) { | ||
| 33 | if(iterator) { | ||
| 34 | free(iterator); | ||
| 35 | } | ||
| 36 | } | ||
| 37 | |||
| 38 | node_iterator_t* node_iterator_create(node_list_t* list) { | ||
| 39 | node_iterator_t* iterator = (node_iterator_t*) malloc(sizeof(node_iterator_t)); | ||
| 40 | if(iterator == NULL) { | ||
| 41 | return NULL; | ||
| 42 | } | ||
| 43 | memset(iterator, '\0', sizeof(node_iterator_t)); | ||
| 44 | |||
| 45 | iterator->count = 0; | ||
| 46 | iterator->position = 0; | ||
| 47 | |||
| 48 | iterator->end = NULL; | ||
| 49 | iterator->begin = NULL; | ||
| 50 | iterator->value = NULL; | ||
| 51 | |||
| 52 | iterator->list = NULL; | ||
| 53 | iterator->next = node_iterator_next; | ||
| 54 | iterator->bind = node_iterator_bind; | ||
| 55 | |||
| 56 | |||
| 57 | if(list != NULL) { | ||
| 58 | iterator->bind(iterator, list); | ||
| 59 | } | ||
| 60 | |||
| 61 | return iterator; | ||
| 62 | } | ||
| 63 | |||
| 64 | node_t* node_iterator_next(node_iterator_t* iterator) { | ||
| 65 | node_t* node = iterator->value; | ||
| 66 | if (node) { | ||
| 67 | iterator->value = node->next; | ||
| 68 | } | ||
| 69 | iterator->position++; | ||
| 70 | return node; | ||
| 71 | } | ||
| 72 | |||
| 73 | int node_iterator_bind(node_iterator_t* iterator, node_list_t* list) { | ||
| 74 | iterator->position = 0; | ||
| 75 | iterator->end = list->end; | ||
| 76 | iterator->count = list->count; | ||
| 77 | iterator->begin = list->begin; | ||
| 78 | iterator->value = list->begin; | ||
| 79 | return 0; | ||
| 80 | } | ||
