Project

Profile

Help

Revision 538c334c

Added by Michael Kay about 3 years ago

Minor performance tweak; eliminate a TODO.

View differences:

latest9.9/hej/net/sf/saxon/om/Chain.java
82 82
                    this.children.add(gv);
83 83
                }
84 84
            }
85
        } else {
86
            this.children = children;
87 85
        }
88 86
    }
89 87

  
90 88
    public Item<?> head() {
89
        if (extent != null) {
90
            return extent.isEmpty() ? null : extent.get(0);
91
        }
91 92
        for (GroundedValue<?> seq : children) {
92 93
            Item<?> head = seq.head();
93 94
            if (head != null) {
......
141 142
     * @return the n'th item if it exists, or null otherwise
142 143
     */
143 144
    public Item<?> itemAt(int n) {
144
        // TODO: avoid consolidating the chain beyond the required item
145
        consolidate();
146
        if (n >= 0 && n < extent.size()) {
147
            return extent.get(n);
145
        if (n == 0) {
146
            return head();
148 147
        } else {
149
            return null;
148
            consolidate();
149
            if (n >= 0 && n < extent.size()) {
150
                return extent.get(n);
151
            } else {
152
                return null;
153
            }
150 154
        }
151 155
    }
152 156

  

Also available in: Unified diff