[Libre-soc-bugs] [Bug 1094] insndb instruction database visitor-walker is needed

bugzilla-daemon at libre-soc.org bugzilla-daemon at libre-soc.org
Tue Jun 20 20:35:00 BST 2023


https://bugs.libre-soc.org/show_bug.cgi?id=1094

--- Comment #214 from Jacob Lifshay <programmerjake at gmail.com> ---
(In reply to Jacob Lifshay from comment #212)
> also, if you use a list for path, and just push and pop indexes from the end
> rather than making a new object every time then you don't need to constantly
> allocate as much, which is a bit faster.

e.g.:
class Walker(...):
    def __init__(self):
        self.path = []
        self.path_kind = []

    @Hook(list, tuple)
    def walk_seq(self, value):
        for i, v in enumerate(value):
            self.path.append(i)
            self.path_kind.append(Index)
            yield (v, self.path, self.path_kind, value)
            yield from self(v)
            self.path.pop()
            self.path_kind.pop()

    @Hook(dict)
    def walk_dict(self, value):
        for k, v in value.items():
            self.path.append(k)
            self.path_kind.append(GetKey)
            yield (k, self.path, self.path_kind, value)
            yield from self(k)
            self.path_kind[-1] = Index
            yield (v, self.path, self.path_kind, value)
            yield from self(v)
            self.path.pop()
            self.path_kind.pop()

    ...

-- 
You are receiving this mail because:
You are on the CC list for the bug.


More information about the libre-soc-bugs mailing list