From: Nikolay Sivov Subject: [PATCH 3/5] dwrite: Use helpers to search through loaders lists Message-Id: <544A0906.8060803@codeweavers.com> Date: Fri, 24 Oct 2014 12:08:38 +0400 --- From 14152b932a64b8378455ad7206a40f6b6fbd69a4 Mon Sep 17 00:00:00 2001 From: Nikolay Sivov Date: Fri, 24 Oct 2014 11:41:46 +0400 Subject: [PATCH 3/5] dwrite: Use helpers to search through loaders lists --- dlls/dwrite/main.c | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/dlls/dwrite/main.c b/dlls/dwrite/main.c index 57e0038..4c549d6 100644 --- a/dlls/dwrite/main.c +++ b/dlls/dwrite/main.c @@ -495,6 +495,20 @@ static struct fileloader *factory_get_file_loader(struct dwritefactory *factory, return found; } +static struct collectionloader *factory_get_collection_loader(struct dwritefactory *factory, IDWriteFontCollectionLoader *loader) +{ + struct collectionloader *entry, *found = NULL; + + LIST_FOR_EACH_ENTRY(entry, &factory->collection_loaders, struct collectionloader, entry) { + if (entry->loader == loader) { + found = entry; + break; + } + } + + return found; +} + static HRESULT WINAPI dwritefactory_QueryInterface(IDWriteFactory *iface, REFIID riid, void **obj) { struct dwritefactory *This = impl_from_IDWriteFactory(iface); @@ -575,10 +589,8 @@ static HRESULT WINAPI dwritefactory_RegisterFontCollectionLoader(IDWriteFactory if (!loader) return E_INVALIDARG; - LIST_FOR_EACH_ENTRY(entry, &This->collection_loaders, struct collectionloader, entry) { - if (entry->loader == loader) - return DWRITE_E_ALREADYREGISTERED; - } + if (factory_get_collection_loader(This, loader)) + return DWRITE_E_ALREADYREGISTERED; entry = heap_alloc(sizeof(*entry)); if (!entry) @@ -595,20 +607,14 @@ static HRESULT WINAPI dwritefactory_UnregisterFontCollectionLoader(IDWriteFactor IDWriteFontCollectionLoader *loader) { struct dwritefactory *This = impl_from_IDWriteFactory(iface); - struct collectionloader *entry, *found = NULL; + struct collectionloader *found; TRACE("(%p)->(%p)\n", This, loader); if (!loader) return E_INVALIDARG; - LIST_FOR_EACH_ENTRY(entry, &This->collection_loaders, struct collectionloader, entry) { - if (entry->loader == loader) { - found = entry; - break; - } - } - + found = factory_get_collection_loader(This, loader); if (!found) return E_INVALIDARG; @@ -784,10 +790,8 @@ static HRESULT WINAPI dwritefactory_RegisterFontFileLoader(IDWriteFactory *iface if (!loader) return E_INVALIDARG; - LIST_FOR_EACH_ENTRY(entry, &This->file_loaders, struct fileloader, entry) { - if (entry->loader == loader) - return DWRITE_E_ALREADYREGISTERED; - } + if (factory_get_file_loader(This, loader)) + return DWRITE_E_ALREADYREGISTERED; entry = heap_alloc(sizeof(*entry)); if (!entry) -- 2.1.1