get rid of piForeach

apply some code analyzer recommendations
ICU flag now check if libicu exists
prepare for more accurate growth of containers (limited PoT, then constantly increase size)
This commit is contained in:
2024-11-20 20:01:47 +03:00
parent 24112498ce
commit caa7880cc4
40 changed files with 415 additions and 320 deletions

View File

@@ -40,7 +40,7 @@
PIStringList PICollection::groups() {
PIStringList sl;
PIVector<PICollection::Group> & cg(_groups());
piForeachC(Group & g, cg)
for (const auto & g: cg)
sl << g.name;
return sl;
}
@@ -48,7 +48,7 @@ PIStringList PICollection::groups() {
PIVector<const PIObject *> PICollection::groupElements(const PIString & group) {
PIVector<PICollection::Group> & cg(_groups());
piForeachC(Group & g, cg)
for (const auto & g: cg)
if (g.name == group) return g.elements;
return PIVector<const PIObject *>();
}
@@ -58,7 +58,7 @@ bool PICollection::addToGroup(const PIString & group, const PIObject * element)
// piCout << "add to" << group << element;
PIString n = PIStringAscii(element->className());
PIVector<PICollection::Group> & cg(_groups());
piForeach(Group & g, cg)
for (auto & g: cg)
if (g.name == group) {
for (int i = 0; i < g.elements.size_s(); ++i)
if (PIString(g.elements[i]->className()) == n) return false;

View File

@@ -177,7 +177,9 @@ public:
private:
Notifier();
PIObject * o;
NO_COPY_CLASS(Notifier)
PIObject * o = nullptr;
std::atomic_int new_id = {1};
};

View File

@@ -108,7 +108,7 @@ PIInit::PIInit() {
PIStringList ifpathes;
ifpathes << PIStringAscii("/bin/ifconfig") << PIStringAscii("/sbin/ifconfig") << PIStringAscii("/usr/bin/ifconfig")
<< PIStringAscii("/usr/sbin/ifconfig");
piForeachC(PIString & i, ifpathes) {
for (const auto & i: ifpathes) {
if (fileExists(i)) {
sinfo->ifconfigPath = i;
break;

View File

@@ -360,9 +360,9 @@ PIObject::Connection PIObject::piConnectU(PIObject * src,
void *addr_src(0), *addr_dest(0);
int args(0);
bool que = (performer != 0);
piForeachC(__MetaFunc & fs, m_src) {
for (const auto & fs: m_src) {
if (addr_src != 0) break;
piForeachC(__MetaFunc & fd, m_dest) {
for (const auto & fd: m_dest) {
if (addr_src != 0) break;
if (fs.canConnectTo(fd, args)) {
addr_src = fs.addr;
@@ -477,7 +477,7 @@ void PIObject::piDisconnectAll() {
PIMutexLocker _ml(mutex_connect);
PIVector<PIObject *> cv = connectors.toVector();
// piCout << "disconnect connectors =" << connectors.size();
piForeach(PIObject * o, cv) {
for (auto * o: cv) {
// piCout << "disconnect"<< src << o;
if (!o || (o == this)) continue;
if (!o->isPIObject()) continue;
@@ -496,7 +496,7 @@ void PIObject::piDisconnectAll() {
}
}
// piCout << "disconnect connections =" << connections.size();
piForeachC(PIObject::Connection & c, connections) {
for (const auto & c: connections) {
if (c.functor) continue;
if (!c.dest_o) continue;
if (!c.dest_o->isPIObject()) continue;
@@ -512,10 +512,10 @@ void PIObject::updateConnectors() {
// piCout << "*** updateConnectors" << this;
connectors.clear();
PIMutexLocker _ml(mutexObjects());
piForeach(PIObject * o, objects()) {
for (auto * o: objects()) {
if (o == this) continue;
PIVector<Connection> & oc(o->connections);
piForeach(Connection & c, oc)
for (auto & c: oc)
if (c.dest == this) connectors << o;
}
}
@@ -551,7 +551,7 @@ void PIObject::callQueuedEvents() {
PIVector<__QueuedEvent> qe = events_queue;
events_queue.clear();
mutex_queue.unlock();
piForeachC(__QueuedEvent & e, qe) {
for (const auto & e: qe) {
if (e.dest_o->thread_safe_) e.dest_o->mutex_.lock();
e.dest_o->emitter_ = e.src;
callAddrV(e.slot, e.dest, e.values.size_s(), e.values);

View File

@@ -510,7 +510,7 @@ public:
//! Returns PIObject* with name "name" or 0, if there is no object found
static PIObject * findByName(const PIString & name) {
PIMutexLocker _ml(mutexObjects());
piForeach(PIObject * i, PIObject::objects()) {
for (auto * i: PIObject::objects()) {
if (i->name() != name) continue;
return i;
}