From 4cce8cbd5f300edc59bc0d79fea5ee1f662b13df Mon Sep 17 00:00:00 2001 From: Hans Leidekker Date: Wed, 23 Dec 2015 11:06:57 +0100 Subject: [PATCH] wbemdisp: Calculate the object count returned from ISWbemObjectSet::get_Count just once. Signed-off-by: Hans Leidekker Signed-off-by: Alexandre Julliard --- dlls/wbemdisp/locator.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/dlls/wbemdisp/locator.c b/dlls/wbemdisp/locator.c index 3465eb19beb..d1f2609998c 100644 --- a/dlls/wbemdisp/locator.c +++ b/dlls/wbemdisp/locator.c @@ -356,6 +356,7 @@ struct objectset ISWbemObjectSet ISWbemObjectSet_iface; LONG refs; IEnumWbemClassObject *objectenum; + LONG count; }; static inline struct objectset *impl_from_ISWbemObjectSet( @@ -517,20 +518,10 @@ static HRESULT WINAPI objectset_get_Count( LONG *iCount ) { struct objectset *objectset = impl_from_ISWbemObjectSet( iface ); - LONG count = 0, total = 0; TRACE( "%p, %p\n", objectset, iCount ); - while (IEnumWbemClassObject_Skip( objectset->objectenum, WBEM_INFINITE, 1 ) == S_OK) count++; - - IEnumWbemClassObject_Reset( objectset->objectenum ); - while (IEnumWbemClassObject_Skip( objectset->objectenum, WBEM_INFINITE, 1 ) == S_OK) total++; - - count = total - count; - IEnumWbemClassObject_Reset( objectset->objectenum ); - while (count--) IEnumWbemClassObject_Skip( objectset->objectenum, WBEM_INFINITE, 1 ); - - *iCount = total; + *iCount = objectset->count; return S_OK; } @@ -567,6 +558,14 @@ static const ISWbemObjectSetVtbl objectset_vtbl = objectset_ItemIndex }; +static LONG get_object_count( IEnumWbemClassObject *iter ) +{ + LONG count = 0; + while (IEnumWbemClassObject_Skip( iter, WBEM_INFINITE, 1 ) == S_OK) count++; + IEnumWbemClassObject_Reset( iter ); + return count; +} + static HRESULT SWbemObjectSet_create( IEnumWbemClassObject *wbem_objectenum, ISWbemObjectSet **obj ) { struct objectset *objectset; @@ -578,6 +577,7 @@ static HRESULT SWbemObjectSet_create( IEnumWbemClassObject *wbem_objectenum, ISW objectset->refs = 1; objectset->objectenum = wbem_objectenum; IEnumWbemClassObject_AddRef( objectset->objectenum ); + objectset->count = get_object_count( objectset->objectenum ); *obj = &objectset->ISWbemObjectSet_iface; TRACE( "returning iface %p\n", *obj );