Skip to content

Commit

Permalink
odb: Add pointer caching to master terminal retrival
Browse files Browse the repository at this point in the history
Signed-off-by: Jan Bylicki <[email protected]>
  • Loading branch information
jbylicki committed Dec 11, 2024
1 parent a008522 commit e3df9ad
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
3 changes: 3 additions & 0 deletions src/odb/include/odb/dbObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ enum dbObjectType

class dbDatabase;

class dbMTerm;

class dbObject
{
public:
Expand All @@ -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;
Expand Down
21 changes: 12 additions & 9 deletions src/odb/src/db/dbITerm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 2 additions & 0 deletions src/odb/src/db/dbInst.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit e3df9ad

Please sign in to comment.