Hi,

before submitting patches on gerrit, I would like to have your feed back to make sure I'm right.

'OUString' have 'indexOf' that can find a substring (literal or OUString) or a char. IMO, looking for a 1 char long string is the same as looking for this char itself. However, the later is faster. In some cases, we even allocate memory before doing the search !


Example #1: we allocate memory to build a 1 char long string and search for it
>>>>>>>>>>>>>>>>>>
diff --git a/sc/source/ui/vba/vbafilesearch.cxx b/sc/source/ui/vba/vbafilesearch.cxx
index ddb5c04..220b2e2 100644
--- a/sc/source/ui/vba/vbafilesearch.cxx
+++ b/sc/source/ui/vba/vbafilesearch.cxx
@@ -180,7 +180,7 @@ sal_Int32 SAL_CALL ScVbaFileSearch::Execute( ) throw (css::uno::RuntimeExceptio
     if ( IsWildCard( aTempFileName ) )
     {
         bool bEndWithAsterisk = aTempFileName.endsWithAsciiL("*", 1);
- bool bStartWithAsterisk = (aTempFileName.indexOf(::rtl::OUString("*")) == 0);
+        bool bStartWithAsterisk = (aTempFileName.indexOf('*')) == 0);
         if ( !bEndWithAsterisk && !bStartWithAsterisk )
         {
aTempFileName = ::rtl::OUString("*") + aTempFileName + ::rtl::OUString("*");
>>>>>>>>>>>>>>>>>>

Example #2: we search for a 1 char string
>>>>>>>>>>>>>>>>>>
diff --git a/shell/source/tools/lngconvex/lngconvex.cxx b/shell/source/tools/lngconvex/lngconvex.cxx
index 5b2ecb2..dce42ab 100644
--- a/shell/source/tools/lngconvex/lngconvex.cxx
+++ b/shell/source/tools/lngconvex/lngconvex.cxx
@@ -200,7 +200,7 @@ public:
 private:
     void init()
     {
-        sal_Int32 idx = lang_.indexOf("-");
+        sal_Int32 idx = lang_.indexOf('-');

         if (idx > -1)
         {
>>>>>>>>>>>>>>>>>>

In both cases, I think it is safe to search only for the char irself.


There are a few of these that can be cleanup.
If you agree with this, I will provide a patch via gerrit.

Best regards



_______________________________________________
LibreOffice mailing list
LibreOffice@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice

Reply via email to