-  wxASSERT( str.GetStringData()->IsValid() );
-  wxASSERT( nStart == npos || nStart <= length() );
-
-  // TODO could be made much quicker than that
-  const wxChar *p = c_str() + (nStart == npos ? length() : nStart);
-  while ( p >= c_str() + str.length() ) {
-    if ( wxStrncmp(p - str.length(), str.c_str(), str.length()) == 0 )
-      return p - str.length() - c_str();
-    p--;
-  }
+    wxASSERT( str.GetStringData()->IsValid() );
+    wxASSERT( nStart == npos || nStart <= length() );
+
+    if ( length() >= str.length() )
+    {
+        // avoids a corner case later
+        if ( length() == 0 && str.length() == 0 )
+            return 0;
+
+        // "top" is the point where search starts from
+        size_t top = length() - str.length();