-
- Downloads
NodeFragment: improved insert methods
The single method (formerly SH_NodeFragment_append_child) to add a child at the end of the child list was replaced, by a bunch of methods to insert a child at the beginning (SH_NodeFragment_prepend_child), at the end (SH_NodeFragment_append_child), at a specific position (SH_NodeFragment_insert_child) and directly before (SH_NodeFragment_insert_child_before) or after another child (SH_NodeFragment_insert_child_after). All these methods are implemented by a single internal one (insert_child), as there isn't really much difference in inserting one or the other way. But this internal method doesn't check whether this insertion request is actually doable, to save overhead as not every insertion method requires this check. This is done by the respective method. However if the check is not done correctly the internal method will attempt to write at not allocated space, which will hopefully result in a segfault. The child list is implemented as an array. To reduce the overhead to realloc calls, the array is allocated in chunks of childs. The calculation how many has to be allocated is done by another static method and determined by the macro CHILD_CHUNK. This is set to 5, which is just a guess. It should be somewhere around the average number of childs per html element, to reduce unused overhead. Also some predicates (SH_NodeFragment_is_parent, SH_NodeFragment_is_ancestor) were added to check whether a relationship exists between to nodes, thus whether they are linked through one or multiple levels. These functions could replace the old ones (SH_NodeFragment_is_child, SH_NodeFragment_is_descendant) semantically. Furthermore they are more efficient as this is now possible to check over the parent pointer. The internal insert method also uses these methods to check whether the child node is actually a parent of the parent node, which would result in errors later one. The old test is now obsolete but remained, as it is not bad to test more.
Showing
- sefht.geany 4 additions, 4 deletionssefht.geany
- src/lib/sefht/node_fragment.c 257 additions, 20 deletionssrc/lib/sefht/node_fragment.c
- src/lib/sefht/node_fragment.h 55 additions, 4 deletionssrc/lib/sefht/node_fragment.h
- src/lib/sefht/status.h 3 additions, 1 deletionsrc/lib/sefht/status.h
- tests/test_node_fragment.c 556 additions, 4 deletionstests/test_node_fragment.c
Loading
Please register or sign in to comment