[Cmake-commits] CMake branch, next, updated. v3.2.2-2182-g9e58d68

Stephen Kelly steveire at gmail.com
Sun Apr 26 13:31:53 EDT 2015


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "CMake".

The branch, next has been updated
       via  9e58d685db1ca130f61d6fffeb59e98e14bcc3b0 (commit)
       via  f040fa757a6244d47ae6b72a67b7efac4f4662c4 (commit)
       via  afa70ed57e8cac0a0df2ec604ffceb2c9081d95a (commit)
       via  3ec35fa02ee7d4cff914e1c31deb66e2aeeb42f1 (commit)
       via  661d6f0c01d78712a13c81eb9aa315e704b2a628 (commit)
       via  72c5a900a35d94a973dad4b0276d5d7a989d26e7 (commit)
       via  5a16632d3ddab3b74d56c7b4670cf9ef84905a6c (commit)
       via  4ae78dc1b3608f255f11a71137321985cb5d56d3 (commit)
       via  fe80183ffaf092c7d58c583cf13e8564aa1847c2 (commit)
       via  b8ae82a7f87b5a08d5ba6446e3ebf8a8355362dd (commit)
       via  3a3289257ad451e043b57ce0f2c1ac9f46c78386 (commit)
       via  46ba0cc8cfd4d14d264f9ea8bd31819b356f23e8 (commit)
       via  aa8a091b4c3a7658a94b9fe1c84b9a5622f26398 (commit)
       via  28862c77df60049792a319c20c236832584f5527 (commit)
       via  58f0624f341d2e0fb8559ee5099debc1285a3584 (commit)
       via  fc98fa87a7d3740199f5b6d9309d5856bd507c28 (commit)
       via  2c24078f8046b456f81c3cd8cf4bb9cf1f963f27 (commit)
       via  b5185748d66ec850d78fc4e206803943d323fe3c (commit)
       via  155c334ce3517a3f6e0a32daded9cf3c5b01c5b9 (commit)
       via  cafd52c76189c5659a1d32f9ad15a0f5b69a2370 (commit)
       via  038ba6f3624af88a633976a71e2a7653e684efcc (commit)
       via  8fdea5ae4b50924b147e67082e2efacdbb79944e (commit)
       via  47c946d48fa1024e1964fc64a1a5db4ac8b48470 (commit)
       via  3137703457930a453c611e9cc51ee7b90338f585 (commit)
       via  0d8fdbb5a18b60905646d6a5b1432dfdfd32320f (commit)
       via  22d354d7963bbd678ad67d0450bfde6458005c3b (commit)
       via  882e18954e742cb6ef8c9455643e0f46c2c2e1c0 (commit)
      from  8dc6ca94d199acb52a70d5382e75a22bf504df7e (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=9e58d685db1ca130f61d6fffeb59e98e14bcc3b0
commit 9e58d685db1ca130f61d6fffeb59e98e14bcc3b0
Merge: 8dc6ca9 f040fa7
Author:     Stephen Kelly <steveire at gmail.com>
AuthorDate: Sun Apr 26 13:31:51 2015 -0400
Commit:     CMake Topic Stage <kwrobot at kitware.com>
CommitDate: Sun Apr 26 13:31:51 2015 -0400

    Merge topic 'refactor-cmDefinitions' into next
    
    f040fa75 cmMakefile: Store definition stack as a vector.
    afa70ed5 cmDefinitions: Remove Parent pointer.
    3ec35fa0 cmDefinitions: Convert MakeClosure into a static method.
    661d6f0c cmDefinitions: Implement MakeClosure in terms of a vector of ancestors.
    72c5a900 cmDefinitions: Use vector of cmDefinitions* to create closure.
    5a16632d cmDefinitions: Replace recursion with loop.
    4ae78dc1 cmDefinitions: Replace private constructor with MakeClosure.
    fe80183f cmDefinitions: Externalize looping for ClosureKeys.
    b8ae82a7 cmDefinitions: Change LocalKeys to return a vector.
    3a328925 cmDefinitions: Make ClosureKeys API vector-based.
    46ba0cc8 cmDefinitions: Inline GetClosureKeys implementation.
    aa8a091b cmDefinitions: Replace ClosureKeys recursion with looping.
    28862c77 cmDefinitions: Inline GetInternal into Get.
    58f0624f cmDefinitions: Externalize the stack loop for the Get method.
    fc98fa87 cmDefinitions: Extract loop from GetInternal to Get.
    2c24078f cmDefinitions: Use Set API in Get implementation.
    ...


http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=f040fa757a6244d47ae6b72a67b7efac4f4662c4
commit f040fa757a6244d47ae6b72a67b7efac4f4662c4
Author:     Stephen Kelly <steveire at gmail.com>
AuthorDate: Sun Apr 26 16:22:52 2015 +0200
Commit:     Stephen Kelly <steveire at gmail.com>
CommitDate: Sun Apr 26 19:30:54 2015 +0200

    cmMakefile: Store definition stack as a vector.

diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx
index ab1ee00..c51984b 100644
--- a/Source/cmMakefile.cxx
+++ b/Source/cmMakefile.cxx
@@ -38,30 +38,28 @@
 #include <cmsys/FStream.hxx>
 #include <cmsys/auto_ptr.hxx>
 
-#include <list>
 #include <ctype.h> // for isspace
 #include <assert.h>
 
 class cmMakefile::Internals
 {
 public:
-  std::list<cmDefinitions> VarStack;
+  std::vector<cmDefinitions> VarStack;
   std::stack<std::set<std::string> > VarInitStack;
   std::stack<std::set<std::string> > VarUsageStack;
   bool IsSourceFileTryCompile;
 
   void PushDefinitions()
   {
-    this->VarStack.push_back(cmDefinitions());
+    this->VarStack.resize(this->VarStack.size() + 1);
   }
 
   void InitializeDefinitions(cmMakefile* parent)
   {
     std::vector<cmDefinitions const*> defPtrs;
-    defPtrs.reserve(this->VarStack.size());
-    for (std::list<cmDefinitions>::iterator it =
-         parent->Internal->VarStack.begin();
-         it != parent->Internal->VarStack.end(); ++it)
+    for (std::vector<cmDefinitions>::iterator it =
+        parent->Internal->VarStack.begin();
+        it != parent->Internal->VarStack.end(); ++it)
       {
       defPtrs.push_back(&*it);
       }
@@ -74,7 +72,7 @@ public:
   {
     std::vector<cmDefinitions*> defPtrs;
     defPtrs.reserve(this->VarStack.size());
-    for (std::list<cmDefinitions>::iterator it = this->VarStack.begin();
+    for (std::vector<cmDefinitions>::iterator it = this->VarStack.begin();
         it != this->VarStack.end(); ++it)
       {
       defPtrs.push_back(&*it);
@@ -125,7 +123,7 @@ public:
   {
     std::vector<std::string> closureKeys;
     std::vector<std::string> undefinedKeys;
-    for (std::list<cmDefinitions>::const_iterator it = this->VarStack.begin();
+    for (std::vector<cmDefinitions>::const_iterator it = this->VarStack.begin();
         it != this->VarStack.end(); ++it)
       {
       std::vector<std::string> const& localKeys = it->Keys(undefinedKeys);
@@ -146,14 +144,14 @@ public:
 
   bool RaiseScope(std::string const& var, const char* varDef, cmMakefile* mf)
   {
-    cmDefinitions& cur = this->VarStack.back();
-    if(cmDefinitions* up = cur.GetParent())
+    if(this->VarStack.size() > 1)
       {
       // First localize the definition in the current scope.
-      cur.Get(var);
+      this->GetDefinition(var);
 
       // Now update the definition in the parent scope.
-      up->Set(var, varDef);
+      cmDefinitions& up = this->VarStack[this->VarStack.size() - 2];
+      up.Set(var, varDef);
       }
     else if(cmLocalGenerator* plg = mf->GetLocalGenerator()->GetParent())
       {

http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=afa70ed57e8cac0a0df2ec604ffceb2c9081d95a
commit afa70ed57e8cac0a0df2ec604ffceb2c9081d95a
Author:     Stephen Kelly <steveire at gmail.com>
AuthorDate: Sun Apr 26 16:19:11 2015 +0200
Commit:     Stephen Kelly <steveire at gmail.com>
CommitDate: Sun Apr 26 19:30:54 2015 +0200

    cmDefinitions: Remove Parent pointer.
    
    All structural knowledge of the stack of scopes is now external.

diff --git a/Source/cmDefinitions.cxx b/Source/cmDefinitions.cxx
index fe27b76..a39855f 100644
--- a/Source/cmDefinitions.cxx
+++ b/Source/cmDefinitions.cxx
@@ -14,12 +14,6 @@
 #include <assert.h>
 
 //----------------------------------------------------------------------------
-cmDefinitions::cmDefinitions(cmDefinitions* parent)
-  : Up(parent)
-{
-}
-
-//----------------------------------------------------------------------------
 std::pair<const char*, bool> cmDefinitions::Get(const std::string& key)
 {
   MapType::const_iterator i = this->Map.find(key);
diff --git a/Source/cmDefinitions.h b/Source/cmDefinitions.h
index 5a3a993..6c57c36 100644
--- a/Source/cmDefinitions.h
+++ b/Source/cmDefinitions.h
@@ -26,12 +26,6 @@
 class cmDefinitions
 {
 public:
-  /** Construct with the given parent scope.  */
-  cmDefinitions(cmDefinitions* parent = 0);
-
-  /** Returns the parent scope, if any.  */
-  cmDefinitions* GetParent() const { return this->Up; }
-
   std::pair<const char*, bool> Get(const std::string& key);
 
   /** Set (or unset if null) a value associated with a key.  */
@@ -63,9 +57,6 @@ private:
     bool Exists;
   };
 
-  // Parent scope, if any.
-  cmDefinitions* Up;
-
   // Local definitions, set or unset.
 #if defined(CMAKE_BUILD_WITH_CMAKE)
   typedef cmsys::hash_map<std::string, Def> MapType;
diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx
index 299b4c9..ab1ee00 100644
--- a/Source/cmMakefile.cxx
+++ b/Source/cmMakefile.cxx
@@ -52,12 +52,7 @@ public:
 
   void PushDefinitions()
   {
-    cmDefinitions* parent = 0;
-    if (!this->VarStack.empty())
-      {
-      parent = &this->VarStack.back();
-      }
-    this->VarStack.push_back(cmDefinitions(parent));
+    this->VarStack.push_back(cmDefinitions());
   }
 
   void InitializeDefinitions(cmMakefile* parent)

http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=3ec35fa02ee7d4cff914e1c31deb66e2aeeb42f1
commit 3ec35fa02ee7d4cff914e1c31deb66e2aeeb42f1
Author:     Stephen Kelly <steveire at gmail.com>
AuthorDate: Sun Apr 26 16:13:56 2015 +0200
Commit:     Stephen Kelly <steveire at gmail.com>
CommitDate: Sun Apr 26 19:30:54 2015 +0200

    cmDefinitions: Convert MakeClosure into a static method.
    
    Accept a range of cmDefinitions*.

diff --git a/Source/cmDefinitions.cxx b/Source/cmDefinitions.cxx
index 8613ea9..fe27b76 100644
--- a/Source/cmDefinitions.cxx
+++ b/Source/cmDefinitions.cxx
@@ -61,18 +61,13 @@ std::vector<std::string> cmDefinitions::LocalKeys() const
 }
 
 //----------------------------------------------------------------------------
-cmDefinitions cmDefinitions::MakeClosure() const
+cmDefinitions cmDefinitions::MakeClosure(
+    std::vector<cmDefinitions const*>::iterator begin,
+    std::vector<cmDefinitions const*>::iterator end)
 {
   std::set<std::string> undefined;
   cmDefinitions closure;
-  cmDefinitions const* defs = this;
-  std::vector<cmDefinitions const*> ups;
-  while(defs)
-    {
-    ups.push_back(defs);
-    defs = defs->Up;
-    }
-  closure.MakeClosure(undefined, ups.begin(), ups.end());
+  closure.MakeClosure(undefined, begin, end);
   return closure;
 }
 
diff --git a/Source/cmDefinitions.h b/Source/cmDefinitions.h
index f2c014f..5a3a993 100644
--- a/Source/cmDefinitions.h
+++ b/Source/cmDefinitions.h
@@ -45,7 +45,9 @@ public:
   std::vector<std::string>
   Keys(std::vector<std::string>& undefinedKeys) const;
 
-  cmDefinitions MakeClosure() const;
+  static cmDefinitions MakeClosure(
+      std::vector<cmDefinitions const*>::iterator begin,
+      std::vector<cmDefinitions const*>::iterator end);
 
 private:
   // String with existence boolean.
diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx
index 36e06f5..299b4c9 100644
--- a/Source/cmMakefile.cxx
+++ b/Source/cmMakefile.cxx
@@ -62,7 +62,17 @@ public:
 
   void InitializeDefinitions(cmMakefile* parent)
   {
-    this->VarStack.back() = parent->Internal->VarStack.back().MakeClosure();
+    std::vector<cmDefinitions const*> defPtrs;
+    defPtrs.reserve(this->VarStack.size());
+    for (std::list<cmDefinitions>::iterator it =
+         parent->Internal->VarStack.begin();
+         it != parent->Internal->VarStack.end(); ++it)
+      {
+      defPtrs.push_back(&*it);
+      }
+    std::reverse(defPtrs.begin(), defPtrs.end());
+    this->VarStack.back() = cmDefinitions::MakeClosure(defPtrs.begin(),
+                                                       defPtrs.end());
   }
 
   const char* GetDefinition(std::string const& name)

http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=661d6f0c01d78712a13c81eb9aa315e704b2a628
commit 661d6f0c01d78712a13c81eb9aa315e704b2a628
Author:     Stephen Kelly <steveire at gmail.com>
AuthorDate: Sun Apr 26 16:00:18 2015 +0200
Commit:     Stephen Kelly <steveire at gmail.com>
CommitDate: Sun Apr 26 19:30:53 2015 +0200

    cmDefinitions: Implement MakeClosure in terms of a vector of ancestors.

diff --git a/Source/cmDefinitions.cxx b/Source/cmDefinitions.cxx
index d9f28f0..8613ea9 100644
--- a/Source/cmDefinitions.cxx
+++ b/Source/cmDefinitions.cxx
@@ -65,22 +65,25 @@ cmDefinitions cmDefinitions::MakeClosure() const
 {
   std::set<std::string> undefined;
   cmDefinitions closure;
-  closure.MakeClosure(undefined, this);
-  return closure;
-}
-
-//----------------------------------------------------------------------------
-void cmDefinitions::MakeClosure(std::set<std::string>& undefined,
-                                cmDefinitions const* defs)
-{
-  std::vector<cmDefinitions*> ups;
+  cmDefinitions const* defs = this;
+  std::vector<cmDefinitions const*> ups;
   while(defs)
     {
     ups.push_back(defs);
     defs = defs->Up;
     }
-  for (std::vector<cmDefinitions*>::const_iterator it = ups.begin();
-       it != ups.end(); ++it)
+  closure.MakeClosure(undefined, ups.begin(), ups.end());
+  return closure;
+}
+
+//----------------------------------------------------------------------------
+void
+cmDefinitions::MakeClosure(std::set<std::string>& undefined,
+                           std::vector<cmDefinitions const*>::iterator begin,
+                           std::vector<cmDefinitions const*>::iterator end)
+{
+  for (std::vector<cmDefinitions const*>::const_iterator it = begin;
+       it != end; ++it)
     {
     // Consider local definitions.
     for(MapType::const_iterator mi = (*it)->Map.begin();
diff --git a/Source/cmDefinitions.h b/Source/cmDefinitions.h
index dcfb01d..f2c014f 100644
--- a/Source/cmDefinitions.h
+++ b/Source/cmDefinitions.h
@@ -73,7 +73,8 @@ private:
   MapType Map;
 
   void MakeClosure(std::set<std::string>& undefined,
-                   cmDefinitions const* defs);
+                   std::vector<cmDefinitions const*>::iterator begin,
+                   std::vector<cmDefinitions const*>::iterator end);
 };
 
 #endif

http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=72c5a900a35d94a973dad4b0276d5d7a989d26e7
commit 72c5a900a35d94a973dad4b0276d5d7a989d26e7
Author:     Stephen Kelly <steveire at gmail.com>
AuthorDate: Sun Apr 26 15:54:02 2015 +0200
Commit:     Stephen Kelly <steveire at gmail.com>
CommitDate: Sun Apr 26 19:30:53 2015 +0200

    cmDefinitions: Use vector of cmDefinitions* to create closure.

diff --git a/Source/cmDefinitions.cxx b/Source/cmDefinitions.cxx
index 988d28b..d9f28f0 100644
--- a/Source/cmDefinitions.cxx
+++ b/Source/cmDefinitions.cxx
@@ -73,11 +73,18 @@ cmDefinitions cmDefinitions::MakeClosure() const
 void cmDefinitions::MakeClosure(std::set<std::string>& undefined,
                                 cmDefinitions const* defs)
 {
+  std::vector<cmDefinitions*> ups;
   while(defs)
     {
+    ups.push_back(defs);
+    defs = defs->Up;
+    }
+  for (std::vector<cmDefinitions*>::const_iterator it = ups.begin();
+       it != ups.end(); ++it)
+    {
     // Consider local definitions.
-    for(MapType::const_iterator mi = defs->Map.begin();
-        mi != defs->Map.end(); ++mi)
+    for(MapType::const_iterator mi = (*it)->Map.begin();
+        mi != (*it)->Map.end(); ++mi)
       {
       // Use this key if it is not already set or unset.
       if(this->Map.find(mi->first) == this->Map.end() &&
@@ -93,7 +100,6 @@ void cmDefinitions::MakeClosure(std::set<std::string>& undefined,
           }
         }
       }
-    defs = defs->Up;
     }
 }
 

http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=5a16632d3ddab3b74d56c7b4670cf9ef84905a6c
commit 5a16632d3ddab3b74d56c7b4670cf9ef84905a6c
Author:     Stephen Kelly <steveire at gmail.com>
AuthorDate: Sun Apr 26 15:49:43 2015 +0200
Commit:     Stephen Kelly <steveire at gmail.com>
CommitDate: Sun Apr 26 19:30:53 2015 +0200

    cmDefinitions: Replace recursion with loop.

diff --git a/Source/cmDefinitions.cxx b/Source/cmDefinitions.cxx
index 94b27fd..988d28b 100644
--- a/Source/cmDefinitions.cxx
+++ b/Source/cmDefinitions.cxx
@@ -73,29 +73,27 @@ cmDefinitions cmDefinitions::MakeClosure() const
 void cmDefinitions::MakeClosure(std::set<std::string>& undefined,
                                 cmDefinitions const* defs)
 {
-  // Consider local definitions.
-  for(MapType::const_iterator mi = defs->Map.begin();
-      mi != defs->Map.end(); ++mi)
+  while(defs)
     {
-    // Use this key if it is not already set or unset.
-    if(this->Map.find(mi->first) == this->Map.end() &&
-       undefined.find(mi->first) == undefined.end())
+    // Consider local definitions.
+    for(MapType::const_iterator mi = defs->Map.begin();
+        mi != defs->Map.end(); ++mi)
       {
-      if(mi->second.Exists)
-        {
-        this->Map.insert(*mi);
-        }
-      else
+      // Use this key if it is not already set or unset.
+      if(this->Map.find(mi->first) == this->Map.end() &&
+         undefined.find(mi->first) == undefined.end())
         {
-        undefined.insert(mi->first);
+        if(mi->second.Exists)
+          {
+          this->Map.insert(*mi);
+          }
+        else
+          {
+          undefined.insert(mi->first);
+          }
         }
       }
-    }
-
-  // Traverse parents.
-  if(cmDefinitions const* up = defs->Up)
-    {
-    this->MakeClosure(undefined, up);
+    defs = defs->Up;
     }
 }
 

http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=4ae78dc1b3608f255f11a71137321985cb5d56d3
commit 4ae78dc1b3608f255f11a71137321985cb5d56d3
Author:     Stephen Kelly <steveire at gmail.com>
AuthorDate: Sun Apr 26 15:44:26 2015 +0200
Commit:     Stephen Kelly <steveire at gmail.com>
CommitDate: Sun Apr 26 19:30:53 2015 +0200

    cmDefinitions: Replace private constructor with MakeClosure.

diff --git a/Source/cmDefinitions.cxx b/Source/cmDefinitions.cxx
index 844d72b..94b27fd 100644
--- a/Source/cmDefinitions.cxx
+++ b/Source/cmDefinitions.cxx
@@ -61,21 +61,16 @@ std::vector<std::string> cmDefinitions::LocalKeys() const
 }
 
 //----------------------------------------------------------------------------
-cmDefinitions cmDefinitions::Closure() const
-{
-  return cmDefinitions(ClosureTag(), this);
-}
-
-//----------------------------------------------------------------------------
-cmDefinitions::cmDefinitions(ClosureTag const&, cmDefinitions const* root):
-  Up(0)
+cmDefinitions cmDefinitions::MakeClosure() const
 {
   std::set<std::string> undefined;
-  this->ClosureImpl(undefined, root);
+  cmDefinitions closure;
+  closure.MakeClosure(undefined, this);
+  return closure;
 }
 
 //----------------------------------------------------------------------------
-void cmDefinitions::ClosureImpl(std::set<std::string>& undefined,
+void cmDefinitions::MakeClosure(std::set<std::string>& undefined,
                                 cmDefinitions const* defs)
 {
   // Consider local definitions.
@@ -100,7 +95,7 @@ void cmDefinitions::ClosureImpl(std::set<std::string>& undefined,
   // Traverse parents.
   if(cmDefinitions const* up = defs->Up)
     {
-    this->ClosureImpl(undefined, up);
+    this->MakeClosure(undefined, up);
     }
 }
 
diff --git a/Source/cmDefinitions.h b/Source/cmDefinitions.h
index e79614a..dcfb01d 100644
--- a/Source/cmDefinitions.h
+++ b/Source/cmDefinitions.h
@@ -42,13 +42,11 @@ public:
   /** Get the set of all local keys.  */
   std::vector<std::string> LocalKeys() const;
 
-  /** Compute the closure of all defined keys with values.
-      This flattens the scope.  The result has no parent.  */
-  cmDefinitions Closure() const;
-
   std::vector<std::string>
   Keys(std::vector<std::string>& undefinedKeys) const;
 
+  cmDefinitions MakeClosure() const;
+
 private:
   // String with existence boolean.
   struct Def: public std::string
@@ -74,10 +72,7 @@ private:
 #endif
   MapType Map;
 
-  // Implementation of Closure() method.
-  struct ClosureTag {};
-  cmDefinitions(ClosureTag const&, cmDefinitions const* root);
-  void ClosureImpl(std::set<std::string>& undefined,
+  void MakeClosure(std::set<std::string>& undefined,
                    cmDefinitions const* defs);
 };
 
diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx
index b95dfe2..36e06f5 100644
--- a/Source/cmMakefile.cxx
+++ b/Source/cmMakefile.cxx
@@ -62,7 +62,7 @@ public:
 
   void InitializeDefinitions(cmMakefile* parent)
   {
-    this->VarStack.back() = parent->Internal->VarStack.back().Closure();
+    this->VarStack.back() = parent->Internal->VarStack.back().MakeClosure();
   }
 
   const char* GetDefinition(std::string const& name)

http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=fe80183ffaf092c7d58c583cf13e8564aa1847c2
commit fe80183ffaf092c7d58c583cf13e8564aa1847c2
Author:     Stephen Kelly <steveire at gmail.com>
AuthorDate: Sun Apr 26 15:38:36 2015 +0200
Commit:     Stephen Kelly <steveire at gmail.com>
CommitDate: Sun Apr 26 19:30:52 2015 +0200

    cmDefinitions: Externalize looping for ClosureKeys.

diff --git a/Source/cmDefinitions.cxx b/Source/cmDefinitions.cxx
index d612a63..844d72b 100644
--- a/Source/cmDefinitions.cxx
+++ b/Source/cmDefinitions.cxx
@@ -105,28 +105,19 @@ void cmDefinitions::ClosureImpl(std::set<std::string>& undefined,
 }
 
 //----------------------------------------------------------------------------
-std::vector<std::string> cmDefinitions::ClosureKeys() const
+std::vector<std::string>
+cmDefinitions::Keys(std::vector<std::string>& undefined) const
 {
-  std::set<std::string> defined;
-  std::set<std::string> undefined;
-
-  cmDefinitions const* up = this;
-
-  while (up)
+  std::vector<std::string> defined;
+  defined.reserve(this->Map.size());
+  for(MapType::const_iterator mi = this->Map.begin();
+      mi != this->Map.end(); ++mi)
     {
-    // Consider local definitions.
-    for(MapType::const_iterator mi = up->Map.begin();
-        mi != up->Map.end(); ++mi)
-      {
-      // Use this key if it is not already set or unset.
-      if(defined.find(mi->first) == defined.end() &&
-         undefined.find(mi->first) == undefined.end())
-        {
-        std::set<std::string>& m = mi->second.Exists? defined : undefined;
-        m.insert(mi->first);
-        }
-      }
-    up = this->Up;
+    std::vector<std::string>& m = mi->second.Exists? defined : undefined;
+    m.push_back(mi->first);
     }
-  return std::vector<std::string>(defined.begin(), defined.end());
+  std::sort(undefined.begin(), undefined.end());
+  undefined.erase(std::unique(undefined.begin(), undefined.end()),
+                  undefined.end());
+  return defined;
 }
diff --git a/Source/cmDefinitions.h b/Source/cmDefinitions.h
index c3644bb..e79614a 100644
--- a/Source/cmDefinitions.h
+++ b/Source/cmDefinitions.h
@@ -46,8 +46,8 @@ public:
       This flattens the scope.  The result has no parent.  */
   cmDefinitions Closure() const;
 
-  /** Compute the set of all defined keys.  */
-  std::vector<std::string> ClosureKeys() const;
+  std::vector<std::string>
+  Keys(std::vector<std::string>& undefinedKeys) const;
 
 private:
   // String with existence boolean.
diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx
index 332c52b..b95dfe2 100644
--- a/Source/cmMakefile.cxx
+++ b/Source/cmMakefile.cxx
@@ -118,7 +118,20 @@ public:
 
   std::vector<std::string> ClosureKeys() const
   {
-    return this->VarStack.back().ClosureKeys();
+    std::vector<std::string> closureKeys;
+    std::vector<std::string> undefinedKeys;
+    for (std::list<cmDefinitions>::const_iterator it = this->VarStack.begin();
+        it != this->VarStack.end(); ++it)
+      {
+      std::vector<std::string> const& localKeys = it->Keys(undefinedKeys);
+      closureKeys.insert(closureKeys.end(), localKeys.begin(), localKeys.end());
+      std::vector<std::string>::iterator newIt =
+          closureKeys.end() - localKeys.size();
+      std::inplace_merge(closureKeys.begin(), newIt, closureKeys.end());
+      }
+    closureKeys.erase(std::unique(closureKeys.begin(),
+                                  closureKeys.end()), closureKeys.end());
+    return closureKeys;
   }
 
   void PopDefinitions()

http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=b8ae82a7f87b5a08d5ba6446e3ebf8a8355362dd
commit b8ae82a7f87b5a08d5ba6446e3ebf8a8355362dd
Author:     Stephen Kelly <steveire at gmail.com>
AuthorDate: Sun Apr 26 16:34:13 2015 +0200
Commit:     Stephen Kelly <steveire at gmail.com>
CommitDate: Sun Apr 26 19:30:52 2015 +0200

    cmDefinitions: Change LocalKeys to return a vector.
    
    This is more efficient and we lose nothing.

diff --git a/Source/cmDefinitions.cxx b/Source/cmDefinitions.cxx
index 929a407..d612a63 100644
--- a/Source/cmDefinitions.cxx
+++ b/Source/cmDefinitions.cxx
@@ -44,16 +44,17 @@ void cmDefinitions::Erase(const std::string& key)
 }
 
 //----------------------------------------------------------------------------
-std::set<std::string> cmDefinitions::LocalKeys() const
+std::vector<std::string> cmDefinitions::LocalKeys() const
 {
-  std::set<std::string> keys;
+  std::vector<std::string> keys;
+  keys.reserve(this->Map.size());
   // Consider local definitions.
   for(MapType::const_iterator mi = this->Map.begin();
       mi != this->Map.end(); ++mi)
     {
     if (mi->second.Exists)
       {
-      keys.insert(mi->first);
+      keys.push_back(mi->first);
       }
     }
   return keys;
diff --git a/Source/cmDefinitions.h b/Source/cmDefinitions.h
index e5a427f..c3644bb 100644
--- a/Source/cmDefinitions.h
+++ b/Source/cmDefinitions.h
@@ -40,7 +40,7 @@ public:
   void Erase(const std::string& key);
 
   /** Get the set of all local keys.  */
-  std::set<std::string> LocalKeys() const;
+  std::vector<std::string> LocalKeys() const;
 
   /** Compute the closure of all defined keys with values.
       This flattens the scope.  The result has no parent.  */
diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx
index 1384e77..332c52b 100644
--- a/Source/cmMakefile.cxx
+++ b/Source/cmMakefile.cxx
@@ -111,7 +111,7 @@ public:
       }
   }
 
-  std::set<std::string> LocalKeys() const
+  std::vector<std::string> LocalKeys() const
   {
     return this->VarStack.back().LocalKeys();
   }
@@ -1905,8 +1905,8 @@ void cmMakefile::CheckForUnusedVariables() const
     {
     return;
     }
-  const std::set<std::string>& locals = this->Internal->LocalKeys();
-  std::set<std::string>::const_iterator it = locals.begin();
+  const std::vector<std::string>& locals = this->Internal->LocalKeys();
+  std::vector<std::string>::const_iterator it = locals.begin();
   for (; it != locals.end(); ++it)
     {
     this->CheckForUnused("out of scope", *it);
@@ -4457,10 +4457,10 @@ void cmMakefile::PopScope()
 
   std::set<std::string> init = this->Internal->VarInitStack.top();
   std::set<std::string> usage = this->Internal->VarUsageStack.top();
-  const std::set<std::string>& locals = this->Internal->LocalKeys();
+  const std::vector<std::string>& locals = this->Internal->LocalKeys();
   // Remove initialization and usage information for variables in the local
   // scope.
-  std::set<std::string>::const_iterator it = locals.begin();
+  std::vector<std::string>::const_iterator it = locals.begin();
   for (; it != locals.end(); ++it)
     {
     init.erase(*it);

http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=3a3289257ad451e043b57ce0f2c1ac9f46c78386
commit 3a3289257ad451e043b57ce0f2c1ac9f46c78386
Author:     Stephen Kelly <steveire at gmail.com>
AuthorDate: Sun Apr 26 15:36:49 2015 +0200
Commit:     Stephen Kelly <steveire at gmail.com>
CommitDate: Sun Apr 26 19:30:52 2015 +0200

    cmDefinitions: Make ClosureKeys API vector-based.

diff --git a/Source/cmDefinitions.cxx b/Source/cmDefinitions.cxx
index bcb70e1..929a407 100644
--- a/Source/cmDefinitions.cxx
+++ b/Source/cmDefinitions.cxx
@@ -104,7 +104,7 @@ void cmDefinitions::ClosureImpl(std::set<std::string>& undefined,
 }
 
 //----------------------------------------------------------------------------
-std::set<std::string> cmDefinitions::ClosureKeys() const
+std::vector<std::string> cmDefinitions::ClosureKeys() const
 {
   std::set<std::string> defined;
   std::set<std::string> undefined;
@@ -127,5 +127,5 @@ std::set<std::string> cmDefinitions::ClosureKeys() const
       }
     up = this->Up;
     }
-  return defined;
+  return std::vector<std::string>(defined.begin(), defined.end());
 }
diff --git a/Source/cmDefinitions.h b/Source/cmDefinitions.h
index 1a8d8e8..e5a427f 100644
--- a/Source/cmDefinitions.h
+++ b/Source/cmDefinitions.h
@@ -47,7 +47,7 @@ public:
   cmDefinitions Closure() const;
 
   /** Compute the set of all defined keys.  */
-  std::set<std::string> ClosureKeys() const;
+  std::vector<std::string> ClosureKeys() const;
 
 private:
   // String with existence boolean.
diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx
index 8573964..1384e77 100644
--- a/Source/cmMakefile.cxx
+++ b/Source/cmMakefile.cxx
@@ -116,7 +116,7 @@ public:
     return this->VarStack.back().LocalKeys();
   }
 
-  std::set<std::string> ClosureKeys() const
+  std::vector<std::string> ClosureKeys() const
   {
     return this->VarStack.back().ClosureKeys();
   }
@@ -2518,8 +2518,7 @@ std::vector<std::string> cmMakefile
   std::vector<std::string> res;
   if ( !cacheonly )
     {
-    std::set<std::string> definitions = this->Internal->ClosureKeys();
-    res.insert(res.end(), definitions.begin(), definitions.end());
+    res = this->Internal->ClosureKeys();
     }
   std::vector<std::string> cacheKeys =
       this->GetState()->GetCacheEntryKeys();

http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=46ba0cc8cfd4d14d264f9ea8bd31819b356f23e8
commit 46ba0cc8cfd4d14d264f9ea8bd31819b356f23e8
Author:     Stephen Kelly <steveire at gmail.com>
AuthorDate: Sun Apr 26 15:38:09 2015 +0200
Commit:     Stephen Kelly <steveire at gmail.com>
CommitDate: Sun Apr 26 19:30:52 2015 +0200

    cmDefinitions: Inline GetClosureKeys implementation.

diff --git a/Source/cmDefinitions.cxx b/Source/cmDefinitions.cxx
index f6eddbc..bcb70e1 100644
--- a/Source/cmDefinitions.cxx
+++ b/Source/cmDefinitions.cxx
@@ -108,14 +108,7 @@ std::set<std::string> cmDefinitions::ClosureKeys() const
 {
   std::set<std::string> defined;
   std::set<std::string> undefined;
-  this->ClosureKeys(defined, undefined);
-  return defined;
-}
 
-//----------------------------------------------------------------------------
-void cmDefinitions::ClosureKeys(std::set<std::string>& defined,
-                                std::set<std::string>& undefined) const
-{
   cmDefinitions const* up = this;
 
   while (up)
@@ -134,4 +127,5 @@ void cmDefinitions::ClosureKeys(std::set<std::string>& defined,
       }
     up = this->Up;
     }
+  return defined;
 }
diff --git a/Source/cmDefinitions.h b/Source/cmDefinitions.h
index f927c13..1a8d8e8 100644
--- a/Source/cmDefinitions.h
+++ b/Source/cmDefinitions.h
@@ -79,10 +79,6 @@ private:
   cmDefinitions(ClosureTag const&, cmDefinitions const* root);
   void ClosureImpl(std::set<std::string>& undefined,
                    cmDefinitions const* defs);
-
-  // Implementation of ClosureKeys() method.
-  void ClosureKeys(std::set<std::string>& defined,
-                   std::set<std::string>& undefined) const;
 };
 
 #endif

http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=aa8a091b4c3a7658a94b9fe1c84b9a5622f26398
commit aa8a091b4c3a7658a94b9fe1c84b9a5622f26398
Author:     Stephen Kelly <steveire at gmail.com>
AuthorDate: Sun Apr 26 11:38:08 2015 +0200
Commit:     Stephen Kelly <steveire at gmail.com>
CommitDate: Sun Apr 26 19:30:51 2015 +0200

    cmDefinitions: Replace ClosureKeys recursion with looping.

diff --git a/Source/cmDefinitions.cxx b/Source/cmDefinitions.cxx
index 83a6053..f6eddbc 100644
--- a/Source/cmDefinitions.cxx
+++ b/Source/cmDefinitions.cxx
@@ -116,22 +116,22 @@ std::set<std::string> cmDefinitions::ClosureKeys() const
 void cmDefinitions::ClosureKeys(std::set<std::string>& defined,
                                 std::set<std::string>& undefined) const
 {
-  // Consider local definitions.
-  for(MapType::const_iterator mi = this->Map.begin();
-      mi != this->Map.end(); ++mi)
+  cmDefinitions const* up = this;
+
+  while (up)
     {
-    // Use this key if it is not already set or unset.
-    if(defined.find(mi->first) == defined.end() &&
-       undefined.find(mi->first) == undefined.end())
+    // Consider local definitions.
+    for(MapType::const_iterator mi = up->Map.begin();
+        mi != up->Map.end(); ++mi)
       {
-      std::set<std::string>& m = mi->second.Exists? defined : undefined;
-      m.insert(mi->first);
+      // Use this key if it is not already set or unset.
+      if(defined.find(mi->first) == defined.end() &&
+         undefined.find(mi->first) == undefined.end())
+        {
+        std::set<std::string>& m = mi->second.Exists? defined : undefined;
+        m.insert(mi->first);
+        }
       }
-    }
-
-  // Traverse parents.
-  if(cmDefinitions const* up = this->Up)
-    {
-    up->ClosureKeys(defined, undefined);
+    up = this->Up;
     }
 }

http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=28862c77df60049792a319c20c236832584f5527
commit 28862c77df60049792a319c20c236832584f5527
Author:     Stephen Kelly <steveire at gmail.com>
AuthorDate: Sun Apr 26 15:08:30 2015 +0200
Commit:     Stephen Kelly <steveire at gmail.com>
CommitDate: Sun Apr 26 19:30:51 2015 +0200

    cmDefinitions: Inline GetInternal into Get.

diff --git a/Source/cmDefinitions.cxx b/Source/cmDefinitions.cxx
index 899de1f..83a6053 100644
--- a/Source/cmDefinitions.cxx
+++ b/Source/cmDefinitions.cxx
@@ -20,7 +20,7 @@ cmDefinitions::cmDefinitions(cmDefinitions* parent)
 }
 
 //----------------------------------------------------------------------------
-std::pair<const char*, bool> cmDefinitions::GetInternal(const std::string& key)
+std::pair<const char*, bool> cmDefinitions::Get(const std::string& key)
 {
   MapType::const_iterator i = this->Map.find(key);
   std::pair<const char*, bool> result((const char*)0, false);
@@ -32,12 +32,6 @@ std::pair<const char*, bool> cmDefinitions::GetInternal(const std::string& key)
 }
 
 //----------------------------------------------------------------------------
-std::pair<const char*, bool> cmDefinitions::Get(const std::string& key)
-{
-  return this->GetInternal(key);
-}
-
-//----------------------------------------------------------------------------
 void cmDefinitions::Set(const std::string& key, const char* value)
 {
   Def def(value);
diff --git a/Source/cmDefinitions.h b/Source/cmDefinitions.h
index f4e35c5..f927c13 100644
--- a/Source/cmDefinitions.h
+++ b/Source/cmDefinitions.h
@@ -74,9 +74,6 @@ private:
 #endif
   MapType Map;
 
-  // Internal query and update methods.
-  std::pair<const char*, bool> GetInternal(const std::string& key);
-
   // Implementation of Closure() method.
   struct ClosureTag {};
   cmDefinitions(ClosureTag const&, cmDefinitions const* root);

http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=58f0624f341d2e0fb8559ee5099debc1285a3584
commit 58f0624f341d2e0fb8559ee5099debc1285a3584
Author:     Stephen Kelly <steveire at gmail.com>
AuthorDate: Sun Apr 26 13:10:43 2015 +0200
Commit:     Stephen Kelly <steveire at gmail.com>
CommitDate: Sun Apr 26 19:30:51 2015 +0200

    cmDefinitions: Externalize the stack loop for the Get method.
    
    Use a temporary vector to traverse the stack backwards.

diff --git a/Source/cmDefinitions.cxx b/Source/cmDefinitions.cxx
index 6c7257e..899de1f 100644
--- a/Source/cmDefinitions.cxx
+++ b/Source/cmDefinitions.cxx
@@ -32,28 +32,9 @@ std::pair<const char*, bool> cmDefinitions::GetInternal(const std::string& key)
 }
 
 //----------------------------------------------------------------------------
-const char* cmDefinitions::Get(const std::string& key)
+std::pair<const char*, bool> cmDefinitions::Get(const std::string& key)
 {
-  std::vector<cmDefinitions*> ups;
-  cmDefinitions* up = this;
-  std::pair<const char*, bool> result((const char*)0, false);
-  while (up)
-    {
-    result = up->GetInternal(key);
-    if(result.second)
-      {
-      break;
-      }
-    ups.push_back(up);
-    up = up->Up;
-    }
-  // Store the result in intermediate scopes.
-  for (std::vector<cmDefinitions*>::const_iterator it = ups.begin();
-       it != ups.end(); ++it)
-    {
-    (*it)->Set(key, result.first);
-    }
-  return result.first;
+  return this->GetInternal(key);
 }
 
 //----------------------------------------------------------------------------
diff --git a/Source/cmDefinitions.h b/Source/cmDefinitions.h
index a90c8ba..f4e35c5 100644
--- a/Source/cmDefinitions.h
+++ b/Source/cmDefinitions.h
@@ -21,8 +21,7 @@
  * \brief Store a scope of variable definitions for CMake language.
  *
  * This stores the state of variable definitions (set or unset) for
- * one scope.  Sets are always local.  Gets search parent scopes
- * transitively and save results locally.
+ * one scope.  Sets are always local.
  */
 class cmDefinitions
 {
@@ -33,9 +32,7 @@ public:
   /** Returns the parent scope, if any.  */
   cmDefinitions* GetParent() const { return this->Up; }
 
-  /** Get the value associated with a key; null if none.
-      Store the result locally if it came from a parent.  */
-  const char* Get(const std::string& key);
+  std::pair<const char*, bool> Get(const std::string& key);
 
   /** Set (or unset if null) a value associated with a key.  */
   void Set(const std::string& key, const char* value);
diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx
index a5c5fff..8573964 100644
--- a/Source/cmMakefile.cxx
+++ b/Source/cmMakefile.cxx
@@ -67,7 +67,30 @@ public:
 
   const char* GetDefinition(std::string const& name)
   {
-    return this->VarStack.back().Get(name);
+    std::vector<cmDefinitions*> defPtrs;
+    defPtrs.reserve(this->VarStack.size());
+    for (std::list<cmDefinitions>::iterator it = this->VarStack.begin();
+        it != this->VarStack.end(); ++it)
+      {
+      defPtrs.push_back(&*it);
+      }
+    std::pair<const char*, bool> result((const char*)0, false);
+    std::vector<cmDefinitions*>::reverse_iterator it = defPtrs.rbegin();
+    for ( ; it != defPtrs.rend(); ++it)
+      {
+      result = (*it)->Get(name);
+      if(result.second)
+        {
+        break;
+        }
+      }
+    std::vector<cmDefinitions*>::reverse_iterator last = it;
+    // Store the result in intermediate scopes.
+    for (it = defPtrs.rbegin(); it != last; ++it)
+      {
+      (*it)->Set(name, result.first);
+      }
+    return result.first;
   }
 
   void SetDefinition(std::string const& name, std::string const& value)

http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=fc98fa87a7d3740199f5b6d9309d5856bd507c28
commit fc98fa87a7d3740199f5b6d9309d5856bd507c28
Author:     Stephen Kelly <steveire at gmail.com>
AuthorDate: Sun Apr 26 13:10:43 2015 +0200
Commit:     Stephen Kelly <steveire at gmail.com>
CommitDate: Sun Apr 26 19:28:55 2015 +0200

    cmDefinitions: Extract loop from GetInternal to Get.
    
    Remove now-unused NoDef static member.

diff --git a/Source/cmDefinitions.cxx b/Source/cmDefinitions.cxx
index 35e36b4..6c7257e 100644
--- a/Source/cmDefinitions.cxx
+++ b/Source/cmDefinitions.cxx
@@ -14,26 +14,34 @@
 #include <assert.h>
 
 //----------------------------------------------------------------------------
-cmDefinitions::Def cmDefinitions::NoDef;
-
-//----------------------------------------------------------------------------
 cmDefinitions::cmDefinitions(cmDefinitions* parent)
   : Up(parent)
 {
 }
 
 //----------------------------------------------------------------------------
-const char* cmDefinitions::GetInternal(const std::string& key)
+std::pair<const char*, bool> cmDefinitions::GetInternal(const std::string& key)
+{
+  MapType::const_iterator i = this->Map.find(key);
+  std::pair<const char*, bool> result((const char*)0, false);
+  if(i != this->Map.end())
+    {
+    result = std::make_pair(i->second.Exists ? i->second.c_str() : 0, true);
+    }
+  return result;
+}
+
+//----------------------------------------------------------------------------
+const char* cmDefinitions::Get(const std::string& key)
 {
   std::vector<cmDefinitions*> ups;
-  Def def = this->NoDef;
   cmDefinitions* up = this;
+  std::pair<const char*, bool> result((const char*)0, false);
   while (up)
     {
-    MapType::const_iterator i = up->Map.find(key);
-    if(i != up->Map.end())
+    result = up->GetInternal(key);
+    if(result.second)
       {
-      def = i->second;
       break;
       }
     ups.push_back(up);
@@ -43,15 +51,9 @@ const char* cmDefinitions::GetInternal(const std::string& key)
   for (std::vector<cmDefinitions*>::const_iterator it = ups.begin();
        it != ups.end(); ++it)
     {
-    (*it)->Set(key, def.Exists? def.c_str() : 0);
+    (*it)->Set(key, result.first);
     }
-  return def.Exists? def.c_str() : 0;
-}
-
-//----------------------------------------------------------------------------
-const char* cmDefinitions::Get(const std::string& key)
-{
-  return this->GetInternal(key);
+  return result.first;
 }
 
 //----------------------------------------------------------------------------
diff --git a/Source/cmDefinitions.h b/Source/cmDefinitions.h
index f2c71c5..a90c8ba 100644
--- a/Source/cmDefinitions.h
+++ b/Source/cmDefinitions.h
@@ -65,7 +65,6 @@ private:
     Def(Def const& d): std_string(d), Exists(d.Exists) {}
     bool Exists;
   };
-  static Def NoDef;
 
   // Parent scope, if any.
   cmDefinitions* Up;
@@ -79,7 +78,7 @@ private:
   MapType Map;
 
   // Internal query and update methods.
-  const char* GetInternal(const std::string& key);
+  std::pair<const char*, bool> GetInternal(const std::string& key);
 
   // Implementation of Closure() method.
   struct ClosureTag {};

http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=2c24078f8046b456f81c3cd8cf4bb9cf1f963f27
commit 2c24078f8046b456f81c3cd8cf4bb9cf1f963f27
Author:     Stephen Kelly <steveire at gmail.com>
AuthorDate: Sun Apr 26 13:28:19 2015 +0200
Commit:     Stephen Kelly <steveire at gmail.com>
CommitDate: Sun Apr 26 19:28:55 2015 +0200

    cmDefinitions: Use Set API in Get implementation.

diff --git a/Source/cmDefinitions.cxx b/Source/cmDefinitions.cxx
index 3cdeb07..35e36b4 100644
--- a/Source/cmDefinitions.cxx
+++ b/Source/cmDefinitions.cxx
@@ -43,7 +43,7 @@ const char* cmDefinitions::GetInternal(const std::string& key)
   for (std::vector<cmDefinitions*>::const_iterator it = ups.begin();
        it != ups.end(); ++it)
     {
-    (*it)->Map[key] = def;
+    (*it)->Set(key, def.Exists? def.c_str() : 0);
     }
   return def.Exists? def.c_str() : 0;
 }

http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=b5185748d66ec850d78fc4e206803943d323fe3c
commit b5185748d66ec850d78fc4e206803943d323fe3c
Author:     Stephen Kelly <steveire at gmail.com>
AuthorDate: Sun Apr 26 15:09:11 2015 +0200
Commit:     Stephen Kelly <steveire at gmail.com>
CommitDate: Sun Apr 26 19:28:55 2015 +0200

    cmDefinitions: Use map::operator[] in Get.
    
    The key is not already in the map.

diff --git a/Source/cmDefinitions.cxx b/Source/cmDefinitions.cxx
index 3ea2c36..3cdeb07 100644
--- a/Source/cmDefinitions.cxx
+++ b/Source/cmDefinitions.cxx
@@ -43,7 +43,7 @@ const char* cmDefinitions::GetInternal(const std::string& key)
   for (std::vector<cmDefinitions*>::const_iterator it = ups.begin();
        it != ups.end(); ++it)
     {
-    (*it)->Map.insert(MapType::value_type(key, def));
+    (*it)->Map[key] = def;
     }
   return def.Exists? def.c_str() : 0;
 }

http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=155c334ce3517a3f6e0a32daded9cf3c5b01c5b9
commit 155c334ce3517a3f6e0a32daded9cf3c5b01c5b9
Author:     Stephen Kelly <steveire at gmail.com>
AuthorDate: Sun Apr 26 13:02:25 2015 +0200
Commit:     Stephen Kelly <steveire at gmail.com>
CommitDate: Sun Apr 26 19:28:54 2015 +0200

    cmDefinitions: Simplify API of GetInternal.
    
    Remove need to keep iterator over loops.

diff --git a/Source/cmDefinitions.cxx b/Source/cmDefinitions.cxx
index 8705dfa..3ea2c36 100644
--- a/Source/cmDefinitions.cxx
+++ b/Source/cmDefinitions.cxx
@@ -23,16 +23,14 @@ cmDefinitions::cmDefinitions(cmDefinitions* parent)
 }
 
 //----------------------------------------------------------------------------
-cmDefinitions::Def const&
-cmDefinitions::GetInternal(const std::string& key)
+const char* cmDefinitions::GetInternal(const std::string& key)
 {
   std::vector<cmDefinitions*> ups;
   Def def = this->NoDef;
-  MapType::const_iterator i;
   cmDefinitions* up = this;
   while (up)
     {
-    i = up->Map.find(key);
+    MapType::const_iterator i = up->Map.find(key);
     if(i != up->Map.end())
       {
       def = i->second;
@@ -45,16 +43,15 @@ cmDefinitions::GetInternal(const std::string& key)
   for (std::vector<cmDefinitions*>::const_iterator it = ups.begin();
        it != ups.end(); ++it)
     {
-    i = (*it)->Map.insert(MapType::value_type(key, def)).first;
+    (*it)->Map.insert(MapType::value_type(key, def));
     }
-  return i->second;
+  return def.Exists? def.c_str() : 0;
 }
 
 //----------------------------------------------------------------------------
 const char* cmDefinitions::Get(const std::string& key)
 {
-  Def const& def = this->GetInternal(key);
-  return def.Exists? def.c_str() : 0;
+  return this->GetInternal(key);
 }
 
 //----------------------------------------------------------------------------
diff --git a/Source/cmDefinitions.h b/Source/cmDefinitions.h
index 13f885d..f2c71c5 100644
--- a/Source/cmDefinitions.h
+++ b/Source/cmDefinitions.h
@@ -79,7 +79,7 @@ private:
   MapType Map;
 
   // Internal query and update methods.
-  Def const& GetInternal(const std::string& key);
+  const char* GetInternal(const std::string& key);
 
   // Implementation of Closure() method.
   struct ClosureTag {};

http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=cafd52c76189c5659a1d32f9ad15a0f5b69a2370
commit cafd52c76189c5659a1d32f9ad15a0f5b69a2370
Author:     Stephen Kelly <steveire at gmail.com>
AuthorDate: Sun Apr 26 12:48:43 2015 +0200
Commit:     Stephen Kelly <steveire at gmail.com>
CommitDate: Sun Apr 26 19:28:54 2015 +0200

    cmDefinitions: Remove conditionals before loop.
    
    They are now redundant.
    
    In the previous code, we knew that this->Map did not contain the
    searched value, so we stored 'this' in the ups list.  Now we don't
    know that prior to the loop.  Only cmDefinitions which do not
    contain the value should be in the ups list.

diff --git a/Source/cmDefinitions.cxx b/Source/cmDefinitions.cxx
index 91107b1..8705dfa 100644
--- a/Source/cmDefinitions.cxx
+++ b/Source/cmDefinitions.cxx
@@ -26,19 +26,10 @@ cmDefinitions::cmDefinitions(cmDefinitions* parent)
 cmDefinitions::Def const&
 cmDefinitions::GetInternal(const std::string& key)
 {
-  MapType::const_iterator i = this->Map.find(key);
-  if(i != this->Map.end())
-    {
-    return i->second;
-    }
-  cmDefinitions* up = this->Up;
-  if(!up)
-    {
-    return this->NoDef;
-    }
   std::vector<cmDefinitions*> ups;
-  ups.push_back(this);
   Def def = this->NoDef;
+  MapType::const_iterator i;
+  cmDefinitions* up = this;
   while (up)
     {
     i = up->Map.find(key);

http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=038ba6f3624af88a633976a71e2a7653e684efcc
commit 038ba6f3624af88a633976a71e2a7653e684efcc
Author:     Stephen Kelly <steveire at gmail.com>
AuthorDate: Sun Apr 26 12:19:42 2015 +0200
Commit:     Stephen Kelly <steveire at gmail.com>
CommitDate: Sun Apr 26 19:28:54 2015 +0200

    cmDefinitions: Replace GetInternal recursion with looping.

diff --git a/Source/cmDefinitions.cxx b/Source/cmDefinitions.cxx
index 34ba509..91107b1 100644
--- a/Source/cmDefinitions.cxx
+++ b/Source/cmDefinitions.cxx
@@ -36,9 +36,27 @@ cmDefinitions::GetInternal(const std::string& key)
     {
     return this->NoDef;
     }
-  // Query the parent scope and store the result locally.
-  Def def = up->GetInternal(key);
-  return this->Map.insert(MapType::value_type(key, def)).first->second;
+  std::vector<cmDefinitions*> ups;
+  ups.push_back(this);
+  Def def = this->NoDef;
+  while (up)
+    {
+    i = up->Map.find(key);
+    if(i != up->Map.end())
+      {
+      def = i->second;
+      break;
+      }
+    ups.push_back(up);
+    up = up->Up;
+    }
+  // Store the result in intermediate scopes.
+  for (std::vector<cmDefinitions*>::const_iterator it = ups.begin();
+       it != ups.end(); ++it)
+    {
+    i = (*it)->Map.insert(MapType::value_type(key, def)).first;
+    }
+  return i->second;
 }
 
 //----------------------------------------------------------------------------

http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=8fdea5ae4b50924b147e67082e2efacdbb79944e
commit 8fdea5ae4b50924b147e67082e2efacdbb79944e
Author:     Stephen Kelly <steveire at gmail.com>
AuthorDate: Sun Apr 26 12:39:53 2015 +0200
Commit:     Stephen Kelly <steveire at gmail.com>
CommitDate: Sun Apr 26 19:28:54 2015 +0200

    cmDefinitions: Invert conditional code.
    
    Return the simple case first.

diff --git a/Source/cmDefinitions.cxx b/Source/cmDefinitions.cxx
index 032a96e..34ba509 100644
--- a/Source/cmDefinitions.cxx
+++ b/Source/cmDefinitions.cxx
@@ -31,13 +31,14 @@ cmDefinitions::GetInternal(const std::string& key)
     {
     return i->second;
     }
-  if(cmDefinitions* up = this->Up)
+  cmDefinitions* up = this->Up;
+  if(!up)
     {
-    // Query the parent scope and store the result locally.
-    Def def = up->GetInternal(key);
-    return this->Map.insert(MapType::value_type(key, def)).first->second;
+    return this->NoDef;
     }
-  return this->NoDef;
+  // Query the parent scope and store the result locally.
+  Def def = up->GetInternal(key);
+  return this->Map.insert(MapType::value_type(key, def)).first->second;
 }
 
 //----------------------------------------------------------------------------

http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=47c946d48fa1024e1964fc64a1a5db4ac8b48470
commit 47c946d48fa1024e1964fc64a1a5db4ac8b48470
Author:     Stephen Kelly <steveire at gmail.com>
AuthorDate: Sat Apr 25 16:36:48 2015 +0200
Commit:     Stephen Kelly <steveire at gmail.com>
CommitDate: Sun Apr 26 19:28:53 2015 +0200

    cmDefinitions: Externalize the Set logic.

diff --git a/Source/cmDefinitions.cxx b/Source/cmDefinitions.cxx
index 58500c9..032a96e 100644
--- a/Source/cmDefinitions.cxx
+++ b/Source/cmDefinitions.cxx
@@ -11,6 +11,8 @@
 ============================================================================*/
 #include "cmDefinitions.h"
 
+#include <assert.h>
+
 //----------------------------------------------------------------------------
 cmDefinitions::Def cmDefinitions::NoDef;
 
@@ -49,16 +51,7 @@ const char* cmDefinitions::Get(const std::string& key)
 void cmDefinitions::Set(const std::string& key, const char* value)
 {
   Def def(value);
-  if(this->Up || def.Exists)
-    {
-    // In lower scopes we store keys, defined or not.
-    this->Map[key] = def;
-    }
-  else
-    {
-    // In the top-most scope we need not store undefined keys.
-    this->Map.erase(key);
-    }
+  this->Map[key] = def;
 }
 
 void cmDefinitions::Erase(const std::string& key)
diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx
index 96700d6..a5c5fff 100644
--- a/Source/cmMakefile.cxx
+++ b/Source/cmMakefile.cxx
@@ -77,7 +77,15 @@ public:
 
   void RemoveDefinition(std::string const& name)
   {
-    this->VarStack.back().Set(name, 0);
+    if (this->VarStack.size() > 1)
+      {
+      // In lower scopes we store keys, defined or not.
+      this->VarStack.back().Set(name, 0);
+      }
+    else
+      {
+      this->VarStack.back().Erase(name);
+      }
   }
 
   std::set<std::string> LocalKeys() const

http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=3137703457930a453c611e9cc51ee7b90338f585
commit 3137703457930a453c611e9cc51ee7b90338f585
Author:     Stephen Kelly <steveire at gmail.com>
AuthorDate: Sat Apr 25 16:33:26 2015 +0200
Commit:     Stephen Kelly <steveire at gmail.com>
CommitDate: Sun Apr 26 19:28:53 2015 +0200

    cmDefinitions: Add an Erase method.

diff --git a/Source/cmDefinitions.cxx b/Source/cmDefinitions.cxx
index abb46b3..58500c9 100644
--- a/Source/cmDefinitions.cxx
+++ b/Source/cmDefinitions.cxx
@@ -61,6 +61,11 @@ void cmDefinitions::Set(const std::string& key, const char* value)
     }
 }
 
+void cmDefinitions::Erase(const std::string& key)
+{
+  this->Map.erase(key);
+}
+
 //----------------------------------------------------------------------------
 std::set<std::string> cmDefinitions::LocalKeys() const
 {
diff --git a/Source/cmDefinitions.h b/Source/cmDefinitions.h
index 83cd0d9..13f885d 100644
--- a/Source/cmDefinitions.h
+++ b/Source/cmDefinitions.h
@@ -40,6 +40,8 @@ public:
   /** Set (or unset if null) a value associated with a key.  */
   void Set(const std::string& key, const char* value);
 
+  void Erase(const std::string& key);
+
   /** Get the set of all local keys.  */
   std::set<std::string> LocalKeys() const;
 

http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=0d8fdbb5a18b60905646d6a5b1432dfdfd32320f
commit 0d8fdbb5a18b60905646d6a5b1432dfdfd32320f
Author:     Stephen Kelly <steveire at gmail.com>
AuthorDate: Sun Apr 26 11:33:47 2015 +0200
Commit:     Stephen Kelly <steveire at gmail.com>
CommitDate: Sun Apr 26 19:28:53 2015 +0200

    cmDefinitions: Inline SetInternal method.

diff --git a/Source/cmDefinitions.cxx b/Source/cmDefinitions.cxx
index d5f6ebc..abb46b3 100644
--- a/Source/cmDefinitions.cxx
+++ b/Source/cmDefinitions.cxx
@@ -39,9 +39,16 @@ cmDefinitions::GetInternal(const std::string& key)
 }
 
 //----------------------------------------------------------------------------
-cmDefinitions::Def const&
-cmDefinitions::SetInternal(const std::string& key, Def const& def)
+const char* cmDefinitions::Get(const std::string& key)
 {
+  Def const& def = this->GetInternal(key);
+  return def.Exists? def.c_str() : 0;
+}
+
+//----------------------------------------------------------------------------
+void cmDefinitions::Set(const std::string& key, const char* value)
+{
+  Def def(value);
   if(this->Up || def.Exists)
     {
     // In lower scopes we store keys, defined or not.
@@ -55,19 +62,6 @@ cmDefinitions::SetInternal(const std::string& key, Def const& def)
 }
 
 //----------------------------------------------------------------------------
-const char* cmDefinitions::Get(const std::string& key)
-{
-  Def const& def = this->GetInternal(key);
-  return def.Exists? def.c_str() : 0;
-}
-
-//----------------------------------------------------------------------------
-void cmDefinitions::Set(const std::string& key, const char* value)
-{
-  this->SetInternal(key, Def(value));
-}
-
-//----------------------------------------------------------------------------
 std::set<std::string> cmDefinitions::LocalKeys() const
 {
   std::set<std::string> keys;
diff --git a/Source/cmDefinitions.h b/Source/cmDefinitions.h
index 690df1f..83cd0d9 100644
--- a/Source/cmDefinitions.h
+++ b/Source/cmDefinitions.h
@@ -78,7 +78,6 @@ private:
 
   // Internal query and update methods.
   Def const& GetInternal(const std::string& key);
-  Def const& SetInternal(const std::string& key, Def const& def);
 
   // Implementation of Closure() method.
   struct ClosureTag {};

http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=22d354d7963bbd678ad67d0450bfde6458005c3b
commit 22d354d7963bbd678ad67d0450bfde6458005c3b
Author:     Stephen Kelly <steveire at gmail.com>
AuthorDate: Sat Apr 25 16:29:54 2015 +0200
Commit:     Stephen Kelly <steveire at gmail.com>
CommitDate: Sun Apr 26 19:28:53 2015 +0200

    cmDefinitions: Remove unused Set return value.

diff --git a/Source/cmDefinitions.cxx b/Source/cmDefinitions.cxx
index 6a27659..d5f6ebc 100644
--- a/Source/cmDefinitions.cxx
+++ b/Source/cmDefinitions.cxx
@@ -45,13 +45,12 @@ cmDefinitions::SetInternal(const std::string& key, Def const& def)
   if(this->Up || def.Exists)
     {
     // In lower scopes we store keys, defined or not.
-    return (this->Map[key] = def);
+    this->Map[key] = def;
     }
   else
     {
     // In the top-most scope we need not store undefined keys.
     this->Map.erase(key);
-    return this->NoDef;
     }
 }
 
@@ -63,10 +62,9 @@ const char* cmDefinitions::Get(const std::string& key)
 }
 
 //----------------------------------------------------------------------------
-const char* cmDefinitions::Set(const std::string& key, const char* value)
+void cmDefinitions::Set(const std::string& key, const char* value)
 {
-  Def const& def = this->SetInternal(key, Def(value));
-  return def.Exists? def.c_str() : 0;
+  this->SetInternal(key, Def(value));
 }
 
 //----------------------------------------------------------------------------
diff --git a/Source/cmDefinitions.h b/Source/cmDefinitions.h
index ab588ee..690df1f 100644
--- a/Source/cmDefinitions.h
+++ b/Source/cmDefinitions.h
@@ -38,7 +38,7 @@ public:
   const char* Get(const std::string& key);
 
   /** Set (or unset if null) a value associated with a key.  */
-  const char* Set(const std::string& key, const char* value);
+  void Set(const std::string& key, const char* value);
 
   /** Get the set of all local keys.  */
   std::set<std::string> LocalKeys() const;

http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=882e18954e742cb6ef8c9455643e0f46c2c2e1c0
commit 882e18954e742cb6ef8c9455643e0f46c2c2e1c0
Author:     Stephen Kelly <steveire at gmail.com>
AuthorDate: Sat Apr 25 17:21:51 2015 +0200
Commit:     Stephen Kelly <steveire at gmail.com>
CommitDate: Sun Apr 26 19:28:46 2015 +0200

    cmMakefile: Remove stack adaptor for the VarStack.
    
    The purpose of the stack is to allow access only to the top of it.  Access
    to items which are not at the top is needed, so cmDefinitions objects
    get a Parent pointer.  Because that Parent pointer must not be left
    dangling, the stack must be implemented with a linked list.
    
    These are all problems resulting from the incorrect use of stack in the
    first place as it is not a suitable interface for what is needed here.  Remove
    it now.

diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx
index 9da01db..96700d6 100644
--- a/Source/cmMakefile.cxx
+++ b/Source/cmMakefile.cxx
@@ -38,7 +38,6 @@
 #include <cmsys/FStream.hxx>
 #include <cmsys/auto_ptr.hxx>
 
-#include <stack>
 #include <list>
 #include <ctype.h> // for isspace
 #include <assert.h>
@@ -46,7 +45,7 @@
 class cmMakefile::Internals
 {
 public:
-  std::stack<cmDefinitions, std::list<cmDefinitions> > VarStack;
+  std::list<cmDefinitions> VarStack;
   std::stack<std::set<std::string> > VarInitStack;
   std::stack<std::set<std::string> > VarUsageStack;
   bool IsSourceFileTryCompile;
@@ -56,49 +55,49 @@ public:
     cmDefinitions* parent = 0;
     if (!this->VarStack.empty())
       {
-      parent = &this->VarStack.top();
+      parent = &this->VarStack.back();
       }
-    this->VarStack.push(cmDefinitions(parent));
+    this->VarStack.push_back(cmDefinitions(parent));
   }
 
   void InitializeDefinitions(cmMakefile* parent)
   {
-    this->VarStack.top() = parent->Internal->VarStack.top().Closure();
+    this->VarStack.back() = parent->Internal->VarStack.back().Closure();
   }
 
   const char* GetDefinition(std::string const& name)
   {
-    return this->VarStack.top().Get(name);
+    return this->VarStack.back().Get(name);
   }
 
   void SetDefinition(std::string const& name, std::string const& value)
   {
-    this->VarStack.top().Set(name, value.c_str());
+    this->VarStack.back().Set(name, value.c_str());
   }
 
   void RemoveDefinition(std::string const& name)
   {
-    this->VarStack.top().Set(name, 0);
+    this->VarStack.back().Set(name, 0);
   }
 
   std::set<std::string> LocalKeys() const
   {
-    return this->VarStack.top().LocalKeys();
+    return this->VarStack.back().LocalKeys();
   }
 
   std::set<std::string> ClosureKeys() const
   {
-    return this->VarStack.top().ClosureKeys();
+    return this->VarStack.back().ClosureKeys();
   }
 
   void PopDefinitions()
   {
-    this->VarStack.pop();
+    this->VarStack.pop_back();
   }
 
   bool RaiseScope(std::string const& var, const char* varDef, cmMakefile* mf)
   {
-    cmDefinitions& cur = this->VarStack.top();
+    cmDefinitions& cur = this->VarStack.back();
     if(cmDefinitions* up = cur.GetParent())
       {
       // First localize the definition in the current scope.

-----------------------------------------------------------------------

Summary of changes:


hooks/post-receive
-- 
CMake


More information about the Cmake-commits mailing list