private void AddAttribute(string prefix, string localName, string namespaceName)
{
int top = _attrCount++;
if (top == _attrStack.Length)
{
AttrName[] newStack = new AttrName[top * 2];
Array.Copy(_attrStack, newStack, top);
_attrStack = newStack;
}
_attrStack[top].Set(prefix, localName, namespaceName);
if (_attrCount < MaxAttrDuplWalkCount)
{
// check for duplicates
for (int i = 0; i < top; i++)
{
if (_attrStack[i].IsDuplicate(prefix, localName, namespaceName))
{
throw DupAttrException(prefix, localName);
}
}
}
else
{
// reached the threshold -> add all attributes to hash table
if (_attrCount == MaxAttrDuplWalkCount)
{
if (_attrHashTable == null)
{
_attrHashTable = new Dictionary<string, int>(_hasher);
}
Debug.Assert(_attrHashTable.Count == 0);
for (int i = 0; i < top; i++)
{
AddToAttrHashTable(i);
}
}
// add last attribute to hash table and check for duplicates
AddToAttrHashTable(top);
int prev = _attrStack[top].prev;
while (prev > 0)
{
// indexes are stored incremented by 1, 0 means no entry
prev--;
if (_attrStack[prev].IsDuplicate(prefix, localName, namespaceName))
{
throw DupAttrException(prefix, localName);
}
prev = _attrStack[prev].prev;
}
}
}