summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormgrojo <mgrojo@gmail.com>2019-08-21 15:32:18 +0200
committermgrojo <mgrojo@gmail.com>2019-08-21 15:32:18 +0200
commit3a937e3df5717132cfd2b7459396ee4e5567868c (patch)
tree4ddd2b88b0f1aabcc44f05ae77374fbb81c4398e
parentea0c67bb9ccf7b22e086f33bdb89f5aa12fc5a4f (diff)
downloadATCD-3a937e3df5717132cfd2b7459396ee4e5567868c.tar.gz
Optimization: avoid nested iteration in ACE_Service_Repository::find_i
This method was performing two iterations: the first using an index, and the second in the call to this->service_array_.find, which uses an iterator over the Array_Map looking for the element with that index. This simplifies and optimizes this method by iterating for the element once using directly the map iterator.
-rw-r--r--ACE/ace/Service_Repository.cpp20
1 files changed, 8 insertions, 12 deletions
diff --git a/ACE/ace/Service_Repository.cpp b/ACE/ace/Service_Repository.cpp
index 6c5fb03df59..bb0755853fe 100644
--- a/ACE/ace/Service_Repository.cpp
+++ b/ACE/ace/Service_Repository.cpp
@@ -275,25 +275,21 @@ ACE_Service_Repository::find_i (const ACE_TCHAR name[],
bool ignore_suspended) const
{
ACE_TRACE ("ACE_Service_Repository::find_i");
- size_t i = 0;
- array_type::const_iterator element = this->service_array_.end ();
+ array_type::const_iterator iter;
- for (i = 0; i < this->service_array_.size(); i++)
+ for (iter = this->service_array_.begin(); iter != this->service_array_.end(); ++iter)
{
- array_type::const_iterator iter = this->service_array_.find (i);
- if (iter != this->service_array_.end ()
- && (*iter).second != 0 // skip any empty slots
+ if ((*iter).second != 0 // skip any empty slots
&& ACE_OS::strcmp (name, (*iter).second->name ()) == 0)
{
- element = iter;
break;
}
}
- if (element != this->service_array_.end ())
+ if (iter != this->service_array_.end ())
{
- slot = i;
- if ((*element).second->fini_called ())
+ slot = (*iter).first;
+ if ((*iter).second->fini_called ())
{
if (srp != 0)
*srp = 0;
@@ -301,10 +297,10 @@ ACE_Service_Repository::find_i (const ACE_TCHAR name[],
}
if (srp != 0)
- *srp = (*element).second;
+ *srp = (*iter).second;
if (ignore_suspended
- && (*element).second->active () == 0)
+ && (*iter).second->active () == 0)
return -2;
return 0;