Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The improvement for xmpp_stanza_add_child. #169

Open
xbr-hw opened this issue Nov 23, 2020 · 1 comment
Open

The improvement for xmpp_stanza_add_child. #169

xbr-hw opened this issue Nov 23, 2020 · 1 comment

Comments

@xbr-hw
Copy link

xbr-hw commented Nov 23, 2020

while (s->next)

When the size of stanza is big, the procedure time of get the tail node will be too long. Therefore, we can store then address of the tail node everytime we invoke xmpp_stanza_add_child. Next time we can get the tail node directly. Like this:

int xmpp_stanza_add_child(xmpp_stanza_t *stanza, xmpp_stanza_t *child)
{
xmpp_stanza_t *s;

/* get a reference to the child */
xmpp_stanza_clone(child);

child->parent = stanza;

if (!stanza->children)
    stanza->children = child;
else {
    **s = stanza->children_tail;**
    s->next = child;
    child->prev = s;
}

**stanza->children_tail = child;**
return XMPP_EOK;

}

@pasis
Copy link
Member

pasis commented Nov 26, 2020

Good point! I would prefer to implement general-purpose double-linked list and use it everywhere in libstrophe. This will solve the issue. Additionally to performance improvement, this will reduce copy-paste and hide all complexity in a single module.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants