* %REVIEW% Directly managed arrays rather than vectors?
* %REVIEW% Handles or IDs? Given usage, I think handles.
* */
protected void declareNamespaceInContext(int elementNodeIndex,int namespaceNodeIndex)
{
SuballocatedIntVector nsList=null;
if(m_namespaceDeclSets==null)
{
// First
m_namespaceDeclSetElements=new SuballocatedIntVector(32);
m_namespaceDeclSetElements.addElement(elementNodeIndex);
m_namespaceDeclSets=new Vector();
nsList=new SuballocatedIntVector(32);
m_namespaceDeclSets.addElement(nsList);
}
else
{
// Most recent. May be -1 (none) if DTM was pruned.
// %OPT% Is there a lastElement() method? Should there be?
int last=m_namespaceDeclSetElements.size()-1;
if(last>=0 && elementNodeIndex==m_namespaceDeclSetElements.elementAt(last))
{
nsList=(SuballocatedIntVector)m_namespaceDeclSets.elementAt(last);
}
}
if(nsList==null)
{
m_namespaceDeclSetElements.addElement(elementNodeIndex);
SuballocatedIntVector inherited =
findNamespaceContext(_parent(elementNodeIndex));
if (inherited!=null) {
// %OPT% Count-down might be faster, but debuggability may
// be better this way, and if we ever decide we want to
// keep this ordered by expanded-type...
int isize=inherited.size();
// Base the size of a new namespace list on the
// size of the inherited list - but within reason!
nsList=new SuballocatedIntVector(Math.max(Math.min(isize+16,2048),
32));
for(int i=0;i<isize;++i)
{
nsList.addElement(inherited.elementAt(i));
}
} else {
nsList=new SuballocatedIntVector(32);
}
m_namespaceDeclSets.addElement(nsList);
}