Kaydet (Commit) bd44b3ee authored tarafından Noel Grandin's avatar Noel Grandin

tdf#89522 PERF FILEOPEN xlsx, part 1

Inherit from tools::WeakBase non-virtually, so that we can use a
static_cast in tools::WeakReference::get instead of a dynamic_cast.

This takes the file-open time from 1m21 to 40s for me.

Add a clang plugin to make sure we don't accidentally end up inheriting
from tools::WeakBase more than once.

Change-Id: I9c7c36403333f99094e1f9d8cce2ecd9200377f9
Reviewed-on: https://gerrit.libreoffice.org/71231Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
Tested-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst 81297c29
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
namespace tools
{
struct WeakBase
{
virtual ~WeakBase();
};
}
struct Foo1 : public tools::WeakBase
{
virtual ~Foo1();
};
struct Foo2 : public tools::WeakBase
{
virtual ~Foo2();
};
// expected-error@+1 {{multiple copies of WeakBase, through inheritance paths Bar->Foo1->WeakBase, Bar->Foo2->WeakBase [loplugin:weakbase]}}
struct Bar : public Foo1, public Foo2
{
virtual ~Bar();
};
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include <string>
#include <iostream>
#include <map>
#include <set>
#include "plugin.hxx"
#include "clang/AST/CXXInheritance.h"
/**
* Check for multiple copies of WeakBase in base classes
*/
namespace
{
class WeakBase : public loplugin::FilteringPlugin<WeakBase>
{
public:
explicit WeakBase(loplugin::InstantiationData const& data)
: FilteringPlugin(data)
{
}
virtual void run() override { TraverseDecl(compiler.getASTContext().getTranslationUnitDecl()); }
bool VisitCXXRecordDecl(CXXRecordDecl const*);
};
bool WeakBase::VisitCXXRecordDecl(CXXRecordDecl const* recordDecl)
{
if (ignoreLocation(recordDecl))
{
return true;
}
// StringRef aFileName = getFileNameOfSpellingLoc(
// compiler.getSourceManager().getSpellingLoc(compat::getBeginLoc(fieldDecl)));
// if (loplugin::hasPathnamePrefix(aFileName, SRCDIR "/chart2/source/"))
// return true;
// if (loplugin::isSamePathname(aFileName, SRCDIR "/include/sfx2/recentdocsview.hxx"))
// return true;
// if (loplugin::isSamePathname(aFileName, SRCDIR "/include/sfx2/templatelocalview.hxx"))
// return true;
// if (loplugin::isSamePathname(aFileName, SRCDIR "/store/source/stortree.hxx")
// || loplugin::isSamePathname(aFileName, SRCDIR "/store/source/stordata.hxx"))
// return true;
// if (loplugin::isSamePathname(aFileName, SRCDIR "/sw/source/uibase/inc/dbtree.hxx"))
// return true;
recordDecl = recordDecl->getCanonicalDecl();
if (!recordDecl->hasDefinition())
return true;
int noWeakBases = 0;
std::string basePaths;
auto BaseMatchesCallback = [&](const CXXBaseSpecifier* cxxBaseSpecifier, CXXBasePath& Paths) {
if (!cxxBaseSpecifier->getType().getTypePtr())
return false;
const CXXRecordDecl* baseCXXRecordDecl = cxxBaseSpecifier->getType()->getAsCXXRecordDecl();
if (!baseCXXRecordDecl)
return false;
if (baseCXXRecordDecl->isInvalidDecl())
return false;
if (baseCXXRecordDecl->getName() != "WeakBase")
return false;
++noWeakBases;
std::string sPath;
for (CXXBasePathElement const& pathElement : Paths)
{
if (!sPath.empty())
{
sPath += "->";
}
if (pathElement.Class->hasDefinition())
sPath += pathElement.Class->getNameAsString();
else
sPath += "???";
}
sPath += "->";
sPath += baseCXXRecordDecl->getNameAsString();
if (!basePaths.empty())
basePaths += ", ";
basePaths += sPath;
return false;
};
CXXBasePaths aPaths;
recordDecl->lookupInBases(BaseMatchesCallback, aPaths);
if (noWeakBases > 1)
{
report(DiagnosticsEngine::Warning,
"multiple copies of WeakBase, through inheritance paths %0",
compat::getBeginLoc(recordDecl))
<< basePaths << recordDecl->getSourceRange();
}
return true;
}
loplugin::Plugin::Registration<WeakBase> WeakBase("weakbase", true);
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
......@@ -143,7 +143,7 @@ public:
struct SdrModelImpl;
class SVX_DLLPUBLIC SdrModel : public SfxBroadcaster, public virtual tools::WeakBase
class SVX_DLLPUBLIC SdrModel : public SfxBroadcaster, public tools::WeakBase
{
private:
#ifdef DBG_UTIL
......
......@@ -304,7 +304,7 @@ public:
// SwFlyDrawObj
/// Abstract DrawObject
class SVX_DLLPUBLIC SdrObject : public SfxListener, public virtual tools::WeakBase
class SVX_DLLPUBLIC SdrObject : public SfxListener, public tools::WeakBase
{
private:
friend class SdrObjListIter;
......
......@@ -364,7 +364,7 @@ public:
// SwDPage
// OReportPage
class SVX_DLLPUBLIC SdrPage : public SdrObjList, public virtual tools::WeakBase
class SVX_DLLPUBLIC SdrPage : public SdrObjList, public tools::WeakBase
{
// #i9076#
friend class SdrModel;
......
......@@ -41,7 +41,7 @@ namespace sdr { namespace properties {
*/
class SfxStyleSheet;
class SVX_DLLPUBLIC SdrText : public virtual tools::WeakBase
class SVX_DLLPUBLIC SdrText : public tools::WeakBase
{
public:
explicit SdrText( SdrTextObj& rObject );
......
......@@ -146,7 +146,7 @@ public:
};
class SVX_DLLPUBLIC SdrView : public SdrCreateView, public virtual tools::WeakBase
class SVX_DLLPUBLIC SdrView : public SdrCreateView, public tools::WeakBase
{
friend class SdrPageView;
......
......@@ -61,9 +61,10 @@ template< class reference_type >
inline reference_type * WeakReference< reference_type >::get() const
{
auto pWeakBase = mpWeakConnection->mpReference;
auto pRet = dynamic_cast<reference_type *>(pWeakBase);
assert((pWeakBase && pRet) || (!pWeakBase && !pRet));
return pRet;
if (!pWeakBase)
return nullptr;
assert(dynamic_cast<reference_type *>(pWeakBase));
return static_cast<reference_type *>(pWeakBase);
}
template< class reference_type >
......
......@@ -79,6 +79,7 @@ $(eval $(call gb_CompilerTest_add_exception_objects,compilerplugins_clang, \
compilerplugins/clang/test/unusedvariablemore \
compilerplugins/clang/test/useuniqueptr \
compilerplugins/clang/test/vclwidgets \
compilerplugins/clang/test/weakbase \
compilerplugins/clang/test/writeonlyvars \
))
......
......@@ -1113,8 +1113,8 @@ void SdrPageProperties::SetStyleSheet(SfxStyleSheet* pStyleSheet)
SdrPage::SdrPage(SdrModel& rModel, bool bMasterPage)
: tools::WeakBase(),
SdrObjList(),
: SdrObjList(),
tools::WeakBase(),
maPageUsers(),
mrSdrModelFromSdrPage(rModel),
mnWidth(10),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment