@@ -32,10 +32,7 @@ typedef struct _dom_token_list_it {
32
32
zend_object_iterator it ;
33
33
/* Store the hash position here to allow multiple (e.g. nested) iterations of the same token list. */
34
34
HashPosition pos ;
35
- /* Modification tracking: when the token list changes, we increment its counter.
36
- * When this counter no longer matches the counter of the token list, we know that it has changed and we
37
- * have to update the iteration index. */
38
- size_t modification_nr ;
35
+ php_libxml_cache_tag cache_tag ;
39
36
} dom_token_list_it ;
40
37
41
38
/* https://infra.spec.whatwg.org/#ascii-whitespace */
@@ -137,7 +134,7 @@ static void dom_token_list_update(dom_token_list_object *intern)
137
134
const xmlAttr * attr = dom_token_list_get_attr (intern );
138
135
HashTable * token_set = TOKEN_LIST_GET_SET (intern );
139
136
140
- intern -> modification_nr ++ ;
137
+ php_libxml_invalidate_cache_tag ( & intern -> cache_tag ) ;
141
138
142
139
/* 1. If the associated element does not have an associated attribute and token set is empty, then return. */
143
140
if (attr == NULL && zend_hash_num_elements (token_set ) == 0 ) {
@@ -182,7 +179,7 @@ static void dom_token_list_ensure_set_up_to_date(dom_token_list_object *intern)
182
179
183
180
/* xmlStrEqual will automatically handle equality rules of NULL vs "" (etc) correctly. */
184
181
if (!xmlStrEqual (value , (const xmlChar * ) intern -> cached_string )) {
185
- intern -> modification_nr ++ ;
182
+ php_libxml_invalidate_cache_tag ( & intern -> cache_tag ) ;
186
183
efree (intern -> cached_string );
187
184
HashTable * token_set = TOKEN_LIST_GET_SET (intern );
188
185
zend_hash_destroy (token_set );
@@ -199,7 +196,7 @@ void dom_token_list_ctor(dom_token_list_object *intern, dom_object *element_obj)
199
196
element_obj -> document -> refcount ++ ;
200
197
intern -> dom .document = element_obj -> document ;
201
198
202
- intern -> modification_nr = 0 ;
199
+ intern -> cache_tag . modification_nr = 0 ;
203
200
204
201
ALLOC_HASHTABLE (TOKEN_LIST_GET_SET (intern ));
205
202
HashTable * token_set = TOKEN_LIST_GET_SET (intern );
@@ -642,7 +639,7 @@ static void dom_token_list_it_get_current_key(zend_object_iterator *iter, zval *
642
639
643
640
dom_token_list_ensure_set_up_to_date (object );
644
641
645
- if (UNEXPECTED (object -> modification_nr != iterator -> modification_nr )) {
642
+ if (UNEXPECTED (php_libxml_is_cache_tag_stale ( & object -> cache_tag , & iterator -> cache_tag ) )) {
646
643
iter -> index = 0 ;
647
644
HashPosition pos ;
648
645
HashTable * token_set = TOKEN_LIST_GET_SET (object );
@@ -704,7 +701,7 @@ zend_object_iterator *dom_token_list_get_iterator(zend_class_entry *ce, zval *ob
704
701
ZVAL_OBJ_COPY (& iterator -> it .data , Z_OBJ_P (object ));
705
702
706
703
iterator -> it .funcs = & dom_token_list_it_funcs ;
707
- iterator -> modification_nr = intern -> modification_nr ;
704
+ iterator -> cache_tag = intern -> cache_tag ;
708
705
709
706
return & iterator -> it ;
710
707
}
0 commit comments