xom-interest AT lists.ibiblio.org
Subject: XOM API for Processing XML with Java
List archive
Re: [XOM-interest] Possible ArrayList optimization
- From: "Bradley S. Huffman" <hip AT a.cs.okstate.edu>
- To: Elliotte Rusty Harold <elharo AT metalab.unc.edu>
- Cc: xom-interest AT lists.ibiblio.org
- Subject: Re: [XOM-interest] Possible ArrayList optimization
- Date: Mon, 12 May 2003 08:59:06 -0500
Elliotte Rusty Harold writes:
> At 8:10 PM -0500 5/9/03, Bradley S. Huffman wrote:
>
>
> >I'm assuming you mean spped when building from a SAX source. First in XOM,
> >get rid of the parent stack, it's not needed, you can call getParent() in
> >endElement(...).
>
> I don't see how that would work. getParent() returns null before I've
> added it to the parent. That's why I need the parent stack. I could
> move more work into endElement() but I'm not sure how that would help.
Something like this wouldn't work? (**warning** I just typed this in from
memory as a example, it has been tested)
Brad
*** XOMHandler.old Mon May 12 08:43:46 2003
--- XOMHandler.java Mon May 12 08:58:16 2003
***************
*** 40,46 ****
implements ContentHandler, LexicalHandler, DeclHandler, DTDHandler {
private Document document;
! private Stack parents;
private boolean inProlog;
private int position; // number of items currently in prolog
private Locator locator;
--- 40,46 ----
implements ContentHandler, LexicalHandler, DeclHandler, DTDHandler {
private Document document;
! private ParentNode parent;
private boolean inProlog;
private int position; // number of items currently in prolog
private Locator locator;
***************
*** 63,72 ****
}
public void startDocument() {
- parents = new Stack();
Element fauxRoot = new Element("fauxRoot");
document = factory.makeDocument(fauxRoot);
! parents.push(document);
inProlog = true;
position = 0;
buffer = new StringBuffer();
--- 63,71 ----
}
public void startDocument() {
Element fauxRoot = new Element("fauxRoot");
document = factory.makeDocument(fauxRoot);
! parent = document;
inProlog = true;
position = 0;
buffer = new StringBuffer();
***************
*** 75,81 ****
}
public void endDocument() {
! parents.pop();
}
public void startElement(String namespaceURI, String localName,
--- 74,80 ----
}
public void endDocument() {
! parent = parent.getParent();
}
public void startElement(String namespaceURI, String localName,
***************
*** 85,91 ****
int colon = qualifiedName.indexOf(':');
Element element = factory.makeElement(qualifiedName, namespaceURI);
element.setActualBaseURI(locator.getSystemId());
! ParentNode parent = (ParentNode) parents.peek();
if (parent instanceof Document) {
Document doc = (Document) parent;
doc.setRootElement(element);
--- 84,91 ----
int colon = qualifiedName.indexOf(':');
Element element = factory.makeElement(qualifiedName, namespaceURI);
element.setActualBaseURI(locator.getSystemId());
!
! // Add element to current parent
if (parent instanceof Document) {
Document doc = (Document) parent;
doc.setRootElement(element);
***************
*** 94,100 ****
else {
parent.appendChild(element);
}
! parents.push(element);
// Attach the attributes
for (int i = 0; i < attributes.getLength(); i++) {
--- 94,102 ----
else {
parent.appendChild(element);
}
!
! // Change current parent to new element.
! parent = element;
// Attach the attributes
for (int i = 0; i < attributes.getLength(); i++) {
***************
*** 157,163 ****
public void endElement(String namespaceURI, String localName, String
qualifiedName) {
flushText();
! parents.pop();
}
private StringBuffer buffer;
--- 159,167 ----
public void endElement(String namespaceURI, String localName, String
qualifiedName) {
flushText();
!
! // Change current parent to this element's parent.
! parent = parent.getParent();
}
private StringBuffer buffer;
***************
*** 170,176 ****
private void flushText() {
if (buffer.length() > 0) {
Text data = factory.makeText(buffer.toString());
- ParentNode parent = (ParentNode) parents.peek();
parent.appendChild(data);
buffer.setLength(0);
}
--- 174,179 ----
***************
*** 185,191 ****
flushText();
ProcessingInstruction instruction
= factory.makeProcessingInstruction(target, data);
- ParentNode parent = (ParentNode) parents.peek();
if (inProlog) {
parent.insertChild(position, instruction);
position++;
--- 188,193 ----
***************
*** 218,224 ****
String systemID) {
inDTD = true;
DocType doctype = new DocType(rootName, publicID, systemID);
- ParentNode parent = (ParentNode) parents.peek();
parent.insertChild(position, doctype);
position++;
this.doctype = doctype;
--- 220,225 ----
***************
*** 245,251 ****
if (!inDTD && !inExternalSubset) {
flushText();
Comment comment = factory.makeComment(new String(text, start,
length));
- ParentNode parent = (ParentNode) parents.peek();
if (inProlog) {
parent.insertChild(position, comment);
position++;
--- 246,251 ----
-
[XOM-interest] Possible ArrayList optimization,
Elliotte Rusty Harold, 05/09/2003
- Re: [XOM-interest] Possible ArrayList optimization, John Cowan, 05/09/2003
-
Re: [XOM-interest] Possible ArrayList optimization,
dirk bergstrom, 05/09/2003
-
Re: [XOM-interest] Possible ArrayList optimization,
Elliotte Rusty Harold, 05/09/2003
- Re: [XOM-interest] Possible ArrayList optimization, Elliotte Rusty Harold, 05/11/2003
-
Re: [XOM-interest] Possible ArrayList optimization,
Elliotte Rusty Harold, 05/09/2003
-
Re: [XOM-interest] Possible ArrayList optimization,
Bradley S. Huffman, 05/09/2003
- Re: [XOM-interest] Possible ArrayList optimization, Elliotte Rusty Harold, 05/10/2003
-
Re: [XOM-interest] Possible ArrayList optimization,
Elliotte Rusty Harold, 05/11/2003
-
Re: [XOM-interest] Possible ArrayList optimization,
Bradley S. Huffman, 05/12/2003
- Re: [XOM-interest] Possible ArrayList optimization, Elliotte Rusty Harold, 05/12/2003
-
Re: [XOM-interest] Possible ArrayList optimization,
Bradley S. Huffman, 05/12/2003
-
Re: [XOM-interest] Possible ArrayList optimization,
Janek Bogucki, 05/11/2003
-
Re: [XOM-interest] Possible ArrayList optimization,
Elliotte Rusty Harold, 05/12/2003
-
Re: [XOM-interest] Possible ArrayList optimization,
dirk bergstrom, 05/12/2003
-
Re: [XOM-interest] Possible ArrayList optimization,
Elliotte Rusty Harold, 05/13/2003
- Re: [XOM-interest] Possible ArrayList optimization, Karl Waclawek, 05/13/2003
-
Re: [XOM-interest] Possible ArrayList optimization,
Elliotte Rusty Harold, 05/13/2003
-
Re: [XOM-interest] Possible ArrayList optimization,
dirk bergstrom, 05/12/2003
-
Re: [XOM-interest] Possible ArrayList optimization,
Elliotte Rusty Harold, 05/12/2003
- <Possible follow-up(s)>
- RE: [XOM-interest] Possible ArrayList optimization, New, Cecil (GEAE), 05/13/2003
Archive powered by MHonArc 2.6.24.