From d3e7f34333f227b88eab2681f33660a80337b8e1 Mon Sep 17 00:00:00 2001 From: Dmitry Selyutin Date: Fri, 9 Jun 2023 21:27:57 +0300 Subject: [PATCH] insndb/core: introduce Records type --- src/openpower/insndb/core.py | 18 ++++++++++++++++-- src/openpower/insndb/db.py | 4 +++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/openpower/insndb/core.py b/src/openpower/insndb/core.py index 5472502f..26e3c1a9 100644 --- a/src/openpower/insndb/core.py +++ b/src/openpower/insndb/core.py @@ -3720,6 +3720,19 @@ class SVP64Database: return None +class Records(tuple): + def __new__(cls, records): + return super().__new__(cls, sorted(records)) + + def subnodes(self, match=None): + if match is None: + match = lambda subnode: True + + for record in self: + if match(record): + yield record + + class Database(Node): def __init__(self, root): root = _pathlib.Path(root) @@ -3748,7 +3761,7 @@ class Database(Node): names[record.name] = record opcodes[section][record.PO].add(record) - self.__db = sorted(db) + self.__db = Records(db) self.__names = dict(sorted(names.items())) self.__opcodes = dict(sorted(opcodes.items())) @@ -3758,7 +3771,8 @@ class Database(Node): if match is None: match = lambda subnode: True - yield from filter(match, self) + if match(self.__db): + yield self.__db def __repr__(self): return repr(self.__db) diff --git a/src/openpower/insndb/db.py b/src/openpower/insndb/db.py index 2fce21b1..33586152 100644 --- a/src/openpower/insndb/db.py +++ b/src/openpower/insndb/db.py @@ -10,6 +10,7 @@ from openpower.insndb.core import ( Database, Extra, Record, + Records, Visitor, visit, ) @@ -138,6 +139,7 @@ def main(): visitor = commands[command][0]() db = Database(find_wiki_dir()) + records = next(db.subnodes(match=lambda node: isinstance(node, Records))) if command in ("list",): match = None else: @@ -145,7 +147,7 @@ def main(): def match(record): return (isinstance(record, Record) and (record.name == insn)) - for node in db.subnodes(match=match): + for node in records.subnodes(match=match): visit(visitor=visitor, node=node) -- 2.30.2