summaryrefslogtreecommitdiff
path: root/basic
diff options
context:
space:
mode:
authorEike Rathke <erack@redhat.com>2017-11-24 14:24:03 +0100
committerEike Rathke <erack@redhat.com>2017-11-24 21:30:02 +0100
commit4b98e352e543d0462f2727c5762552e32ef4d76a (patch)
tree1e3053920c8418cefad7ffddf8f4bdd2b4f562b1 /basic
parent4e3530b4f870e0470c23ae89cdb8b9a09af54d59 (diff)
Make the SbiInstance SvNumberFormatter shared_ptr
In preparation to get rid of the per call locally created SvNumberFormatter instances.. Change-Id: Ic7db3bbb655aa18e939f5722964655a20f2eadf2 Reviewed-on: https://gerrit.libreoffice.org/45227 Reviewed-by: Eike Rathke <erack@redhat.com> Tested-by: Eike Rathke <erack@redhat.com>
Diffstat (limited to 'basic')
-rw-r--r--basic/source/inc/runtime.hxx6
-rw-r--r--basic/source/runtime/methods.cxx34
-rw-r--r--basic/source/runtime/methods1.cxx7
-rw-r--r--basic/source/runtime/runtime.cxx24
4 files changed, 21 insertions, 50 deletions
diff --git a/basic/source/inc/runtime.hxx b/basic/source/inc/runtime.hxx
index dc92fb87f3d9..86baec31ac53 100644
--- a/basic/source/inc/runtime.hxx
+++ b/basic/source/inc/runtime.hxx
@@ -133,7 +133,7 @@ class SbiInstance
std::unique_ptr<SbiDdeControl> pDdeCtrl;
// DLL-Calls (DECLARE)
std::unique_ptr<SbiDllMgr> pDllMgr;
- std::unique_ptr<SvNumberFormatter> pNumberFormatter;
+ std::shared_ptr<SvNumberFormatter> pNumberFormatter;
StarBASIC* pBasic;
LanguageType meFormatterLangType;
DateOrder meFormatterDateOrder;
@@ -186,13 +186,13 @@ public:
SbiDllMgr* GetDllMgr();
SbiRTLData* GetRTLData() const { return const_cast<SbiRTLData*>(&aRTLData); }
- SvNumberFormatter* GetNumberFormatter();
+ std::shared_ptr<SvNumberFormatter> GetNumberFormatter();
sal_uInt32 GetStdDateIdx() const { return nStdDateIdx; }
sal_uInt32 GetStdTimeIdx() const { return nStdTimeIdx; }
sal_uInt32 GetStdDateTimeIdx() const { return nStdDateTimeIdx; }
// offer NumberFormatter also static
- static SvNumberFormatter* PrepareNumberFormatter( sal_uInt32 &rnStdDateIdx,
+ static std::shared_ptr<SvNumberFormatter> PrepareNumberFormatter( sal_uInt32 &rnStdDateIdx,
sal_uInt32 &rnStdTimeIdx, sal_uInt32 &rnStdDateTimeIdx,
LanguageType const * peFormatterLangType=nullptr, DateOrder const * peFormatterDateOrder=nullptr );
};
diff --git a/basic/source/runtime/methods.cxx b/basic/source/runtime/methods.cxx
index 6cbde3a5dcaa..6b47d8b2a78f 100644
--- a/basic/source/runtime/methods.cxx
+++ b/basic/source/runtime/methods.cxx
@@ -2032,7 +2032,7 @@ void SbRtl_DateValue(StarBASIC *, SbxArray & rPar, bool)
else
{
// #39629 check GetSbData()->pInst, can be called from the URL line
- SvNumberFormatter* pFormatter = nullptr;
+ std::shared_ptr<SvNumberFormatter> pFormatter;
if( GetSbData()->pInst )
{
pFormatter = GetSbData()->pInst->GetNumberFormatter();
@@ -2083,11 +2083,6 @@ void SbRtl_DateValue(StarBASIC *, SbxArray & rPar, bool)
{
StarBASIC::Error( ERRCODE_BASIC_CONVERSION );
}
- // #39629 pFormatter can be requested itself
- if( !GetSbData()->pInst )
- {
- delete pFormatter;
- }
}
}
@@ -2099,7 +2094,7 @@ void SbRtl_TimeValue(StarBASIC *, SbxArray & rPar, bool)
}
else
{
- SvNumberFormatter* pFormatter = nullptr;
+ std::shared_ptr<SvNumberFormatter> pFormatter;
if( GetSbData()->pInst )
pFormatter = GetSbData()->pInst->GetNumberFormatter();
else
@@ -2126,10 +2121,6 @@ void SbRtl_TimeValue(StarBASIC *, SbxArray & rPar, bool)
{
StarBASIC::Error( ERRCODE_BASIC_CONVERSION );
}
- if( !GetSbData()->pInst )
- {
- delete pFormatter;
- }
}
}
@@ -2288,7 +2279,7 @@ void SbRtl_Time(StarBASIC *, SbxArray & rPar, bool bWrite)
double nDays = (double)nSeconds * ( 1.0 / (24.0*3600.0) );
Color* pCol;
- SvNumberFormatter* pFormatter = nullptr;
+ std::shared_ptr<SvNumberFormatter> pFormatter;
sal_uInt32 nIndex;
if( GetSbData()->pInst )
{
@@ -2302,11 +2293,6 @@ void SbRtl_Time(StarBASIC *, SbxArray & rPar, bool bWrite)
}
pFormatter->GetOutputString( nDays, nIndex, aRes, &pCol );
-
- if( !GetSbData()->pInst )
- {
- delete pFormatter;
- }
}
pMeth->PutString( aRes );
}
@@ -2339,7 +2325,7 @@ void SbRtl_Date(StarBASIC *, SbxArray & rPar, bool bWrite)
OUString aRes;
Color* pCol;
- SvNumberFormatter* pFormatter = nullptr;
+ std::shared_ptr<SvNumberFormatter> pFormatter;
sal_uInt32 nIndex;
if( GetSbData()->pInst )
{
@@ -2354,11 +2340,6 @@ void SbRtl_Date(StarBASIC *, SbxArray & rPar, bool bWrite)
pFormatter->GetOutputString( nDays, nIndex, aRes, &pCol );
pMeth->PutString( aRes );
-
- if( !GetSbData()->pInst )
- {
- delete pFormatter;
- }
}
else
{
@@ -3097,7 +3078,7 @@ void SbRtl_FileDateTime(StarBASIC *, SbxArray & rPar, bool)
Color* pCol;
- SvNumberFormatter* pFormatter = nullptr;
+ std::shared_ptr<SvNumberFormatter> pFormatter;
sal_uInt32 nIndex;
if( GetSbData()->pInst )
{
@@ -3113,11 +3094,6 @@ void SbRtl_FileDateTime(StarBASIC *, SbxArray & rPar, bool)
OUString aRes;
pFormatter->GetOutputString( fSerial, nIndex, aRes, &pCol );
rPar.Get(0)->PutString( aRes );
-
- if( !GetSbData()->pInst )
- {
- delete pFormatter;
- }
}
}
diff --git a/basic/source/runtime/methods1.cxx b/basic/source/runtime/methods1.cxx
index ad9424a56976..f6d404dd548d 100644
--- a/basic/source/runtime/methods1.cxx
+++ b/basic/source/runtime/methods1.cxx
@@ -2332,7 +2332,7 @@ void SbRtl_FormatDateTime(StarBASIC *, SbxArray & rPar, bool)
// Dienstag, 21. December 2004
case 1:
{
- SvNumberFormatter* pFormatter = nullptr;
+ std::shared_ptr<SvNumberFormatter> pFormatter;
if( GetSbData()->pInst )
{
pFormatter = GetSbData()->pInst->GetNumberFormatter();
@@ -2347,11 +2347,6 @@ void SbRtl_FormatDateTime(StarBASIC *, SbxArray & rPar, bool)
const sal_uInt32 nIndex = pFormatter->GetFormatIndex( NF_DATE_SYSTEM_LONG, eLangType );
Color* pCol;
pFormatter->GetOutputString( dDate, nIndex, aRetStr, &pCol );
-
- if( !GetSbData()->pInst )
- {
- delete pFormatter;
- }
break;
}
diff --git a/basic/source/runtime/runtime.cxx b/basic/source/runtime/runtime.cxx
index 0c4af5336882..2eaa60f85e5f 100644
--- a/basic/source/runtime/runtime.cxx
+++ b/basic/source/runtime/runtime.cxx
@@ -357,7 +357,7 @@ SbiDllMgr* SbiInstance::GetDllMgr()
}
// #39629 create NumberFormatter with the help of a static method now
-SvNumberFormatter* SbiInstance::GetNumberFormatter()
+std::shared_ptr<SvNumberFormatter> SbiInstance::GetNumberFormatter()
{
LanguageType eLangType = Application::GetSettings().GetLanguageTag().getLanguageType();
SvtSysLocale aSysLocale;
@@ -367,25 +367,24 @@ SvNumberFormatter* SbiInstance::GetNumberFormatter()
if( eLangType != meFormatterLangType ||
eDate != meFormatterDateOrder )
{
- pNumberFormatter.reset(nullptr);
+ pNumberFormatter.reset();
}
}
meFormatterLangType = eLangType;
meFormatterDateOrder = eDate;
if( !pNumberFormatter )
{
- pNumberFormatter.reset(PrepareNumberFormatter( nStdDateIdx, nStdTimeIdx, nStdDateTimeIdx,
- &meFormatterLangType, &meFormatterDateOrder ));
+ pNumberFormatter = PrepareNumberFormatter( nStdDateIdx, nStdTimeIdx, nStdDateTimeIdx,
+ &meFormatterLangType, &meFormatterDateOrder);
}
- return pNumberFormatter.get();
+ return pNumberFormatter;
}
// #39629 offer NumberFormatter static too
-SvNumberFormatter* SbiInstance::PrepareNumberFormatter( sal_uInt32 &rnStdDateIdx,
+std::shared_ptr<SvNumberFormatter> SbiInstance::PrepareNumberFormatter( sal_uInt32 &rnStdDateIdx,
sal_uInt32 &rnStdTimeIdx, sal_uInt32 &rnStdDateTimeIdx,
LanguageType const * peFormatterLangType, DateOrder const * peFormatterDateOrder )
{
- SvNumberFormatter* pNumberFormater = nullptr;
LanguageType eLangType;
if( peFormatterLangType )
{
@@ -406,10 +405,11 @@ SvNumberFormatter* SbiInstance::PrepareNumberFormatter( sal_uInt32 &rnStdDateIdx
eDate = aSysLocale.GetLocaleData().getDateOrder();
}
- pNumberFormater = new SvNumberFormatter( comphelper::getProcessComponentContext(), eLangType );
+ std::shared_ptr<SvNumberFormatter> pNumberFormatter(
+ new SvNumberFormatter( comphelper::getProcessComponentContext(), eLangType ));
sal_Int32 nCheckPos = 0; short nType;
- rnStdTimeIdx = pNumberFormater->GetStandardFormat( css::util::NumberFormat::TIME, eLangType );
+ rnStdTimeIdx = pNumberFormatter->GetStandardFormat( css::util::NumberFormat::TIME, eLangType );
// the formatter's standard templates have only got a two-digit date
// -> registering an own format
@@ -428,14 +428,14 @@ SvNumberFormatter* SbiInstance::PrepareNumberFormatter( sal_uInt32 &rnStdDateIdx
case DateOrder::YMD: aDateStr = "YYYY/MM/DD"; break;
}
OUString aStr( aDateStr ); // PutandConvertEntry() modifies string!
- pNumberFormater->PutandConvertEntry( aStr, nCheckPos, nType,
+ pNumberFormatter->PutandConvertEntry( aStr, nCheckPos, nType,
rnStdDateIdx, LANGUAGE_ENGLISH_US, eLangType );
nCheckPos = 0;
aDateStr += " HH:MM:SS";
aStr = aDateStr;
- pNumberFormater->PutandConvertEntry( aStr, nCheckPos, nType,
+ pNumberFormatter->PutandConvertEntry( aStr, nCheckPos, nType,
rnStdDateTimeIdx, LANGUAGE_ENGLISH_US, eLangType );
- return pNumberFormater;
+ return pNumberFormatter;
}