From e3df9ad39a131f3b742460e2ace8c82d0c67cc4b Mon Sep 17 00:00:00 2001 From: Jan Bylicki Date: Mon, 18 Nov 2024 15:26:14 +0100 Subject: [PATCH] odb: Add pointer caching to master terminal retrival Signed-off-by: Jan Bylicki --- src/odb/include/odb/dbObject.h | 3 +++ src/odb/src/db/dbITerm.cpp | 21 ++++++++++++--------- src/odb/src/db/dbInst.cpp | 2 ++ 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/odb/include/odb/dbObject.h b/src/odb/include/odb/dbObject.h index 47676ee04c9..db493adb92d 100644 --- a/src/odb/include/odb/dbObject.h +++ b/src/odb/include/odb/dbObject.h @@ -176,6 +176,8 @@ enum dbObjectType class dbDatabase; +class dbMTerm; + class dbObject { public: @@ -190,6 +192,7 @@ class dbObject // not exported. They are for internal db convenience. _dbObject* getImpl(); const _dbObject* getImpl() const; + mutable dbMTerm* mterm_cache; protected: dbObject() = default; diff --git a/src/odb/src/db/dbITerm.cpp b/src/odb/src/db/dbITerm.cpp index fdf571b01a9..8f821954f3b 100644 --- a/src/odb/src/db/dbITerm.cpp +++ b/src/odb/src/db/dbITerm.cpp @@ -263,15 +263,18 @@ dbNet* dbITerm::getNet() dbMTerm* dbITerm::getMTerm() const { - _dbITerm* iterm = (_dbITerm*) this; - _dbBlock* block = (_dbBlock*) iterm->getOwner(); - _dbInst* inst = block->_inst_tbl->getPtr(iterm->_inst); - _dbInstHdr* inst_hdr = block->_inst_hdr_tbl->getPtr(inst->_inst_hdr); - _dbDatabase* db = iterm->getDatabase(); - _dbLib* lib = db->_lib_tbl->getPtr(inst_hdr->_lib); - _dbMaster* master = lib->_master_tbl->getPtr(inst_hdr->_master); - dbId<_dbMTerm> mterm = inst_hdr->_mterms[iterm->_flags._mterm_idx]; - return (dbMTerm*) master->_mterm_tbl->getPtr(mterm); + if (mterm_cache == nullptr) { + _dbITerm* iterm = (_dbITerm*) this; + _dbBlock* block = (_dbBlock*) iterm->getOwner(); + _dbInst* inst = block->_inst_tbl->getPtr(iterm->_inst); + _dbInstHdr* inst_hdr = block->_inst_hdr_tbl->getPtr(inst->_inst_hdr); + _dbDatabase* db = iterm->getDatabase(); + _dbLib* lib = db->_lib_tbl->getPtr(inst_hdr->_lib); + _dbMaster* master = lib->_master_tbl->getPtr(inst_hdr->_master); + dbId<_dbMTerm> mterm = inst_hdr->_mterms[iterm->_flags._mterm_idx]; + mterm_cache = (dbMTerm*) master->_mterm_tbl->getPtr(mterm); + } + return mterm_cache; } dbBTerm* dbITerm::getBTerm() diff --git a/src/odb/src/db/dbInst.cpp b/src/odb/src/db/dbInst.cpp index 31afab66b8d..1d6aff4446d 100644 --- a/src/odb/src/db/dbInst.cpp +++ b/src/odb/src/db/dbInst.cpp @@ -1362,6 +1362,7 @@ bool dbInst::swapMaster(dbMaster* new_master_) uint i; for (i = 0; i < cnt; ++i) { _dbITerm* it = block->_iterm_tbl->getPtr(inst->_iterms[i]); + it->mterm_cache = nullptr; uint old_idx = it->_flags._mterm_idx; it->_flags._mterm_idx = idx_map[old_idx]; } @@ -1458,6 +1459,7 @@ dbInst* dbInst::create(dbBlock* block_, uint i; for (i = 0; i < mterm_cnt; ++i) { _dbITerm* iterm = block->_iterm_tbl->create(); + iterm->mterm_cache = nullptr; inst->_iterms[i] = iterm->getOID(); iterm->_flags._mterm_idx = i; iterm->_inst = inst->getOID();