FileDocCategorySizeDatePackage
Children.javaAPI DocAndroid 1.5 API3025Wed May 06 22:42:00 BST 2009android.sax

Children

public class Children extends Object
Contains element children. Using this class instead of HashMap results in measurably better performance.

Fields Summary
Child[]
children
Constructors Summary
Methods Summary
Elementget(java.lang.String uri, java.lang.String localName)
Looks up a child by name.

        int hash = uri.hashCode() * 31 + localName.hashCode();
        int index = hash & 15;

        Child current = children[index];
        if (current == null) {
            return null;
        } else {
            do {
                if (current.hash == hash
                        && current.uri.compareTo(uri) == 0
                        && current.localName.compareTo(localName) == 0) {
                    return current;
                }
                current = current.next;
            } while (current != null);

            return null;
        }
    
ElementgetOrCreate(Element parent, java.lang.String uri, java.lang.String localName)
Looks up a child by name and creates a new one if necessary.


                      
           
        int hash = uri.hashCode() * 31 + localName.hashCode();
        int index = hash & 15;

        Child current = children[index];
        if (current == null) {
            // We have no children in this bucket yet.
            current = new Child(parent, uri, localName, parent.depth + 1, hash);
            children[index] = current;
            return current;
        } else {
            // Search this bucket.
            Child previous;
            do {
                if (current.hash == hash
                        && current.uri.compareTo(uri) == 0
                        && current.localName.compareTo(localName) == 0) {
                    // We already have a child with that name.
                    return current;
                }

                previous = current;
                current = current.next;
            } while (current != null);

            // Add a new child to the bucket.
            current = new Child(parent, uri, localName, parent.depth + 1, hash);
            previous.next = current;
            return current;         
        }