--------------------- PatchSet 473 Date: 2002/12/24 10:28:25 Author: rbcollins Branch: esi Tag: (none) Log: use ELementList for esiSequence Members: src/ESI.cc:1.1.2.78->1.1.2.79 Index: squid3/src/ESI.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/ESI.cc,v retrieving revision 1.1.2.78 retrieving revision 1.1.2.79 diff -u -r1.1.2.78 -r1.1.2.79 --- squid3/src/ESI.cc 24 Dec 2002 09:53:35 -0000 1.1.2.78 +++ squid3/src/ESI.cc 24 Dec 2002 10:28:25 -0000 1.1.2.79 @@ -1,6 +1,6 @@ /* - * $Id: ESI.cc,v 1.1.2.78 2002/12/24 09:53:35 rbcollins Exp $ + * $Id: ESI.cc,v 1.1.2.79 2002/12/24 10:28:25 rbcollins Exp $ * * DEBUG: section 86 ESI processing * AUTHOR: Robert Collins @@ -232,6 +232,7 @@ ESIElement::Pointer &operator[](int); ESIElement::Pointer const &operator[](int)const; ESIElement::Pointer * elements; /* unprocessed or rendered nodes */ + void pop_front (size_t const); void push_back(ESIElement::Pointer &); size_t size() const; void setNULL (int start, int end); @@ -266,12 +267,8 @@ void makeUsableElements(esiSequence const &old, esiVarState &); Pointer makeUsable(esiTreeParentPtr, esiVarState &) const; -// ElementList elements; - ESIElement::Pointer * elements; /* unprocessed or rendered nodes */ - int allocedcount; - size_t allocedsize; - int elementcount; - int processedcount; + ElementList elements; /* unprocessed or rendered nodes */ + size_t processedcount; struct { int dovars:1; /* for esiVar */ } flags; @@ -280,12 +277,11 @@ esiSequence(esiSequence const &); private: static MemPool *Pool; - void NULLElements (int start, int end); esiTreeParentPtr parent; int elementIndex (ESIElement::Pointer anElement) const; bool mayFail_; bool failed; - esiProcessResult_t processOne(int, int); + esiProcessResult_t processOne(int, size_t); bool const provideIncrementalData; bool processing; }; @@ -1963,9 +1959,6 @@ esiSequence::~esiSequence () { debug (86,5)("esiSequence::~esiSequence %p\n", this); - NULLElements(0, elementcount); - if (elements) - memFreeBuf (allocedsize, elements); } void * @@ -1984,7 +1977,7 @@ } -esiSequence::esiSequence(esiTreeParentPtr aParent, bool incrementalFlag) : elements(NULL), parent (aParent), mayFail_(true), failed (false), provideIncrementalData (incrementalFlag), processing (false) +esiSequence::esiSequence(esiTreeParentPtr aParent, bool incrementalFlag) : elements(), parent (aParent), mayFail_(true), failed (false), provideIncrementalData (incrementalFlag), processing (false) { } @@ -2011,16 +2004,13 @@ */ assert (output->next == NULL); debug (86,5)("esiSequenceRender: rendering %d elements\n", processedcount); - for (int i = 0; i < processedcount; ++i) { + for (size_t i = 0; i < processedcount; ++i) { elements[i]->render(output); - NULLElements(i,i+1); + elements.setNULL(i,i+1); /* FIXME: pass a ESISegment ** ? */ output = output->tail(); } - if (processedcount) { - xmemmove (elements, &elements[processedcount], (elementcount - processedcount) * sizeof (ESIElement::Pointer)); - } - elementcount -= processedcount; + elements.pop_front (processedcount); processedcount = 0; assert (output->next == NULL); } @@ -2029,7 +2019,7 @@ esiSequence::finish() { debug (86,5) ("esiSequence::finish: %p is finished\n", this); - NULLElements(0,elementcount); + elements.setNULL(0, elements.size()); parent = NULL; } @@ -2049,7 +2039,7 @@ int index = elementIndex (source); assert (index >= 0); /* remove the current node */ - NULLElements(index, index+1); + elements.setNULL(index, index+1); /* create a literal */ esiLiteral *temp = new esiLiteral (data); /* insert the literal */ @@ -2070,35 +2060,30 @@ return false; } /* Tie literals together for efficiency */ - if (elementcount && dynamic_cast(element.getRaw()) && - dynamic_cast(elements[elementcount - 1].getRaw())) { - debug (86,5)("esiSequenceAdd: tying Literals %p and %p together\n", elements[elementcount - 1].getRaw(), + if (elements.size() && dynamic_cast(element.getRaw()) && + dynamic_cast(elements[elements.size() - 1].getRaw())) { + debug (86,5)("esiSequenceAdd: tying Literals %p and %p together\n", elements[elements.size() - 1].getRaw(), element.getRaw()); ESISegmentTransferList (((esiLiteral *)element.getRaw())->buffer, - ((esiLiteral *)elements[elementcount - 1].getRaw())->buffer); + ((esiLiteral *)elements[elements.size() - 1].getRaw())->buffer); return true; } - elements = (ESIElement::Pointer*)memReallocBuf (elements, ++elementcount * sizeof (ESIElement::Pointer), - &allocedsize); - assert (elements); - allocedcount = elementcount; - memset(&elements[elementcount - 1], '\0', sizeof (ESIElement::Pointer)); - elements[elementcount - 1] = element; - debug (86,3)("esiSequenceAdd: Added a new element, elements = %d\n", elementcount); + elements.push_back(element); + debug (86,3)("esiSequenceAdd: Added a new element, elements = %d\n", elements.size()); return true; } int esiSequence::elementIndex(ESIElement::Pointer anElement) const { - for (int i = 0; i < elementcount; ++i) + for (size_t i = 0; i < elements.size(); ++i) if (elements[i] == anElement) return i; return -1; } esiProcessResult_t -esiSequence::processOne(int dovars, int index) +esiSequence::processOne(int dovars, size_t index) { debug (86,5)("esiSequence::process %p about to process element[%d] %p\n", this, index, elements[index].getRaw()); switch (elements[index]->process(dovars)) { @@ -2134,7 +2119,6 @@ /* process as much of the list as we can, stopping only on * faliures */ - int i; esiProcessResult_t rv = ESI_PROCESS_COMPLETE; int dovars = inheritedVarsFlag; if (flags.dovars) @@ -2142,23 +2126,23 @@ debug (86,5)("esiSequence::process: Processing %p with%s variable processing\n", this, dovars ? "" : "out"); processing = true; - for (i = processedcount; i < elementcount; ++i) { + for (size_t i = processedcount; i < elements.size(); ++i) { esiProcessResult_t tempResult = processOne(dovars, i); if (rv < tempResult) rv = tempResult; if (rv == ESI_PROCESS_FAILED) { - NULLElements (0, elementcount); + elements.setNULL (0, elements.size()); failed = true; parent = NULL; processing = false; return rv; } } - assert (rv != ESI_PROCESS_COMPLETE || processedcount == elementcount); + assert (rv != ESI_PROCESS_COMPLETE || processedcount == elements.size()); if (rv == ESI_PROCESS_COMPLETE || rv == ESI_PROCESS_PENDING_WONTFAIL) wontFail(); - if (processedcount == elementcount || provideIncrementalData) { + if (processedcount == elements.size() || provideIncrementalData) { ESISegment::Pointer temp(new ESISegment); render (temp); if (temp->next.getRaw() || temp->len) @@ -2168,7 +2152,7 @@ } /* Depends on full parsing before processing */ - if (processedcount == elementcount) + if (processedcount == elements.size()) parent = NULL; debug (86,5)("esiSequence::process: %p completed\n", this); @@ -2177,19 +2161,6 @@ } void -esiSequence::NULLElements (int start, int end) -{ - assert (start >= 0 && start <= elementcount); - assert (end >= 0 && end <= elementcount); - for (int loopPosition = start; loopPosition < end; ++loopPosition) { - if (elements[loopPosition].getRaw()) - elements[loopPosition]->finish(); - debug (86,5)("esiSequence::NULLElements: Setting index %d, pointer %p to NULL\n", loopPosition, elements[loopPosition].getRaw()); - elements[loopPosition] = NULL; - } -} - -void esiSequence::fail (ESIElement *source) { failed = true; @@ -2199,7 +2170,7 @@ } debug (86,5)("esiSequence::fail: %p has failed.\n", this); parent->fail (this); - NULLElements(0, elementcount); + elements.setNULL(0, elements.size()); parent = NULL; } @@ -2208,16 +2179,12 @@ { flags.dovars = old.flags.dovars; parent = NULL; - elements = NULL; - elementcount = 0; - allocedcount = 0; - allocedsize = 0; } void esiSequence::makeCachableElements(esiSequence const &old) { - for (int counter = 0; counter < old.elementcount; ++counter) { + for (size_t counter = 0; counter < old.elements.size(); ++counter) { ESIElement::Pointer newElement = old.elements[counter]->makeCacheable(); if (newElement.getRaw()) assert (addElement(newElement)); @@ -2227,7 +2194,7 @@ void esiSequence::makeUsableElements(esiSequence const &old, esiVarState &newVarState) { - for (int counter = 0; counter < old.elementcount; ++counter) { + for (size_t counter = 0; counter < old.elements.size(); ++counter) { ESIElement::Pointer newElement = old.elements[counter]->makeUsable (parent, newVarState); if (newElement.getRaw()) assert (addElement(newElement)); @@ -2240,7 +2207,7 @@ debug (86,5)("esiSequence::makeCacheable: Making cachable sequence from %p\n", this); assert (processedcount == 0); assert (!failed); - if (elementcount == 0) { + if (elements.size() == 0) { debug (86,5)("esiSequence::makeCacheable: No elements in sequence %p, returning NULL\n", this); return NULL; } @@ -2257,7 +2224,7 @@ debug (86,5)("esiSequence::makeUsable: Creating usable Sequence\n"); assert (processedcount == 0); assert (!failed); - if (elementcount == 0) { + if (elements.size() == 0) { debug (86,5)("esiSequence::makeUsable: No elements in sequence %p, returning NULL\n", this); return NULL; } @@ -3583,6 +3550,7 @@ for (int loopPosition = start; loopPosition < end; ++loopPosition) { if (elements[loopPosition].getRaw()) elements[loopPosition]->finish(); + debug (86,5)("esiSequence::NULLElements: Setting index %d, pointer %p to NULL\n", loopPosition, elements[loopPosition].getRaw()); elements[loopPosition] = NULL; } } @@ -3660,7 +3628,7 @@ esiChoose::esiChoose(esiChoose const &old) : chosenelement(-1), otherwise (old.otherwise.getRaw() ? old.otherwise->makeCacheable() : NULL), parent (NULL) { - for (int counter = 0; counter < old.elements.elementcount; ++counter) { + for (size_t counter = 0; counter < old.elements.size(); ++counter) { ESIElement::Pointer newElement = old.elements[counter]->makeCacheable(); if (newElement.getRaw()) assert (addElement(newElement)); @@ -3688,11 +3656,8 @@ ElementList::~ElementList() { - int i; debug (86,5)("ElementList::~ElementList %p\n", this); - for (i = 0; i < elementcount; ++i) { - elements[i] = NULL; - } + setNULL(0, elementcount); if (elements) memFreeBuf (allocedsize, elements); } @@ -3710,12 +3675,22 @@ } void +ElementList::pop_front (size_t const count) +{ + if (!count) + return; + xmemmove (elements, &elements[count], (elementcount - count) * sizeof (ESIElement::Pointer)); + elementcount -= count; +} + +void ElementList::push_back(ESIElement::Pointer &newElement) { elements = (ESIElement::Pointer *)memReallocBuf (elements, ++elementcount * sizeof (ESIElement::Pointer), &allocedsize); assert (elements); allocedcount = elementcount; + memset(&elements[elementcount - 1], '\0', sizeof (ESIElement::Pointer)); elements[elementcount - 1] = newElement; }