Skip to content

Commit 6de0486

Browse files
committed
Express php_dom_libxml_notation_iter() using php_dom_libxml_hash_iter()
1 parent f02fd58 commit 6de0486

File tree

1 file changed

+8
-26
lines changed

1 file changed

+8
-26
lines changed

ext/dom/dom_iterators.c

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -31,27 +31,20 @@ struct _nodeIterator {
3131
xmlNode *node;
3232
};
3333

34-
typedef struct _notationIterator notationIterator;
35-
struct _notationIterator {
36-
int cur;
37-
int index;
38-
xmlNotation *notation;
39-
};
40-
4134
/* Function pointer typedef changed in 2.9.8, see https://github.com/GNOME/libxml2/commit/e03f0a199a67017b2f8052354cf732b2b4cae787 */
4235
#if LIBXML_VERSION >= 20908
4336
static void itemHashScanner (void *payload, void *data, const xmlChar *name) /* {{{ */
4437
#else
4538
static void itemHashScanner (void *payload, void *data, xmlChar *name)
4639
#endif
4740
{
48-
nodeIterator *priv = (nodeIterator *)data;
41+
nodeIterator *priv = data;
4942

50-
if(priv->cur < priv->index) {
43+
if (priv->cur < priv->index) {
5144
priv->cur++;
5245
} else {
53-
if(priv->node == NULL) {
54-
priv->node = (xmlNode *)payload;
46+
if (priv->node == NULL) {
47+
priv->node = payload;
5548
}
5649
}
5750
}
@@ -104,22 +97,11 @@ xmlNode *php_dom_libxml_hash_iter(xmlHashTable *ht, int index) /* {{{ */
10497

10598
xmlNode *php_dom_libxml_notation_iter(xmlHashTable *ht, int index) /* {{{ */
10699
{
107-
notationIterator *iter;
108-
xmlNotation *notep = NULL;
109-
int htsize;
110-
111-
if ((htsize = xmlHashSize(ht)) > 0 && index < htsize) {
112-
iter = emalloc(sizeof(notationIterator));
113-
iter->cur = 0;
114-
iter->index = index;
115-
iter->notation = NULL;
116-
xmlHashScan(ht, itemHashScanner, iter);
117-
notep = iter->notation;
118-
efree(iter);
119-
return create_notation(notep->name, notep->PublicID, notep->SystemID);
120-
} else {
121-
return NULL;
100+
xmlNotation *notation = (xmlNotation *) php_dom_libxml_hash_iter(ht, index);
101+
if (notation != NULL) {
102+
return create_notation(notation->name, notation->PublicID, notation->SystemID);
122103
}
104+
return NULL;
123105
}
124106
/* }}} */
125107

0 commit comments

Comments
 (0)