summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBen Boeckel <mathstuf@gmail.com>2013-08-02 19:43:15 (GMT)
committerBrad King <brad.king@kitware.com>2013-08-08 17:31:09 (GMT)
commitfc7c3b4dc8522ad489a6fb67ac6030f302c65df3 (patch)
tree5fe31541d3b997a634055e43e65fc95c6a797fea
parent1e0539cd2c14e2cb892e5f95238002d981645b78 (diff)
downloadCMake-fc7c3b4dc8522ad489a6fb67ac6030f302c65df3.zip
CMake-fc7c3b4dc8522ad489a6fb67ac6030f302c65df3.tar.gz
CMake-fc7c3b4dc8522ad489a6fb67ac6030f302c65df3.tar.bz2
variable_watch: Store client data as pointers
The STL containers create extra copies which makes keeping track of the owner of the client data much messier.
-rw-r--r--Source/cmVariableWatch.cxx27
-rw-r--r--Source/cmVariableWatch.h2
2 files changed, 22 insertions, 7 deletions
diff --git a/Source/cmVariableWatch.cxx b/Source/cmVariableWatch.cxx
index 3905e9b..21b910d 100644
--- a/Source/cmVariableWatch.cxx
+++ b/Source/cmVariableWatch.cxx
@@ -37,21 +37,35 @@ cmVariableWatch::cmVariableWatch()
cmVariableWatch::~cmVariableWatch()
{
+ cmVariableWatch::StringToVectorOfPairs::iterator svp_it;
+
+ for ( svp_it = this->WatchMap.begin();
+ svp_it != this->WatchMap.end(); ++svp_it )
+ {
+ cmVariableWatch::VectorOfPairs::iterator p_it;
+
+ for ( p_it = svp_it->second.begin();
+ p_it != svp_it->second.end(); ++p_it )
+ {
+ delete *p_it;
+ }
+ }
}
void cmVariableWatch::AddWatch(const std::string& variable,
WatchMethod method, void* client_data /*=0*/)
{
- cmVariableWatch::Pair p;
- p.Method = method;
- p.ClientData = client_data;
+ cmVariableWatch::Pair* p = new cmVariableWatch::Pair;
+ p->Method = method;
+ p->ClientData = client_data;
cmVariableWatch::VectorOfPairs* vp = &this->WatchMap[variable];
cmVariableWatch::VectorOfPairs::size_type cc;
for ( cc = 0; cc < vp->size(); cc ++ )
{
- cmVariableWatch::Pair* pair = &(*vp)[cc];
+ cmVariableWatch::Pair* pair = (*vp)[cc];
if ( pair->Method == method )
{
+ delete pair;
(*vp)[cc] = p;
return;
}
@@ -66,8 +80,9 @@ void cmVariableWatch::RemoveWatch(const std::string& variable,
cmVariableWatch::VectorOfPairs::iterator it;
for ( it = vp->begin(); it != vp->end(); ++it )
{
- if ( it->Method == method )
+ if ( (*it)->Method == method )
{
+ delete *it;
vp->erase(it);
return;
}
@@ -87,7 +102,7 @@ void cmVariableWatch::VariableAccessed(const std::string& variable,
cmVariableWatch::VectorOfPairs::const_iterator it;
for ( it = vp->begin(); it != vp->end(); it ++ )
{
- it->Method(variable, access_type, it->ClientData,
+ (*it)->Method(variable, access_type, (*it)->ClientData,
newValue, mf);
}
}
diff --git a/Source/cmVariableWatch.h b/Source/cmVariableWatch.h
index 7dd4ac5..45273e5 100644
--- a/Source/cmVariableWatch.h
+++ b/Source/cmVariableWatch.h
@@ -70,7 +70,7 @@ protected:
Pair() : Method(0), ClientData(0) {}
};
- typedef std::vector< Pair > VectorOfPairs;
+ typedef std::vector< Pair* > VectorOfPairs;
typedef std::map<cmStdString, VectorOfPairs > StringToVectorOfPairs;
StringToVectorOfPairs WatchMap;