diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2022-05-09 16:31:32 +0100 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2022-05-09 21:42:29 +0200 |
commit | ced3501a93fd44621d7d5e0479df72657a0f085d (patch) | |
tree | ab97e49972bb8673083cb594a43c4af1dcbcf1fd | |
parent | cbbdcfd49db545f4f3e4041453706f33065267b7 (diff) |
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.kaganski@collabora.com>
-rw-r--r-- | basic/source/runtime/methods.cxx | 19 |
1 files changed, 6 insertions, 13 deletions
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)); } } |