From 19adccea8f4f8abe8fa2a1da46bf401e85c255cc Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Sun, 2 Jun 2019 23:34:53 +0200 Subject: [PATCH] [util] Add unlikely() around COM ref counting code Improves code generation for the common case. --- src/util/com/com_object.h | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/util/com/com_object.h b/src/util/com/com_object.h index 1d277213..8bb8c48d 100644 --- a/src/util/com/com_object.h +++ b/src/util/com/com_object.h @@ -3,6 +3,8 @@ #include #include "com_include.h" + +#include "../util_likely.h" namespace dxvk { @@ -30,15 +32,15 @@ namespace dxvk { virtual ~ComObject() { } ULONG STDMETHODCALLTYPE AddRef() { - ULONG refCount = m_refCount++; - if (refCount == 0ul) + uint32_t refCount = m_refCount++; + if (unlikely(!refCount)) AddRefPrivate(); return refCount + 1; } ULONG STDMETHODCALLTYPE Release() { - ULONG refCount = --m_refCount; - if (refCount == 0ul) + uint32_t refCount = --m_refCount; + if (unlikely(!refCount)) ReleasePrivate(); return refCount; } @@ -50,7 +52,8 @@ namespace dxvk { void ReleasePrivate() { - if (--m_refPrivate == 0ul) { + uint32_t refPrivate = --m_refPrivate; + if (unlikely(!refPrivate)) { m_refPrivate += 0x80000000; delete this; }