From ced3501a93fd44621d7d5e0479df72657a0f085d Mon Sep 17 00:00:00 2001 From: Mike Kaganski Date: Mon, 9 May 2022 16:31:32 +0100 Subject: 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 --- basic/source/runtime/methods.cxx | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) (limited to 'basic') 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(pArg->GetInteger()) : static_cast(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(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(pArg->GetInteger()) : + static_cast(pArg->GetLong()); + rPar.Get(0)->PutString(OUString::number(nVal, 8)); } } -- cgit