]> git.saurik.com Git - wxWidgets.git/commitdiff
Use single BeforeLast() call in wxConfigPathChanger ctor.
authorVadim Zeitlin <vadim@wxwidgets.org>
Fri, 22 Oct 2010 14:17:42 +0000 (14:17 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Fri, 22 Oct 2010 14:17:42 +0000 (14:17 +0000)
Use a single BeforeLast() call with the "rest" argument and avoid calling
AfterLast() laster in wxConfigPathChanger ctor.

This is a small optimization which may count because wxConfigPathChanger is
used in a lot of wxFileConfig functions but, even more importantly, this works
around a bug in g++ 4 optimized build when the name was not filled by
AfterLast() call correctly as apparently the optimizer decided it was not
used. The real cause of this compiler bug was difficult to find as it couldn't
be reproduced in a simple test case but this change avoids it and fixes
wxFileConfig unit test in optimized build.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@65863 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/common/config.cpp

index 6de614b83a4fd84bb796b77797da075bea3a1ede..636b490e3914dfd07372d87567059ed78b90d28f 100644 (file)
@@ -284,8 +284,9 @@ wxConfigPathChanger::wxConfigPathChanger(const wxConfigBase *pContainer,
   m_bChanged = false;
   m_pContainer = const_cast<wxConfigBase *>(pContainer);
 
-  // the path is everything which precedes the last slash
-  wxString strPath = strEntry.BeforeLast(wxCONFIG_PATH_SEPARATOR);
+  // the path is everything which precedes the last slash and the name is
+  // everything after it -- and this works correctly if there is no slash too
+  wxString strPath = strEntry.BeforeLast(wxCONFIG_PATH_SEPARATOR, &m_strName);
 
   // except in the special case of "/keyname" when there is nothing before "/"
   if ( strPath.empty() &&
@@ -317,13 +318,6 @@ wxConfigPathChanger::wxConfigPathChanger(const wxConfigBase *pContainer,
           m_strOldPath += wxCONFIG_PATH_SEPARATOR;
         m_pContainer->SetPath(strPath);
     }
-
-    // in any case, use the just the name, not full path
-    m_strName = strEntry.AfterLast(wxCONFIG_PATH_SEPARATOR);
-  }
-  else {
-    // it's a name only, without path - nothing to do
-    m_strName = strEntry;
   }
 }