[libxml2] Avoid extra processing on entities



commit a3f1e3e5712257fd279917a9158278534e8f4b72
Author: Daniel Veillard <veillard redhat com>
Date:   Mon Mar 11 13:57:53 2013 +0800

    Avoid extra processing on entities
    
    If an entity has already been checked for correctness no
    need to check it on every reference

 SAX2.c            |    6 ++++--
 parser.c          |    8 ++++++--
 result/att11.sax  |    2 --
 result/att11.sax2 |    2 --
 4 files changed, 10 insertions(+), 8 deletions(-)
---
diff --git a/SAX2.c b/SAX2.c
index 3eea39a..ce7a5d6 100644
--- a/SAX2.c
+++ b/SAX2.c
@@ -591,6 +591,7 @@ xmlSAX2GetEntity(void *ctx, const xmlChar *name)
         * parse the external entity
         */
        xmlNodePtr children;
+       unsigned long oldnbent = ctxt->nbentities;
 
         val = xmlParseCtxtExternalEntity(ctxt, ret->URI,
                                         ret->ExternalID, &children);
@@ -603,8 +604,9 @@ xmlSAX2GetEntity(void *ctx, const xmlChar *name)
            return(NULL);
        }
        ret->owner = 1;
-       if (ret->checked == 0)
-           ret->checked = 1;
+       if (ret->checked == 0) {
+           ret->checked = ctxt->nbentities - oldnbent + 1;
+       }
     }
     return(ret);
 }
diff --git a/parser.c b/parser.c
index ddf3b5b..362186b 100644
--- a/parser.c
+++ b/parser.c
@@ -4044,9 +4044,13 @@ xmlParseAttValueComplex(xmlParserCtxtPtr ctxt, int *attlen, int normalize) {
                     * entities problems
                     */
                    if ((ent->etype != XML_INTERNAL_PREDEFINED_ENTITY) &&
-                       (ent->content != NULL)) {
+                       (ent->content != NULL) && (ent->checked == 0)) {
+                       unsigned long oldnbent = ctxt->nbentities;
+
                        rep = xmlStringDecodeEntities(ctxt, ent->content,
                                                  XML_SUBSTITUTE_REF, 0, 0, 0);
+
+                       ent->checked = ctxt->nbentities - oldnbent + 1;
                        if (rep != NULL) {
                            xmlFree(rep);
                            rep = NULL;
@@ -7213,7 +7217,7 @@ xmlParseReference(xmlParserCtxtPtr ctxt) {
         * Store the number of entities needing parsing for this entity
         * content and do checkings
         */
-       ent->checked = ctxt->nbentities - oldnbent;
+       ent->checked = ctxt->nbentities - oldnbent + 1;
        if (ret == XML_ERR_ENTITY_LOOP) {
            xmlFatalErr(ctxt, XML_ERR_ENTITY_LOOP, NULL);
            xmlFreeNodeList(list);
diff --git a/result/att11.sax b/result/att11.sax
index 67dcf22..52d2861 100644
--- a/result/att11.sax
+++ b/result/att11.sax
@@ -12,9 +12,7 @@ SAX.externalSubset(attributes, , )
 SAX.getEntity(ent)
 SAX.getEntity(recursive)
 SAX.getEntity(ent)
-SAX.getEntity(recursive)
 SAX.getEntity(ent)
-SAX.getEntity(recursive)
 SAX.startElement(attributes, nmtoken=' &ent;   &ent; &ent; ', nmtokens=' Test
      this  normalization ')
 SAX.endElement(attributes)
diff --git a/result/att11.sax2 b/result/att11.sax2
index 859a970..3e8cfd9 100644
--- a/result/att11.sax2
+++ b/result/att11.sax2
@@ -12,9 +12,7 @@ SAX.externalSubset(attributes, , )
 SAX.getEntity(ent)
 SAX.getEntity(recursive)
 SAX.getEntity(ent)
-SAX.getEntity(recursive)
 SAX.getEntity(ent)
-SAX.getEntity(recursive)
 SAX.startElementNs(attributes, NULL, NULL, 0, 2, 0, nmtoken='&ent...', 17, nmtokens='Test...', 25)
 SAX.endElementNs(attributes, NULL, NULL)
 SAX.endDocument()


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]