From 8874b94cd2e2086f4cefe026286e0f64cac6ec9a Mon Sep 17 00:00:00 2001 From: Daniel Veillard Date: Thu, 25 Aug 2005 13:19:21 +0000 Subject: added a parser XML_PARSE_COMPACT option to allocate small text nodes (less * HTMLparser.c parser.c SAX2.c debugXML.c tree.c valid.c xmlreader.c xmllint.c include/libxml/HTMLparser.h include/libxml/parser.h: added a parser XML_PARSE_COMPACT option to allocate small text nodes (less than 8 bytes on 32bits, less than 16bytes on 64bits) directly within the node, various changes to cope with this. * result/XPath/tests/* result/XPath/xptr/* result/xmlid/*: this slightly change the output Daniel --- SAX2.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'SAX2.c') diff --git a/SAX2.c b/SAX2.c index 241e90de..a73fa1fa 100644 --- a/SAX2.c +++ b/SAX2.c @@ -1777,6 +1777,7 @@ xmlSAX2TextNode(xmlParserCtxtPtr ctxt, const xmlChar *str, int len) { xmlErrMemory(ctxt, "xmlSAX2Characters"); return(NULL); } + memset(ret, 0, sizeof(xmlNode)); /* * intern the formatting blanks found between tags, or the * very short strings @@ -1784,7 +1785,14 @@ xmlSAX2TextNode(xmlParserCtxtPtr ctxt, const xmlChar *str, int len) { if (ctxt->dictNames) { xmlChar cur = str[len]; - if ((len <= 3) && ((cur == '"') || (cur == '\'') || + if ((len < (int) (2 * sizeof(void *))) && + (ctxt->options & XML_PARSE_COMPACT)) { + /* store the string in the node overrithing properties and nsDef */ + xmlChar *tmp = (xmlChar *) &(ret->properties); + memcpy(tmp, str, len); + tmp[len] = 0; + intern = tmp; + } else if ((len <= 3) && ((cur == '"') || (cur == '\'') || ((cur == '<') && (str[len + 1] != '!')))) { intern = xmlDictLookup(ctxt->dict, str, len); } else if (IS_BLANK_CH(*str) && (len < 60) && (cur == '<') && @@ -1798,7 +1806,6 @@ xmlSAX2TextNode(xmlParserCtxtPtr ctxt, const xmlChar *str, int len) { } } skip: - memset(ret, 0, sizeof(xmlNode)); ret->type = XML_TEXT_NODE; ret->name = xmlStringText; @@ -2407,8 +2414,11 @@ xmlSAX2Characters(void *ctx, const xmlChar *ch, int len) * We try to minimaze realloc() uses and avoid copying * and recomputing length over and over. */ - if ((ctxt->nodemem == ctxt->nodelen + 1) && - (xmlDictOwns(ctxt->dict, lastChild->content))) { + if (lastChild->content == (xmlChar *)&(lastChild->properties)) { + lastChild->content = xmlStrdup(lastChild->content); + lastChild->properties = NULL; + } else if ((ctxt->nodemem == ctxt->nodelen + 1) && + (xmlDictOwns(ctxt->dict, lastChild->content))) { lastChild->content = xmlStrdup(lastChild->content); } if (ctxt->nodelen + len >= ctxt->nodemem) { -- cgit v1.2.3