From 742d99332fe7c44b8caba8f8092f506aeb5c3f63 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Wed, 13 May 2015 16:47:55 -0700 Subject: [PATCH] Bug 1163916 (part 1) - Avoid a static nsDebugImpl constructor. r=froydnj. --- xpcom/base/nsDebugImpl.cpp | 10 +++++++--- xpcom/base/nsDebugImpl.h | 4 +--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/xpcom/base/nsDebugImpl.cpp b/xpcom/base/nsDebugImpl.cpp index 69874490356..0bca387cb13 100644 --- a/xpcom/base/nsDebugImpl.cpp +++ b/xpcom/base/nsDebugImpl.cpp @@ -579,16 +579,20 @@ Break(const char* aMsg) #endif } -static const nsDebugImpl kImpl; - nsresult nsDebugImpl::Create(nsISupports* aOuter, const nsIID& aIID, void** aInstancePtr) { + static const nsDebugImpl* sImpl; + if (NS_WARN_IF(aOuter)) { return NS_ERROR_NO_AGGREGATION; } - return const_cast(&kImpl)->QueryInterface(aIID, aInstancePtr); + if (!sImpl) { + sImpl = new nsDebugImpl(); + } + + return const_cast(sImpl)->QueryInterface(aIID, aInstancePtr); } //////////////////////////////////////////////////////////////////////////////// diff --git a/xpcom/base/nsDebugImpl.h b/xpcom/base/nsDebugImpl.h index 4cfb7527db5..23680238a4e 100644 --- a/xpcom/base/nsDebugImpl.h +++ b/xpcom/base/nsDebugImpl.h @@ -12,9 +12,7 @@ class nsDebugImpl : public nsIDebug2 { public: - nsDebugImpl() - { - } + nsDebugImpl() = default; NS_DECL_ISUPPORTS NS_DECL_NSIDEBUG2