no need to heap allocate these

Change-Id: I28127f5943a80aca1689d5982cd1f6e6e11eb2c5
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/175863
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
This commit is contained in:
Noel Grandin
2024-11-01 07:27:27 +01:00
parent 6bd9f1f933
commit cf14352cd8
11 changed files with 45 additions and 48 deletions
+6 -6
View File
@@ -1704,18 +1704,18 @@ void SbModule::GetCodeCompleteDataFromParse(CodeCompleteDataCache& aCache)
ErrorHdlResetter aErrHdl;
SbxBase::ResetError();
auto pParser = std::make_unique<SbiParser>(static_cast<StarBASIC*>(GetParent()), this );
pParser->SetCodeCompleting(true);
SbiParser aParser(static_cast<StarBASIC*>(GetParent()), this );
aParser.SetCodeCompleting(true);
while( pParser->Parse() ) {}
SbiSymPool* pPool = pParser->pPool;
while( aParser.Parse() ) {}
SbiSymPool* pPool = aParser.pPool;
aCache.Clear();
for( sal_uInt16 i = 0; i < pPool->GetSize(); ++i )
{
SbiSymDef* pSymDef = pPool->Get(i);
//std::cerr << "i: " << i << ", type: " << pSymDef->GetType() << "; name:" << pSymDef->GetName() << std::endl;
if( (pSymDef->GetType() != SbxEMPTY) && (pSymDef->GetType() != SbxNULL) )
aCache.InsertGlobalVar( pSymDef->GetName(), pParser->aGblStrings.Find(pSymDef->GetTypeId()) );
aCache.InsertGlobalVar( pSymDef->GetName(), aParser.aGblStrings.Find(pSymDef->GetTypeId()) );
SbiSymPool& rChildPool = pSymDef->GetPool();
for(sal_uInt16 j = 0; j < rChildPool.GetSize(); ++j )
@@ -1723,7 +1723,7 @@ void SbModule::GetCodeCompleteDataFromParse(CodeCompleteDataCache& aCache)
SbiSymDef* pChildSymDef = rChildPool.Get(j);
//std::cerr << "j: " << j << ", type: " << pChildSymDef->GetType() << "; name:" << pChildSymDef->GetName() << std::endl;
if( (pChildSymDef->GetType() != SbxEMPTY) && (pChildSymDef->GetType() != SbxNULL) )
aCache.InsertLocalVar( pSymDef->GetName(), pChildSymDef->GetName(), pParser->aGblStrings.Find(pChildSymDef->GetTypeId()) );
aCache.InsertLocalVar( pSymDef->GetName(), pChildSymDef->GetName(), aParser.aGblStrings.Find(pChildSymDef->GetTypeId()) );
}
}
}
+7 -9
View File
@@ -53,9 +53,7 @@ void SbiParser::Print()
{
if( !IsEoln( Peek() ) )
{
auto pExpr = std::make_unique<SbiExpression>(this);
pExpr->Gen();
pExpr.reset();
SbiExpression(this).Gen();
Peek();
aGen.Gen( eCurTok == COMMA ? SbiOpcode::PRINTF_ : SbiOpcode::BPRINT_ );
}
@@ -82,7 +80,7 @@ void SbiParser::Write()
while( !bAbort )
{
auto pExpr = std::make_unique<SbiExpression>(this);
std::optional<SbiExpression> pExpr(std::in_place, this);
pExpr->Gen();
pExpr.reset();
aGen.Gen( SbiOpcode::BWRITE_ );
@@ -130,7 +128,7 @@ void SbiParser::Line()
void SbiParser::LineInput()
{
Channel( true );
auto pExpr = std::make_unique<SbiExpression>( this, SbOPERAND );
std::optional<SbiExpression> pExpr( std::in_place, this, SbOPERAND );
if( !pExpr->IsVariable() )
Error( ERRCODE_BASIC_VAR_EXPECTED );
if( pExpr->GetType() != SbxVARIANT && pExpr->GetType() != SbxSTRING )
@@ -147,7 +145,7 @@ void SbiParser::Input()
{
aGen.Gen( SbiOpcode::RESTART_ );
Channel( true );
auto pExpr = std::make_unique<SbiExpression>( this, SbOPERAND );
std::optional<SbiExpression> pExpr( std::in_place, this, SbOPERAND );
while( !bAbort )
{
if( !pExpr->IsVariable() )
@@ -157,7 +155,7 @@ void SbiParser::Input()
if( Peek() == COMMA )
{
Next();
pExpr.reset(new SbiExpression( this, SbOPERAND ));
pExpr.emplace( this, SbOPERAND );
}
else break;
}
@@ -236,7 +234,7 @@ void SbiParser::Open()
}
TestToken( AS );
// channel number
auto pChan = std::make_unique<SbiExpression>( this );
SbiExpression aChan( this );
std::unique_ptr<SbiExpression> pLen;
if( Peek() == SYMBOL )
{
@@ -253,7 +251,7 @@ void SbiParser::Open()
// channel number
// file name
pLen->Gen();
pChan->Gen();
aChan.Gen();
aFileName.Gen();
aGen.Gen( SbiOpcode::OPEN_, static_cast<sal_uInt32>(nMode), static_cast<sal_uInt32>(nFlags) );
bInStatement = false;
+3 -3
View File
@@ -597,11 +597,11 @@ void SbiParser::Set()
if( eTok == NEW )
{
Next();
auto pTypeDef = std::make_unique<SbiSymDef>( OUString() );
TypeDecl( *pTypeDef, true );
SbiSymDef aTypeDef( u""_ustr );
TypeDecl( aTypeDef, true );
aLvalue.Gen();
aGen.Gen( SbiOpcode::CREATE_, pDef->GetId(), pTypeDef->GetTypeId() );
aGen.Gen( SbiOpcode::CREATE_, pDef->GetId(), aTypeDef.GetTypeId() );
aGen.Gen( SbiOpcode::SETCLASS_, pDef->GetTypeId() );
}
else
+7 -7
View File
@@ -796,12 +796,12 @@ void SfxLibraryContainer::init_Impl( const OUString& rInitialDocumentURL,
source.sSystemId = aFileName;
// start parsing
auto pLibArray = std::make_unique<::xmlscript::LibDescriptorArray> ( );
::xmlscript::LibDescriptorArray aLibArray;
Reference< XParser > xParser = xml::sax::Parser::create(mxContext);
try
{
xParser->setDocumentHandler( ::xmlscript::importLibraryContainer( pLibArray.get() ) );
xParser->setDocumentHandler( ::xmlscript::importLibraryContainer( &aLibArray ) );
xParser->parseStream( source );
}
catch ( const xml::sax::SAXException& )
@@ -815,10 +815,10 @@ void SfxLibraryContainer::init_Impl( const OUString& rInitialDocumentURL,
return;
}
sal_Int32 nLibCount = pLibArray->mnLibCount;
sal_Int32 nLibCount = aLibArray.mnLibCount;
for( sal_Int32 i = 0 ; i < nLibCount ; i++ )
{
::xmlscript::LibDescriptor& rLib = pLibArray->mpLibs[i];
::xmlscript::LibDescriptor& rLib = aLibArray.mpLibs[i];
// Check storage URL
OUString aStorageURL = rLib.aStorageURL;
@@ -1859,7 +1859,7 @@ void SfxLibraryContainer::storeLibraries_Impl( const uno::Reference< embed::XSto
int iArray = 0;
pName = aNames.getConstArray();
::xmlscript::LibDescriptor aLibDescriptorForExtensionLibs;
auto pLibArray = std::make_unique< ::xmlscript::LibDescriptorArray > ( nLibsToSave );
::xmlscript::LibDescriptorArray aLibArray( nLibsToSave );
for( ; pName != pNamesEnd; ++pName )
{
SfxLibrary* pImplLib = getImplLib( *pName );
@@ -1869,7 +1869,7 @@ void SfxLibraryContainer::storeLibraries_Impl( const uno::Reference< embed::XSto
}
const bool bExtensionLib = pImplLib->mbExtension;
::xmlscript::LibDescriptor& rLib = bExtensionLib ?
aLibDescriptorForExtensionLibs : pLibArray->mpLibs[iArray];
aLibDescriptorForExtensionLibs : aLibArray.mpLibs[iArray];
if( !bExtensionLib )
{
iArray++;
@@ -2112,7 +2112,7 @@ void SfxLibraryContainer::storeLibraries_Impl( const uno::Reference< embed::XSto
try
{
xmlscript::exportLibraryContainer( xWriter, pLibArray.get() );
xmlscript::exportLibraryContainer( xWriter, &aLibArray );
if ( bStorage )
{
uno::Reference< embed::XTransactedObject > xTransact( xTargetLibrariesStor, uno::UNO_QUERY_THROW );
+2 -2
View File
@@ -335,11 +335,11 @@ void SfxScriptLibraryContainer::importFromOldStorage( const OUString& aFile )
rtl::Reference<SotStorage> xStorage(new SotStorage(false, aFile));
if( xStorage->GetError() == ERRCODE_NONE )
{
auto pBasicManager = std::make_unique<BasicManager> ( *xStorage, aFile );
BasicManager aBasicManager( *xStorage, aFile );
// Set info
LibraryContainerInfo aInfo( this, nullptr, this );
pBasicManager->SetLibraryContainerInfo( aInfo );
aBasicManager.SetLibraryContainerInfo( aInfo );
}
}
@@ -278,11 +278,11 @@ IMPL_LINK_NOARG(ScreenshotAnnotationDlg_Impl, saveButtonHandler, weld::Button&,
// get a suggestion for the filename from buildable name
OUString aDerivedFileName = mrParentDialog.get_buildable_name();
auto xFileDlg = std::make_unique<sfx2::FileDialogHelper>(ui::dialogs::TemplateDescription::FILESAVE_AUTOEXTENSION,
sfx2::FileDialogHelper aFileDlg(ui::dialogs::TemplateDescription::FILESAVE_AUTOEXTENSION,
FileDialogFlags::NONE, mpParentWindow);
xFileDlg->SetContext(sfx2::FileDialogHelper::ScreenshotAnnotation);
aFileDlg.SetContext(sfx2::FileDialogHelper::ScreenshotAnnotation);
const uno::Reference< ui::dialogs::XFilePicker3 > xFilePicker = xFileDlg->GetFilePicker();
const uno::Reference< ui::dialogs::XFilePicker3 > xFilePicker = aFileDlg.GetFilePicker();
xFilePicker->setTitle(maSaveAsText);
+1 -2
View File
@@ -501,10 +501,9 @@ bool Picture::Read(HWPFile & hwpf)
if (pictype == PICTYPE_DRAW)
{
auto xGuard(std::make_unique<ChangeMemGuard>(follow.data(), follow_block_size));
ChangeMemGuard aGuard(follow.data(), follow_block_size);
LoadDrawingObjectBlock(this, hwpf);
style.cell = picinfo.picdraw.hdo;
xGuard.reset();
}
else if (follow_block_size >= 4)
{
+3 -3
View File
@@ -112,15 +112,15 @@ SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv)
//UCollator *coll = ucol_openRules(Obuf.getStr(), Obuf.getLength(), UCOL_OFF,
// UCOL_DEFAULT_STRENGTH, &parseError, &status);
auto coll = std::make_unique<icu::RuleBasedCollator>(reinterpret_cast<const UChar *>(Obuf.getStr()), status);
icu::RuleBasedCollator coll(reinterpret_cast<const UChar *>(Obuf.getStr()), status);
if (U_SUCCESS(status)) {
std::vector<uint8_t> data;
int32_t len = coll->cloneBinary(nullptr, 0, status);
int32_t len = coll.cloneBinary(nullptr, 0, status);
if (status == U_BUFFER_OVERFLOW_ERROR) {
data.resize(len);
status = U_ZERO_ERROR;
len = coll->cloneBinary(data.data(), len, status);
len = coll.cloneBinary(data.data(), len, status);
}
if (U_SUCCESS(status))
data_write(argv[2], argv[3], data.data(), len);
+6 -6
View File
@@ -431,21 +431,21 @@ bool ScDocumentLoader::GetFilterName( const OUString& rFileName,
// Filter detection
std::shared_ptr<const SfxFilter> pSfxFilter;
auto pMedium = std::make_unique<SfxMedium>( rFileName, StreamMode::STD_READ );
if (pMedium->GetErrorIgnoreWarning() == ERRCODE_NONE && !comphelper::IsFuzzing())
SfxMedium aMedium( rFileName, StreamMode::STD_READ );
if (aMedium.GetErrorIgnoreWarning() == ERRCODE_NONE && !comphelper::IsFuzzing())
{
if ( bWithInteraction )
pMedium->UseInteractionHandler(true); // #i73992# no longer called from GuessFilter
aMedium.UseInteractionHandler(true); // #i73992# no longer called from GuessFilter
SfxFilterMatcher aMatcher(u"scalc"_ustr);
if( bWithContent )
aMatcher.GuessFilter( *pMedium, pSfxFilter );
aMatcher.GuessFilter( aMedium, pSfxFilter );
else
aMatcher.GuessFilterIgnoringContent( *pMedium, pSfxFilter );
aMatcher.GuessFilterIgnoringContent( aMedium, pSfxFilter );
}
bool bOK = false;
if ( pMedium->GetErrorIgnoreWarning() == ERRCODE_NONE )
if ( aMedium.GetErrorIgnoreWarning() == ERRCODE_NONE )
{
if ( pSfxFilter )
rFilter = pSfxFilter->GetFilterName();
+5 -5
View File
@@ -659,14 +659,14 @@ void SwSelPaintRects::HighlightContentControl()
}
if (pCurContentControlAtCursor)
{
auto pCursorForContentControl = std::make_unique<SwShellCursor>(
SwShellCursor aCursorForContentControl(
*GetShell(), SwPosition(*pTextNode, pCurContentControlAtCursor->GetStart()));
pCursorForContentControl->SetMark();
pCursorForContentControl->GetMark()->Assign(
aCursorForContentControl.SetMark();
aCursorForContentControl.GetMark()->Assign(
*pTextNode, *(pCurContentControlAtCursor->End()));
pCursorForContentControl->FillRects();
SwRects* pRects = pCursorForContentControl.get();
aCursorForContentControl.FillRects();
SwRects* pRects = &aCursorForContentControl;
for (const auto& rRect : *pRects)
{
tools::Rectangle aRect(rRect.SVRect());
+2 -2
View File
@@ -793,10 +793,10 @@ static void lcl_SaveDebugDoc( SfxObjectShell *xTargetDocShell,
// aTempFile is not deleted, but that seems to be intentional
utl::TempFileNamed aTempFile( basename, true, u".odt", &sTempDirURL );
INetURLObject aTempFileURL( aTempFile.GetURL() );
auto pDstMed = std::make_unique<SfxMedium>(
SfxMedium aDstMed(
aTempFileURL.GetMainURL( INetURLObject::DecodeMechanism::NONE ),
StreamMode::STD_READWRITE );
bool bAnyError = !xTargetDocShell->DoSaveAs( *pDstMed );
bool bAnyError = !xTargetDocShell->DoSaveAs( aDstMed );
// xObjectShell->DoSaveCompleted crashes the mail merge unit tests, so skip it
bAnyError |= (ERRCODE_NONE != xTargetDocShell->GetErrorIgnoreWarning());
if( bAnyError )