Skip to content
Snippets Groups Projects
Commit 1e575a13 authored by Jonathan Schöbel's avatar Jonathan Schöbel
Browse files

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.
parent 95051add
No related branches found
No related tags found
No related merge requests found
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment