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 ) ; } // Handle overwriting inherited. // %OPT% Keep sorted? (By expanded-name rather than by doc order...) // Downside: Would require insertElementAt if not found, // which has recopying costs. But these are generally short lists... int newEType = _exptype ( namespaceNodeIndex ) ; for ( int i = nsList . size ( ) - 1 ; i >= 0 ; -- i ) { if ( newEType == getExpandedTypeID ( nsList . elementAt ( i ) ) ) { nsList . setElementAt ( makeNodeHandle ( namespaceNodeIndex ) , i ) ; return ; } } nsList . addElement ( makeNodeHandle ( namespaceNodeIndex ) ) ; }
Build table of namespace declaration locations during DTM construction . Table is a Vector of SuballocatedIntVectors containing the namespace node HANDLES declared at that ID plus an SuballocatedIntVector of the element node INDEXES at which these declarations appeared .