basic/source/runtime/methods.cxx |   19 ++++++-------------
 1 file changed, 6 insertions(+), 13 deletions(-)

New commits:
commit ced3501a93fd44621d7d5e0479df72657a0f085d
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Mon May 9 16:31:32 2022 +0100
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Mon May 9 21:42:29 2022 +0200

    Unify and simplify SbRtl_Hex and SbRtl_Oct
    
    OUStringNumber::toAsciiUpperCase is cheaper than OUString::toAsciiUpperCase.
    
    Let SbRtl_Oct use OUString::number as well.
    
    Change-Id: I3a97ec5d3a7b0005fc300310198bae47c62dfbc6
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/134061
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>

diff --git a/basic/source/runtime/methods.cxx b/basic/source/runtime/methods.cxx
index 2ebae2751157..4393041b7808 100644
--- a/basic/source/runtime/methods.cxx
+++ b/basic/source/runtime/methods.cxx
@@ -783,9 +783,7 @@ void SbRtl_Hex(StarBASIC *, SbxArray & rPar, bool)
         sal_uInt32 nVal = pArg->IsInteger() ?
             static_cast<sal_uInt16>(pArg->GetInteger()) :
             static_cast<sal_uInt32>(pArg->GetLong());
-        OUString aStr(OUString::number( nVal, 16 ));
-        aStr = aStr.toAsciiUpperCase();
-        rPar.Get(0)->PutString(aStr);
+        rPar.Get(0)->PutString(OUString::number(nVal, 16).toAsciiUpperCase());
     }
 }
 
@@ -1202,17 +1200,12 @@ void SbRtl_Oct(StarBASIC *, SbxArray & rPar, bool)
     }
     else
     {
-        char aBuffer[16];
         SbxVariableRef pArg = rPar.Get(1);
-        if ( pArg->IsInteger() )
-        {
-            snprintf( aBuffer, sizeof(aBuffer), "%o", pArg->GetInteger() );
-        }
-        else
-        {
-            snprintf( aBuffer, sizeof(aBuffer), "%lo", static_cast<long 
unsigned int>(pArg->GetLong()) );
-        }
-        rPar.Get(0)->PutString(OUString::createFromAscii(aBuffer));
+        // converting value to unsigned and limit to 2 or 4 byte representation
+        sal_uInt32 nVal = pArg->IsInteger() ?
+            static_cast<sal_uInt16>(pArg->GetInteger()) :
+            static_cast<sal_uInt32>(pArg->GetLong());
+        rPar.Get(0)->PutString(OUString::number(nVal, 8));
     }
 }
 

Reply via email to