bug 155578, refactor XSLTProcessor, landing trivial parts to make diff usefull. Function reordering in XSLTProcessor, txExpandedNameMap::remove, r=sicking, sr=bz

git-svn-id: svn://10.0.0.236/trunk@128449 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
axel%pike.org
2002-08-29 08:34:48 +00:00
parent adfb73782f
commit 4befb464f0
5 changed files with 979 additions and 918 deletions

View File

@@ -13,4 +13,4 @@ iframe {
vbox.hidden {
display: none;
}
}

View File

@@ -42,22 +42,16 @@
const int kTxExpandedNameMapAllocSize = 16;
txExpandedNameMap::txExpandedNameMap(MBool aOwnsValues) :
mItems(0), mItemCount(0), mOwnsValues(aOwnsValues)
mItems(0), mItemCount(0), mBufferCount(0), mOwnsValues(aOwnsValues)
{
}
txExpandedNameMap::~txExpandedNameMap()
{
int i;
for (i = 0; i < mItemCount; ++i) {
TX_IF_RELEASE_ATOM(mItems[i].mLocalName);
if (mOwnsValues)
delete mItems[i].mValue;
}
delete [] mItems;
clear();
}
/*
/**
* Adds an item, if an item with this key already exists an error is
* returned
* @param aKey key for item to add
@@ -70,17 +64,20 @@ nsresult txExpandedNameMap::add(const txExpandedName& aKey, TxObject* aValue)
// Check if there already is an item with this key
for (i = 0; i < mItemCount; ++i) {
if (mItems[i].mLocalName == aKey.mLocalName &&
mItems[i].mNamespaceID == aKey.mNamespaceID)
mItems[i].mNamespaceID == aKey.mNamespaceID) {
return NS_ERROR_FAILURE;
}
}
// Allocate a new array if needed
if (mItemCount % kTxExpandedNameMapAllocSize == 0) {
if (mBufferCount == mItemCount) {
MapItem* newItems = new MapItem[mItemCount +
kTxExpandedNameMapAllocSize];
if (!newItems)
if (!newItems) {
return NS_ERROR_OUT_OF_MEMORY;
}
mBufferCount += kTxExpandedNameMapAllocSize;
memcpy(newItems, mItems, mItemCount * sizeof(MapItem));
delete [] mItems;
mItems = newItems;
@@ -95,7 +92,7 @@ nsresult txExpandedNameMap::add(const txExpandedName& aKey, TxObject* aValue)
return NS_OK;
}
/*
/**
* Sets an item, if an item with this key already exists it is overwritten
* with the new value
* @param aKey key for item to set
@@ -109,20 +106,23 @@ nsresult txExpandedNameMap::set(const txExpandedName& aKey, TxObject* aValue)
for (i = 0; i < mItemCount; ++i) {
if (mItems[i].mLocalName == aKey.mLocalName &&
mItems[i].mNamespaceID == aKey.mNamespaceID) {
if (mOwnsValues)
if (mOwnsValues) {
delete mItems[i].mValue;
}
mItems[i].mValue = aValue;
return NS_OK;
}
}
// Allocate a new array if needed
if (mItemCount % kTxExpandedNameMapAllocSize == 0) {
if (mBufferCount == mItemCount) {
MapItem* newItems = new MapItem[mItemCount +
kTxExpandedNameMapAllocSize];
if (!newItems)
if (!newItems) {
return NS_ERROR_OUT_OF_MEMORY;
}
mBufferCount += kTxExpandedNameMapAllocSize;
memcpy(newItems, mItems, mItemCount * sizeof(MapItem));
delete [] mItems;
mItems = newItems;
@@ -137,7 +137,7 @@ nsresult txExpandedNameMap::set(const txExpandedName& aKey, TxObject* aValue)
return NS_OK;
}
/*
/**
* Gets an item
* @param aKey key for item to get
* @return item with specified key, or null if no such item exists
@@ -147,8 +147,55 @@ TxObject* txExpandedNameMap::get(const txExpandedName& aKey)
int i;
for (i = 0; i < mItemCount; ++i) {
if (mItems[i].mLocalName == aKey.mLocalName &&
mItems[i].mNamespaceID == aKey.mNamespaceID)
mItems[i].mNamespaceID == aKey.mNamespaceID) {
return mItems[i].mValue;
}
}
return 0;
}
/**
* Removes an item, deleting it if the map owns the values
* @param aKey key for item to remove
* @return item with specified key, or null if it has been deleted
* or no such item exists
*/
TxObject* txExpandedNameMap::remove(const txExpandedName& aKey)
{
TxObject* value = 0;
int i;
for (i = 0; i < mItemCount; ++i) {
if (mItems[i].mLocalName == aKey.mLocalName &&
mItems[i].mNamespaceID == aKey.mNamespaceID) {
TX_IF_RELEASE_ATOM(mItems[i].mLocalName);
if (mOwnsValues) {
delete mItems[i].mValue;
}
else {
value = mItems[i].mValue;
}
--mItemCount;
if (i != mItemCount) {
memcpy(&mItems[i], &mItems[mItemCount], sizeof(MapItem));
}
}
}
return value;
}
/**
* Clears the items
*/
void txExpandedNameMap::clear()
{
int i;
for (i = 0; i < mItemCount; ++i) {
TX_IF_RELEASE_ATOM(mItems[i].mLocalName);
if (mOwnsValues) {
delete mItems[i].mValue;
}
}
delete [] mItems;
mItemCount = 0;
mBufferCount = 0;
}

View File

