Commit 3cfd0a7a authored by Nikolay Sivov's avatar Nikolay Sivov Committed by Alexandre Julliard

dwrite: Use array allocation helper for in-memory loader.

parent 0520b593
...@@ -4588,8 +4588,8 @@ struct dwrite_inmemory_fileloader ...@@ -4588,8 +4588,8 @@ struct dwrite_inmemory_fileloader
LONG ref; LONG ref;
struct dwrite_inmemory_stream_data **streams; struct dwrite_inmemory_stream_data **streams;
UINT32 filecount; size_t size;
UINT32 capacity; size_t count;
}; };
static inline struct dwrite_localfontfileloader *impl_from_IDWriteLocalFontFileLoader(IDWriteLocalFontFileLoader *iface) static inline struct dwrite_localfontfileloader *impl_from_IDWriteLocalFontFileLoader(IDWriteLocalFontFileLoader *iface)
...@@ -6208,13 +6208,12 @@ static ULONG WINAPI inmemoryfontfileloader_Release(IDWriteInMemoryFontFileLoader ...@@ -6208,13 +6208,12 @@ static ULONG WINAPI inmemoryfontfileloader_Release(IDWriteInMemoryFontFileLoader
{ {
struct dwrite_inmemory_fileloader *loader = impl_from_IDWriteInMemoryFontFileLoader(iface); struct dwrite_inmemory_fileloader *loader = impl_from_IDWriteInMemoryFontFileLoader(iface);
ULONG ref = InterlockedDecrement(&loader->ref); ULONG ref = InterlockedDecrement(&loader->ref);
size_t i;
TRACE("(%p)->(%u)\n", loader, ref); TRACE("(%p)->(%u)\n", loader, ref);
if (!ref) { if (!ref) {
UINT32 i; for (i = 0; i < loader->count; ++i)
for (i = 0; i < loader->filecount; i++)
release_inmemory_stream(loader->streams[i]); release_inmemory_stream(loader->streams[i]);
heap_free(loader->streams); heap_free(loader->streams);
heap_free(loader); heap_free(loader);
...@@ -6239,7 +6238,7 @@ static HRESULT WINAPI inmemoryfontfileloader_CreateStreamFromKey(IDWriteInMemory ...@@ -6239,7 +6238,7 @@ static HRESULT WINAPI inmemoryfontfileloader_CreateStreamFromKey(IDWriteInMemory
index = *(DWORD *)key; index = *(DWORD *)key;
if (index >= loader->filecount) if (index >= loader->count)
return E_INVALIDARG; return E_INVALIDARG;
if (!(stream = heap_alloc(sizeof(*stream)))) if (!(stream = heap_alloc(sizeof(*stream))))
...@@ -6266,21 +6265,8 @@ static HRESULT WINAPI inmemoryfontfileloader_CreateInMemoryFontFileReference(IDW ...@@ -6266,21 +6265,8 @@ static HRESULT WINAPI inmemoryfontfileloader_CreateInMemoryFontFileReference(IDW
*fontfile = NULL; *fontfile = NULL;
if (loader->filecount == loader->capacity) { if (!dwrite_array_reserve((void **)&loader->streams, &loader->size, loader->count + 1, sizeof(*loader->streams)))
if (loader->streams) { return E_OUTOFMEMORY;
struct dwrite_inmemory_stream_data **ptr;
if (!(ptr = heap_realloc(loader->streams, 2 * loader->capacity * sizeof(*loader->streams))))
return E_OUTOFMEMORY;
loader->streams = ptr;
loader->capacity *= 2;
}
else {
loader->capacity = 16;
loader->streams = heap_calloc(loader->capacity, sizeof(*loader->streams));
}
}
if (!(stream = heap_alloc(sizeof(*stream)))) if (!(stream = heap_alloc(sizeof(*stream))))
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
...@@ -6300,8 +6286,8 @@ static HRESULT WINAPI inmemoryfontfileloader_CreateInMemoryFontFileReference(IDW ...@@ -6300,8 +6286,8 @@ static HRESULT WINAPI inmemoryfontfileloader_CreateInMemoryFontFileReference(IDW
memcpy(stream->data, data, data_size); memcpy(stream->data, data, data_size);
} }
key = loader->filecount; key = loader->count;
loader->streams[loader->filecount++] = stream; loader->streams[loader->count++] = stream;
return IDWriteFactory_CreateCustomFontFileReference(factory, &key, sizeof(key), return IDWriteFactory_CreateCustomFontFileReference(factory, &key, sizeof(key),
(IDWriteFontFileLoader *)&loader->IDWriteInMemoryFontFileLoader_iface, fontfile); (IDWriteFontFileLoader *)&loader->IDWriteInMemoryFontFileLoader_iface, fontfile);
...@@ -6311,9 +6297,9 @@ static UINT32 WINAPI inmemoryfontfileloader_GetFileCount(IDWriteInMemoryFontFile ...@@ -6311,9 +6297,9 @@ static UINT32 WINAPI inmemoryfontfileloader_GetFileCount(IDWriteInMemoryFontFile
{ {
struct dwrite_inmemory_fileloader *loader = impl_from_IDWriteInMemoryFontFileLoader(iface); struct dwrite_inmemory_fileloader *loader = impl_from_IDWriteInMemoryFontFileLoader(iface);
TRACE("(%p)\n", loader); TRACE("%p.\n", iface);
return loader->filecount; return loader->count;
} }
static const IDWriteInMemoryFontFileLoaderVtbl inmemoryfontfileloadervtbl = static const IDWriteInMemoryFontFileLoaderVtbl inmemoryfontfileloadervtbl =
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment