[Expat-checkins] expat/lib xmlparse.c,1.78,1.79
Fred L. Drake
fdrake@users.sourceforge.net
Tue, 27 Aug 2002 14:55:21 -0700
Update of /cvsroot/expat/expat/lib
In directory usw-pr-cvs1:/tmp/cvs-serv31254
Modified Files:
xmlparse.c
Log Message:
Added & elaborated some comments about the structures maintained to
store tag information.
Index: xmlparse.c
===================================================================
RCS file: /cvsroot/expat/expat/lib/xmlparse.c,v
retrieving revision 1.78
retrieving revision 1.79
diff -u -d -r1.78 -r1.79
--- xmlparse.c 27 Aug 2002 21:09:14 -0000 1.78
+++ xmlparse.c 27 Aug 2002 21:55:19 -0000 1.79
@@ -148,13 +148,26 @@
int prefixLen;
} TAG_NAME;
+/* TAG represents an open element.
+ The name of the element is stored in both the document and API
+ encodings. The memory buffer 'buf' is a separately-allocated
+ memory area which stores the name. During the XML_Parse()/
+ XMLParseBuffer() when the element is open, the memory for the 'raw'
+ version of the name (in the document encoding) is shared with the
+ document buffer. If the element is open across calls to
+ XML_Parse()/XML_ParseBuffer(), the buffer is re-allocated to
+ contain the 'raw' name as well.
+
+ A parser re-uses these structures, maintaining a list of allocated
+ TAG objects in a free list.
+*/
typedef struct tag {
- struct tag *parent;
- const char *rawName;
+ struct tag *parent; /* parent of this element */
+ const char *rawName; /* tagName in the original encoding */
int rawNameLength;
- TAG_NAME name;
- char *buf;
- char *bufEnd;
+ TAG_NAME name; /* tagName in the API encoding */
+ char *buf; /* buffer for name components */
+ char *bufEnd; /* end of the buffer */
BINDING *bindings;
} TAG;
@@ -1622,7 +1635,11 @@
int bufSize;
int nameLen = sizeof(XML_Char) * (tag->name.strLen + 1);
char *rawNameBuf = tag->buf + nameLen;
- /* Stop if already stored. */
+ /* Stop if already stored. Since tagStack is a stack, we can stop
+ at the first entry that has already been copied; everything
+ below it in the stack is already been accounted for in a
+ previous call to this function.
+ */
if (tag->rawName == rawNameBuf)
break;
/* For re-use purposes we need to ensure that the