Skip to content

Commit 50c72b8

Browse files
committed
ai perf: low risk
1 parent f65a814 commit 50c72b8

File tree

6 files changed

+15
-11
lines changed

6 files changed

+15
-11
lines changed

src/domino/Domino.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ bool Domino::deduceStateSelf_(const Event& aValidEv, bool aPrevType) const noexc
5252
void Domino::effect_() noexcept
5353
{
5454
for (auto&& ev : effectEVs_)
55-
if (state(ev) == true) // avoid multi-change
55+
if (states_[ev] == true) // avoid multi-change; skip bounds check since effectEVs_ are validated
5656
effect_(ev);
5757
effectEVs_.clear();
5858
}

src/domino/WbasicDatDom.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ bool WbasicDatDom<aDominoType>::wbasic_replaceDataOK(const Domino::EvName& aEvNa
115115
template<typename aDominoType>
116116
bool WbasicDatDom<aDominoType>::wrCtrlOk(const Domino::EvName& aEvName, const bool aNewState) noexcept
117117
{
118-
if (aDominoType::getData(aEvName).get() != nullptr)
118+
if (aDominoType::getData(aEvName))
119119
{
120120
WRN("(WbasicDatDom) !!! Failed to change wrCtrl when aleady own data(out-of-ctrl), EvName=" << aEvName);
121121
return false;

src/log/UniBaseLog.hpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,27 +64,30 @@ inline const char* mt_timestamp() noexcept
6464
const char ULN_DEFAULT[] = "DEFAULT";
6565

6666
// ***********************************************************************************************
67-
// - MT safe : yes (aStr is copied)
67+
// - MT safe : yes (aStr is const ref)
6868
// - mem safe: yes
69-
inline void cout_ascii(std::string aStr) noexcept
69+
inline void cout_ascii(const std::string& aStr) noexcept
7070
{
7171
try { // cout may except(eg ios_base::failure) though rare; try-catch is safest as a log
72-
std::cout << std::hex;
72+
std::string buf;
73+
buf.reserve(aStr.size() * 2);
7374
unsigned char preC = 0;
7475
for (unsigned char c : aStr)
7576
{
7677
if (std::isprint(c))
7778
{
7879
if (preC == 0xd || preC == 0xa)
7980
{
80-
std::cout << std::endl;
81+
buf += '\n';
8182
preC = 0;
8283
}
83-
std::cout << c;
84+
buf += static_cast<char>(c);
8485
}
8586
else
8687
{
87-
std::cout << "[`" << static_cast<size_t>(c) << "'}"; // [`'} is rare
88+
char hex[16];
89+
snprintf(hex, sizeof(hex), "[`%zx'}", static_cast<size_t>(c));
90+
buf += hex;
8891
preC = c;
8992
}
9093
}

src/thread/MtInQueue.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ template<class aEleType>
8888
bool MtInQueue::mt_pushOK(S_PTR<aEleType>&& aEle) noexcept
8989
{
9090
// validate aEle
91-
if (aEle.get() == nullptr)
91+
if (!aEle)
9292
{
9393
HID("!!! can't push nullptr since pop empty will ret nullptr");
9494
return false;

src/thread/ThPoolBack.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ ThPoolBack::ThPoolBack(size_t aMaxThread)
5050
task(); // packaged_task saves exception in its future
5151

5252
// no lock so can only use MT_safe part in "this"
53-
this->mt_nDoneFut_.fetch_add(1, std::memory_order_relaxed); // fastest +1
54-
mt_pingMainTH(); // notify mainTH 1 task done
53+
if (this->mt_nDoneFut_.fetch_add(1, std::memory_order_release) == 0) // +1 & ping only if first done
54+
mt_pingMainTH();
5555
}
5656
}); // thread main()
5757
} // for-loop to create threads

src/thread/ThreadBack.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ size_t ThreadBack::hdlDoneFut(UniLog& oneLog) noexcept
1414
{
1515
size_t nHandledFut = 0;
1616
const auto nDoneFut = mt_nDoneFut_.load(memory_order_relaxed); // since mt_nDoneFut_+1 may before future::ready
17+
if (nDoneFut == 0) return 0;
1718
// HID("(ThreadBack) nHandled=" << nHandledFut << '/' << nDoneFut << '|' << nFut());
1819

1920
// bugFix: may mt_nDoneFut_+1 before future::ready, so must check "fut_backFN != fut_backFN_S_.end()"

0 commit comments

Comments
 (0)