Date: prev next · Thread: first prev next last
2012 Archives by date, by thread · List index


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




Context


Privacy Policy | Impressum (Legal Info) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Creative Commons Attribution-Share Alike 3.0 License. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License (MPLv2). "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy.