A more efficient way to collect nodes of a specified type than
        collect_nodes.

def collect_by_type(self, typ):
        '''A more efficient way to collect nodes of a specified type than
        collect_nodes.
        '''
        nodes = []
        if isinstance(self, typ):
            nodes.append(self)
        for c in self:
            nodes.extend(c.collect_by_type(typ))
        return nodes