Skip to content

Commit 479e9be

Browse files
committed
Store hash table entry directly in dom_nnodemap_object
Splits the purpose of the baseobj_zv: now no longer either is an array or an object. Stores the hash table pointer directly, if used.
1 parent 8736342 commit 479e9be

File tree

5 files changed

+20
-19
lines changed

5 files changed

+20
-19
lines changed

ext/dom/obj_map.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,7 @@ static zend_long dom_map_get_xmlht_length(dom_nnodemap_object *map)
5555

5656
static zend_long dom_map_get_nodeset_length(dom_nnodemap_object *map)
5757
{
58-
HashTable *nodeht = Z_ARRVAL(map->baseobj_zv);
59-
return zend_hash_num_elements(nodeht);
58+
return zend_hash_num_elements(map->array);
6059
}
6160

6261
static zend_long dom_map_get_prop_length(dom_nnodemap_object *map)
@@ -132,8 +131,7 @@ static void dom_map_get_notation_item(dom_nnodemap_object *map, zend_long index,
132131

133132
static void dom_map_get_nodeset_item(dom_nnodemap_object *map, zend_long index, zval *return_value)
134133
{
135-
HashTable *nodeht = Z_ARRVAL(map->baseobj_zv);
136-
zval *entry = zend_hash_index_find(nodeht, index);
134+
zval *entry = zend_hash_index_find(map->array, index);
137135
if (entry) {
138136
RETURN_COPY(entry);
139137
} else {
@@ -294,7 +292,7 @@ void php_dom_create_obj_map(dom_object *basenode, dom_object *intern, xmlHashTab
294292

295293
ZEND_ASSERT(basenode != NULL);
296294

297-
ZVAL_OBJ_COPY(&mapptr->baseobj_zv, &basenode->std);
295+
GC_ADDREF(&basenode->std);
298296

299297
xmlDocPtr doc = basenode->document ? basenode->document->ptr : NULL;
300298

ext/dom/obj_map.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ typedef struct php_dom_obj_map_handler {
3030

3131
typedef struct dom_nnodemap_object {
3232
dom_object *baseobj;
33-
zval baseobj_zv;
3433
zend_long cached_length;
3534
union {
3635
xmlHashTable *ht;
36+
HashTable *array;
3737
struct {
3838
xmlChar *local;
3939
zend_string *local_lower;
@@ -47,6 +47,7 @@ typedef struct dom_nnodemap_object {
4747
const php_dom_obj_map_handler *handler;
4848
bool release_local;
4949
bool release_ns;
50+
bool release_array;
5051
} dom_nnodemap_object;
5152

5253
void php_dom_create_obj_map(dom_object *basenode, dom_object *intern, xmlHashTablePtr ht, zend_string *local, zend_string *ns, const php_dom_obj_map_handler *handler);

ext/dom/parentnode/css_selectors.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,8 @@ void dom_parent_node_query_selector_all(xmlNodePtr thisp, dom_object *intern, zv
249249
object_init_ex(return_value, dom_modern_nodelist_class_entry);
250250
dom_object *ret_obj = Z_DOMOBJ_P(return_value);
251251
dom_nnodemap_object *mapptr = (dom_nnodemap_object *) ret_obj->ptr;
252-
ZVAL_ARR(&mapptr->baseobj_zv, list);
252+
mapptr->array = list;
253+
mapptr->release_array = true;
253254
mapptr->handler = &php_dom_obj_map_nodeset;
254255
}
255256
}

ext/dom/php_dom.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1545,8 +1545,11 @@ void dom_nnodemap_objects_free_storage(zend_object *object) /* {{{ */
15451545
if (objmap->local_lower) {
15461546
zend_string_release(objmap->local_lower);
15471547
}
1548-
if (!Z_ISUNDEF(objmap->baseobj_zv)) {
1549-
zval_ptr_dtor(&objmap->baseobj_zv);
1548+
if (objmap->release_array) {
1549+
zend_array_release(objmap->array);
1550+
}
1551+
if (objmap->baseobj) {
1552+
OBJ_RELEASE(&objmap->baseobj->std);
15501553
}
15511554
xmlDictFree(objmap->dict);
15521555
efree(objmap);

ext/dom/xpath.c

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -234,15 +234,6 @@ PHP_METHOD(DOMXPath, registerNamespace)
234234
}
235235
/* }}} */
236236

237-
static void dom_xpath_iter(zval *baseobj, dom_object *intern) /* {{{ */
238-
{
239-
dom_nnodemap_object *mapptr = (dom_nnodemap_object *) intern->ptr;
240-
241-
ZVAL_COPY_VALUE(&mapptr->baseobj_zv, baseobj);
242-
mapptr->handler = &php_dom_obj_map_nodeset;
243-
}
244-
/* }}} */
245-
246237
static void php_xpath_eval(INTERNAL_FUNCTION_PARAMETERS, int type, bool modern) /* {{{ */
247238
{
248239
zval *context = NULL;
@@ -335,6 +326,7 @@ static void php_xpath_eval(INTERNAL_FUNCTION_PARAMETERS, int type, bool modern)
335326
{
336327
xmlNodeSetPtr nodesetp;
337328
zval retval;
329+
bool release_array = false;
338330

339331
if (xpathobjp->type == XPATH_NODESET && NULL != (nodesetp = xpathobjp->nodesetval) && nodesetp->nodeNr) {
340332
array_init_size(&retval, nodesetp->nodeNr);
@@ -369,12 +361,18 @@ static void php_xpath_eval(INTERNAL_FUNCTION_PARAMETERS, int type, bool modern)
369361
}
370362
add_next_index_zval(&retval, &child);
371363
}
364+
release_array = true;
372365
} else {
373366
ZVAL_EMPTY_ARRAY(&retval);
374367
}
368+
375369
object_init_ex(return_value, dom_get_nodelist_ce(modern));
376370
nodeobj = Z_DOMOBJ_P(return_value);
377-
dom_xpath_iter(&retval, nodeobj);
371+
dom_nnodemap_object *mapptr = nodeobj->ptr;
372+
373+
mapptr->array = Z_ARR(retval);
374+
mapptr->release_array = release_array;
375+
mapptr->handler = &php_dom_obj_map_nodeset;
378376
break;
379377
}
380378

0 commit comments

Comments
 (0)