From 4e11e803b4bf6e97e7993acb5509bfa0b506816f Mon Sep 17 00:00:00 2001 From: John Haddon Date: Wed, 23 Jul 2025 12:39:01 +0100 Subject: [PATCH] RefCounted, RunTimeTyped : Inline constructor and destructor Since these do nothing, or almost nothing, it seems beneficial to let the compiler know that. This gives 3-7% performance improvements in specific `Gaffer::Context` benchmarks. --- Changes | 5 ++++ include/IECore/RefCounted.h | 4 +-- include/IECore/RunTimeTyped.h | 4 +-- src/IECore/RefCounted.cpp | 50 ----------------------------------- src/IECore/RunTimeTyped.cpp | 8 ------ 5 files changed, 9 insertions(+), 62 deletions(-) delete mode 100644 src/IECore/RefCounted.cpp diff --git a/Changes b/Changes index cd8971a2c0..c6050fa4d9 100644 --- a/Changes +++ b/Changes @@ -1,6 +1,11 @@ 10.6.x.x (relative to 10.6.0.0a1) ======== +Improvements +------------ + +- RefCounted, RunTimeTyped : Inlined constructor and destructor. + Breaking Changes ---------------- diff --git a/include/IECore/RefCounted.h b/include/IECore/RefCounted.h index d0a4da30e4..068f3cf3c6 100644 --- a/include/IECore/RefCounted.h +++ b/include/IECore/RefCounted.h @@ -132,7 +132,7 @@ class IECORE_API RefCounted : private boost::noncopyable typedef size_t RefCount; - RefCounted(); + RefCounted() : m_numRefs( 0 ) {} /// Add a reference to the current object inline void addRef() const { m_numRefs++; }; @@ -152,7 +152,7 @@ class IECORE_API RefCounted : private boost::noncopyable protected: - virtual ~RefCounted(); + virtual ~RefCounted() {} private : diff --git a/include/IECore/RunTimeTyped.h b/include/IECore/RunTimeTyped.h index 5ffe332512..9b8ecbccfa 100644 --- a/include/IECore/RunTimeTyped.h +++ b/include/IECore/RunTimeTyped.h @@ -218,8 +218,8 @@ class IECORE_API RunTimeTyped : public RefCounted IE_CORE_DECLAREMEMBERPTR( RunTimeTyped ); - RunTimeTyped(); - ~RunTimeTyped() override; + RunTimeTyped() {} + ~RunTimeTyped() override {} //! @name Type identification functions. /// These functions provide useful queries about the typing diff --git a/src/IECore/RefCounted.cpp b/src/IECore/RefCounted.cpp deleted file mode 100644 index 654b9cc3d5..0000000000 --- a/src/IECore/RefCounted.cpp +++ /dev/null @@ -1,50 +0,0 @@ -////////////////////////////////////////////////////////////////////////// -// -// Copyright (c) 2007-2010, Image Engine Design Inc. All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// -// * Redistributions in binary form must reproduce the above copyright -// notice, this list of conditions and the following disclaimer in the -// documentation and/or other materials provided with the distribution. -// -// * Neither the name of Image Engine Design nor the names of any -// other contributors to this software may be used to endorse or -// promote products derived from this software without specific prior -// written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS -// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, -// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR -// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -////////////////////////////////////////////////////////////////////////// - -#include "IECore/RefCounted.h" - -#include - -namespace IECore { - -RefCounted::RefCounted() -{ - m_numRefs = 0; -} - -RefCounted::~RefCounted() -{ -} - -} // namespace IECore diff --git a/src/IECore/RunTimeTyped.cpp b/src/IECore/RunTimeTyped.cpp index 4abbef71cc..8c864653f9 100644 --- a/src/IECore/RunTimeTyped.cpp +++ b/src/IECore/RunTimeTyped.cpp @@ -46,14 +46,6 @@ using namespace IECore; RunTimeTyped::Mutex RunTimeTyped::g_baseTypeIdsMutex; RunTimeTyped::Mutex RunTimeTyped::g_derivedTypeIdsMutex; -RunTimeTyped::RunTimeTyped() -{ -} - -RunTimeTyped::~RunTimeTyped() -{ -} - TypeId RunTimeTyped::typeId() const { return staticTypeId();