@@ -50,7 +50,7 @@ public:
~txExpandedNameMap();
/*
/**
* Adds an item, if an item with this key already exists an error is
* returned
* @param aKey key for item to add
@@ -59,7 +59,7 @@ public:
*/
nsresult add(const txExpandedName& aKey, TxObject* aValue);
/*
/**
* Sets an item, if an item with this key already exists it is overwritten
* with the new value
* @param aKey key for item to set
@@ -68,13 +68,26 @@ public:
*/
nsresult set(const txExpandedName& aKey, TxObject* aValue);
/*
/**
* Gets an item
* @param aKey key for item to get
* @return item with specified key, or null if no such item exists
*/
TxObject* get(const txExpandedName& aKey);
/**
* Removes an item, deleting it if the map owns the values
* @param aKey key for item to remove
* @return item with specified key, or null if it has been deleted
* or no such item exists
*/
TxObject* remove(const txExpandedName& aKey);
/**
* Clears the items
*/
void clear();
class iterator {
public:
iterator(txExpandedNameMap& aMap) : mMap(aMap),
@@ -117,7 +130,7 @@ private:
};
MapItem* mItems;
int mItemCount;
int mItemCount, mBufferCount;
MBool mOwnsValues;
};

File diff suppressed because it is too large Load Diff

View File

@@ -252,18 +252,6 @@ private:
*/
Expr* mNodeExpr;
/*
* Processes the xsl:with-param child elements of the given xsl action.
* @param aAction the action node that takes parameters (xsl:call-template
* or xsl:apply-templates
* @param aContext the current context node
* @param aMap map to place parsed variables in
* @param aPs the current ProcessorState
* @return errorcode
*/
nsresult processParameters(Element* aAction, Node* aContext,
txVariableMap* aMap, ProcessorState* aPs);
#ifdef TX_EXE
/**
* Parses the contents of data, and returns the type and href psuedo attributes
@@ -275,6 +263,11 @@ private:
const String& mode,
ProcessorState* ps);
/*
* Copy a node. For document nodes, copy the children.
*/
void copyNode(Node* aNode, ProcessorState* aPs);
void processAction(Node* aNode, Node* aXsltAction, ProcessorState* aPs);
/**
@@ -295,24 +288,12 @@ private:
Element* aXslElement,
ProcessorState* aPs);
/*
* Processes the specified template using the given context,
* ProcessorState, and parameters.
* @param aContext the current context node
* @param aTemplate the node in the xslt document that contains the
* template
* @param aParams map with parameters to the template
* @param aPs the current ProcessorState
*/
void processTemplate(Node* aContext, Node* aTemplate,
txVariableMap* aParams, ProcessorState* aPs);
void processChildrenAsValue(Node* aNode,
Element* aElement,
ProcessorState* aPs,
MBool aOnlyText,
String& aValue);
void processMatchedTemplate(Node* aXslTemplate,
Node* aNode,
txVariableMap* aParams,
const txExpandedName& aMode,
ProcessorState::ImportFrame* aFrame,
ProcessorState* aPs);
/**
* Invokes the default template for the specified node
* @param node context node
@@ -323,16 +304,6 @@ private:
ProcessorState* ps,
const txExpandedName& mode);
void processStylesheet(Document* aSource,
Document* aStylesheet,
txListIterator* aImportFrame,
ProcessorState* aPs);
void processTopLevel(Document* aSource,
Element* aStylesheet,
txListIterator* importFrame,
ProcessorState* aPs);
/*
* Processes an include or import stylesheet
* @param aHref URI of stylesheet to process
@@ -345,6 +316,47 @@ private:
txListIterator* aImportFrame,
ProcessorState* aPs);
void processMatchedTemplate(Node* aXslTemplate,
Node* aNode,
txVariableMap* aParams,
const txExpandedName& aMode,
ProcessorState::ImportFrame* aFrame,
ProcessorState* aPs);
/*
* Processes the xsl:with-param child elements of the given xsl action.
* @param aAction the action node that takes parameters (xsl:call-template
* or xsl:apply-templates
* @param aContext the current context node
* @param aMap map to place parsed variables in
* @param aPs the current ProcessorState
* @return errorcode
*/
nsresult processParameters(Element* aAction, Node* aContext,
txVariableMap* aMap, ProcessorState* aPs);
void processStylesheet(Document* aSource,
Document* aStylesheet,
txListIterator* aImportFrame,
ProcessorState* aPs);
/*
* Processes the specified template using the given context,
* ProcessorState, and parameters.
* @param aContext the current context node
* @param aTemplate the node in the xslt document that contains the
* template
* @param aParams map with parameters to the template
* @param aPs the current ProcessorState
*/
void processTemplate(Node* aContext, Node* aTemplate,
txVariableMap* aParams, ProcessorState* aPs);
void processTopLevel(Document* aSource,
Element* aStylesheet,
txListIterator* importFrame,
ProcessorState* aPs);
ExprResult* processVariable(Node* node, Element* xslVariable, ProcessorState* ps);
void startTransform(Node* aNode, ProcessorState* aPs);
@@ -361,19 +373,8 @@ private:
*/
void xslCopyOf(ExprResult* aExprResult, ProcessorState* aPs);
/*
* Copy a node. For document nodes, copy the children.
*/
void copyNode(Node* aNode, ProcessorState* aPs);
void startElement(ProcessorState* aPs, const String& aName, const PRInt32 aNsID);
void processChildrenAsValue(Node* aNode,
Element* aElement,
ProcessorState* aPs,
MBool aOnlyText,
String& aValue);
#ifdef TX_EXE
txStreamXMLEventHandler* mOutputHandler;
#else