Skip to content

Commit 76b3b86

Browse files
committed
Swap where stuff gets stored
1 parent 95365a6 commit 76b3b86

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

ext/dom/token_list.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#include "zend_interfaces.h"
2626

2727
#define TOKEN_LIST_GET_INTERNAL() php_dom_token_list_from_obj(Z_OBJ_P(ZEND_THIS))
28-
#define TOKEN_LIST_GET_SET(intern) intern->dom.ptr
28+
#define TOKEN_LIST_GET_SET(intern) (&(intern)->token_set)
2929
#define Z_TOKEN_LIST_P(zv) php_dom_token_list_from_obj(Z_OBJ_P(zv))
3030

3131
typedef struct _dom_token_list_it {
@@ -119,7 +119,8 @@ static char *dom_ordered_set_serializer(HashTable *token_set)
119119

120120
static zend_always_inline xmlNode *dom_token_list_get_element(dom_token_list_object *intern)
121121
{
122-
return intern->element_ptr->node;
122+
php_libxml_node_ptr *element_ptr = intern->dom.ptr;
123+
return element_ptr->node;
123124
}
124125

125126
static zend_always_inline const xmlAttr *dom_token_list_get_attr(dom_token_list_object *intern)
@@ -192,13 +193,12 @@ void dom_token_list_ctor(dom_token_list_object *intern, dom_object *element_obj)
192193
{
193194
php_libxml_node_ptr *ptr = element_obj->ptr;
194195
ptr->refcount++;
195-
intern->element_ptr = ptr;
196+
intern->dom.ptr = ptr;
196197
element_obj->document->refcount++;
197198
intern->dom.document = element_obj->document;
198199

199200
intern->cache_tag.modification_nr = 0;
200201

201-
ALLOC_HASHTABLE(TOKEN_LIST_GET_SET(intern));
202202
HashTable *token_set = TOKEN_LIST_GET_SET(intern);
203203
zend_hash_init(token_set, 0, NULL, NULL, false);
204204

@@ -211,15 +211,14 @@ void dom_token_list_free_obj(zend_object *object)
211211

212212
zend_object_std_dtor(object);
213213

214-
if (EXPECTED(intern->element_ptr != NULL)) { /* Object initialized? */
214+
if (EXPECTED(intern->dom.ptr != NULL)) { /* Object initialized? */
215215
xmlNodePtr node = dom_token_list_get_element(intern);
216-
if (php_libxml_decrement_node_ptr_ref(intern->element_ptr) == 0) {
216+
if (php_libxml_decrement_node_ptr_ref(intern->dom.ptr) == 0) {
217217
php_libxml_node_free_resource(node);
218218
}
219219
php_libxml_decrement_doc_ref((php_libxml_node_object *) &intern->dom);
220220
HashTable *token_set = TOKEN_LIST_GET_SET(intern);
221221
zend_hash_destroy(token_set);
222-
FREE_HASHTABLE(token_set);
223222
efree(intern->cached_string);
224223
}
225224
}
@@ -326,7 +325,7 @@ zend_result dom_token_list_length_read(dom_object *obj, zval *retval)
326325
{
327326
dom_token_list_object *token_list = php_dom_token_list_from_dom_obj(obj);
328327
dom_token_list_ensure_set_up_to_date(token_list);
329-
ZVAL_LONG(retval, zend_hash_num_elements(obj->ptr));
328+
ZVAL_LONG(retval, zend_hash_num_elements(TOKEN_LIST_GET_SET(token_list)));
330329
return SUCCESS;
331330
}
332331

ext/dom/token_list.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#define TOKEN_LIST_H
1919

2020
typedef struct _dom_token_list_object {
21-
php_libxml_node_ptr *element_ptr;
21+
HashTable token_set;
2222
/* Used to check if the token set is up to date. */
2323
char *cached_string;
2424
php_libxml_cache_tag cache_tag;

0 commit comments

Comments
 (0)