diff --git a/SystemTools.cxx b/SystemTools.cxx
index e657f6905c88855cfd44f44845bf59bffe21e101..a2681c162d5a2a49e9f9d9d65d193ff865b3fa38 100644
--- a/SystemTools.cxx
+++ b/SystemTools.cxx
@@ -3130,17 +3130,19 @@ SystemToolsAppendComponents(
   kwsys_stl::vector<kwsys_stl::string>::const_iterator first,
   kwsys_stl::vector<kwsys_stl::string>::const_iterator last)
 {
+  static const kwsys_stl::string up = "..";
+  static const kwsys_stl::string cur = ".";
   for(kwsys_stl::vector<kwsys_stl::string>::const_iterator i = first;
       i != last; ++i)
     {
-    if(*i == "..")
+    if(*i == up)
       {
       if(out_components.size() > 1)
         {
-        out_components.erase(out_components.end()-1, out_components.end());
+        out_components.resize(out_components.size()-1);
         }
       }
-    else if(!(*i == ".") && !(*i == ""))
+    else if(!i->empty() && *i != cur)
       {
       out_components.push_back(*i);
       }