Nikolay Sivov : dwrite/layout: Use array allocation helper for typography features.

Alexandre Julliard julliard at winehq.org
Mon May 13 16:24:17 CDT 2019


Module: wine
Branch: master
Commit: cbd83b4e8089ba7779d48225eedce0129b3c7bda
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=cbd83b4e8089ba7779d48225eedce0129b3c7bda

Author: Nikolay Sivov <nsivov at codeweavers.com>
Date:   Mon May 13 14:21:43 2019 +0300

dwrite/layout: Use array allocation helper for typography features.

Signed-off-by: Nikolay Sivov <nsivov at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/dwrite/layout.c | 63 ++++++++++++++++++++++++----------------------------
 1 file changed, 29 insertions(+), 34 deletions(-)

diff --git a/dlls/dwrite/layout.c b/dlls/dwrite/layout.c
index 40621ce..3e316c2 100644
--- a/dlls/dwrite/layout.c
+++ b/dlls/dwrite/layout.c
@@ -304,11 +304,11 @@ struct dwrite_trimmingsign {
 
 struct dwrite_typography {
     IDWriteTypography IDWriteTypography_iface;
-    LONG ref;
+    LONG refcount;
 
     DWRITE_FONT_FEATURE *features;
-    UINT32 allocated;
-    UINT32 count;
+    size_t capacity;
+    size_t count;
 };
 
 static const IDWriteTextFormat2Vtbl dwritetextformatvtbl;
@@ -5689,9 +5689,7 @@ HRESULT create_textformat(const WCHAR *family_name, IDWriteFontCollection *colle
 
 static HRESULT WINAPI dwritetypography_QueryInterface(IDWriteTypography *iface, REFIID riid, void **obj)
 {
-    struct dwrite_typography *typography = impl_from_IDWriteTypography(iface);
-
-    TRACE("(%p)->(%s %p)\n", typography, debugstr_guid(riid), obj);
+    TRACE("%p, %s, %p.\n", iface, debugstr_guid(riid), obj);
 
     if (IsEqualIID(riid, &IID_IDWriteTypography) || IsEqualIID(riid, &IID_IUnknown)) {
         *obj = iface;
@@ -5709,57 +5707,61 @@ static HRESULT WINAPI dwritetypography_QueryInterface(IDWriteTypography *iface,
 static ULONG WINAPI dwritetypography_AddRef(IDWriteTypography *iface)
 {
     struct dwrite_typography *typography = impl_from_IDWriteTypography(iface);
-    ULONG ref = InterlockedIncrement(&typography->ref);
-    TRACE("(%p)->(%d)\n", typography, ref);
-    return ref;
+    ULONG refcount = InterlockedIncrement(&typography->refcount);
+
+    TRACE("%p, refcount %d.\n", iface, refcount);
+
+    return refcount;
 }
 
 static ULONG WINAPI dwritetypography_Release(IDWriteTypography *iface)
 {
     struct dwrite_typography *typography = impl_from_IDWriteTypography(iface);
-    ULONG ref = InterlockedDecrement(&typography->ref);
+    ULONG refcount = InterlockedDecrement(&typography->refcount);
 
-    TRACE("(%p)->(%d)\n", typography, ref);
+    TRACE("%p, refcount %d.\n", iface, refcount);
 
-    if (!ref) {
+    if (!refcount)
+    {
         heap_free(typography->features);
         heap_free(typography);
     }
 
-    return ref;
+    return refcount;
 }
 
 static HRESULT WINAPI dwritetypography_AddFontFeature(IDWriteTypography *iface, DWRITE_FONT_FEATURE feature)
 {
     struct dwrite_typography *typography = impl_from_IDWriteTypography(iface);
 
-    TRACE("(%p)->(%x %u)\n", typography, feature.nameTag, feature.parameter);
-
-    if (typography->count == typography->allocated) {
-        DWRITE_FONT_FEATURE *ptr = heap_realloc(typography->features, 2*typography->allocated*sizeof(DWRITE_FONT_FEATURE));
-        if (!ptr)
-            return E_OUTOFMEMORY;
+    TRACE("%p, %s, %u.\n", iface, debugstr_tag(feature.nameTag), feature.parameter);
 
-        typography->features = ptr;
-        typography->allocated *= 2;
+    if (!dwrite_array_reserve((void **)&typography->features, &typography->capacity, typography->count + 1,
+            sizeof(*typography->features)))
+    {
+        return E_OUTOFMEMORY;
     }
 
     typography->features[typography->count++] = feature;
+
     return S_OK;
 }
 
 static UINT32 WINAPI dwritetypography_GetFontFeatureCount(IDWriteTypography *iface)
 {
     struct dwrite_typography *typography = impl_from_IDWriteTypography(iface);
-    TRACE("(%p)\n", typography);
+
+    TRACE("%p.\n", iface);
+
     return typography->count;
 }
 
-static HRESULT WINAPI dwritetypography_GetFontFeature(IDWriteTypography *iface, UINT32 index, DWRITE_FONT_FEATURE *feature)
+static HRESULT WINAPI dwritetypography_GetFontFeature(IDWriteTypography *iface, UINT32 index,
+        DWRITE_FONT_FEATURE *feature)
 {
     struct dwrite_typography *typography = impl_from_IDWriteTypography(iface);
 
-    TRACE("(%p)->(%u %p)\n", typography, index, feature);
+    TRACE("%p, %u, %p.\n", iface, index, feature);
 
     if (index >= typography->count)
         return E_INVALIDARG;
@@ -5783,21 +5785,14 @@ HRESULT create_typography(IDWriteTypography **ret)
 
     *ret = NULL;
 
-    typography = heap_alloc(sizeof(*typography));
+    typography = heap_alloc_zero(sizeof(*typography));
     if (!typography)
         return E_OUTOFMEMORY;
 
     typography->IDWriteTypography_iface.lpVtbl = &dwritetypographyvtbl;
-    typography->ref = 1;
-    typography->allocated = 2;
-    typography->count = 0;
-
-    typography->features = heap_calloc(typography->allocated, sizeof(*typography->features));
-    if (!typography->features) {
-        heap_free(typography);
-        return E_OUTOFMEMORY;
-    }
+    typography->refcount = 1;
 
     *ret = &typography->IDWriteTypography_iface;
+
     return S_OK;
 }




More information about the wine-cvs mailing list