Commit e5816090 authored by Jacek Caban's avatar Jacek Caban Committed by Alexandre Julliard

mshtml: Move common code to separated function.

parent f56c1a60
...@@ -56,6 +56,18 @@ static void elem_vector_add(elem_vector *buf, HTMLElement *elem) ...@@ -56,6 +56,18 @@ static void elem_vector_add(elem_vector *buf, HTMLElement *elem)
buf->buf[buf->len++] = elem; buf->buf[buf->len++] = elem;
} }
static void elem_vector_normalize(elem_vector *buf)
{
if(!buf->len) {
mshtml_free(buf->buf);
buf->buf = NULL;
}else if(buf->size > buf->len) {
buf->buf = mshtml_realloc(buf->buf, buf->len*sizeof(HTMLElement**));
}
buf->size = buf->len;
}
#define HTMLELEM_THIS(iface) DEFINE_THIS(HTMLElement, HTMLElement, iface) #define HTMLELEM_THIS(iface) DEFINE_THIS(HTMLElement, HTMLElement, iface)
#define HTMLELEM_NODE_THIS(iface) DEFINE_THIS2(HTMLElement, node, iface) #define HTMLELEM_NODE_THIS(iface) DEFINE_THIS2(HTMLElement, node, iface)
...@@ -1119,15 +1131,7 @@ static HRESULT WINAPI HTMLElement_get_all(IHTMLElement *iface, IDispatch **p) ...@@ -1119,15 +1131,7 @@ static HRESULT WINAPI HTMLElement_get_all(IHTMLElement *iface, IDispatch **p)
buf.buf = mshtml_alloc(buf.size*sizeof(HTMLElement**)); buf.buf = mshtml_alloc(buf.size*sizeof(HTMLElement**));
create_all_list(This->node.doc, This, &buf); create_all_list(This->node.doc, This, &buf);
elem_vector_normalize(&buf);
TRACE("ret\n");
if(!buf.len) {
mshtml_free(buf.buf);
buf.buf = NULL;
}else if(buf.size > buf.len) {
buf.buf = mshtml_realloc(buf.buf, buf.len*sizeof(HTMLElement**));
}
return HTMLElementCollection_Create((IUnknown*)HTMLELEM(This), buf.buf, buf.len, p); return HTMLElementCollection_Create((IUnknown*)HTMLELEM(This), buf.buf, buf.len, p);
} }
...@@ -1520,12 +1524,7 @@ static HRESULT WINAPI HTMLElementCollection_item(IHTMLElementCollection *iface, ...@@ -1520,12 +1524,7 @@ static HRESULT WINAPI HTMLElementCollection_item(IHTMLElementCollection *iface,
ERR("Invalid index. index=%d >= buf.len=%d\n",V_I4(&index), buf.len); ERR("Invalid index. index=%d >= buf.len=%d\n",V_I4(&index), buf.len);
return E_INVALIDARG; return E_INVALIDARG;
} }
if(!buf.len) { elem_vector_normalize(&buf);
mshtml_free(buf.buf);
buf.buf = NULL;
} else if(buf.size > buf.len) {
buf.buf = mshtml_realloc(buf.buf, buf.len*sizeof(HTMLElement*));
}
TRACE("Returning %d element(s).\n", buf.len); TRACE("Returning %d element(s).\n", buf.len);
return HTMLElementCollection_Create(This->ref_unk, buf.buf, buf.len, pdisp); return HTMLElementCollection_Create(This->ref_unk, buf.buf, buf.len, pdisp);
} }
...@@ -1567,16 +1566,10 @@ static HRESULT WINAPI HTMLElementCollection_tags(IHTMLElementCollection *iface, ...@@ -1567,16 +1566,10 @@ static HRESULT WINAPI HTMLElementCollection_tags(IHTMLElementCollection *iface,
} }
nsAString_Finish(&tag_str); nsAString_Finish(&tag_str);
elem_vector_normalize(&buf);
TRACE("fount %d tags\n", buf.len); TRACE("fount %d tags\n", buf.len);
if(!buf.len) {
mshtml_free(buf.buf);
buf.buf = NULL;
}else if(buf.size > buf.len) {
buf.buf = mshtml_realloc(buf.buf, buf.len*sizeof(HTMLElement*));
}
return HTMLElementCollection_Create(This->ref_unk, buf.buf, buf.len, pdisp); return HTMLElementCollection_Create(This->ref_unk, buf.buf, buf.len, pdisp);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment