]> git.saurik.com Git - wxWidgets.git/commitdiff
Use iterators instead of indices in wxStripMenuCodes().
authorVadim Zeitlin <vadim@wxwidgets.org>
Tue, 15 May 2012 10:03:53 +0000 (10:03 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Tue, 15 May 2012 10:03:53 +0000 (10:03 +0000)
Make the function more efficient when using UTF-8 wxStrings by using iterators
instead of indices in the loop searching for "&".

Closes #14307.

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

src/common/utilscmn.cpp

index 1dae85d7f0adb7482d63eb6dfe316495bd37643c..d9ce6b56ff9589990ef07e5a04351b9974ff2398 100644 (file)
@@ -1184,22 +1184,22 @@ wxString wxStripMenuCodes(const wxString& in, int flags)
     size_t len = in.length();
     out.reserve(len);
 
-    for ( size_t n = 0; n < len; n++ )
+    for ( wxString::const_iterator it = in.begin(); it != in.end(); ++it )
     {
-        wxChar ch = in[n];
+        wxChar ch = *it;
         if ( (flags & wxStrip_Mnemonics) && ch == wxT('&') )
         {
             // skip it, it is used to introduce the accel char (or to quote
             // itself in which case it should still be skipped): note that it
             // can't be the last character of the string
-            if ( ++n == len )
+            if ( ++it == in.end() )
             {
                 wxLogDebug(wxT("Invalid menu string '%s'"), in.c_str());
             }
             else
             {
                 // use the next char instead
-                ch = in[n];
+                ch = *it;
             }
         }
         else if ( (flags & wxStrip_Accel) && ch == wxT('\t') )