vulkan-Vulkan_Implementation: Use binary search to lookup function in is_null_func.

This commit is contained in:
Sebastian Lackner 2016-03-23 01:23:19 +01:00
parent 941d4e4383
commit edcd32bdea
2 changed files with 67 additions and 0 deletions

View File

@ -6951,9 +6951,11 @@ fi
if test "$enable_vulkan_Vulkan_Implementation" -eq 1; then
patch_apply vulkan-Vulkan_Implementation/0001-vulkan-Initial-implementation.patch
patch_apply vulkan-Vulkan_Implementation/0002-vulkan-Implement-vkGetPhysicalDeviceWin32Presentatio.patch
patch_apply vulkan-Vulkan_Implementation/0003-vulkan-Use-binary-search-to-lookup-function-in-is_nu.patch
(
echo '+ { "Sebastian Lackner", "vulkan: Initial implementation.", 2 },';
echo '+ { "Michael Müller", "vulkan: Implement vkGetPhysicalDeviceWin32PresentationSupportKHR.", 1 },';
echo '+ { "Sebastian Lackner", "vulkan: Use binary search to lookup function in is_null_func.", 1 },';
) >> "$patchlist"
fi

View File

@ -0,0 +1,65 @@
From ceb7879ae9cd98600f0d1f4005559c1d2dca50a1 Mon Sep 17 00:00:00 2001
From: Sebastian Lackner <sebastian@fds-team.de>
Date: Wed, 23 Mar 2016 01:11:58 +0100
Subject: vulkan: Use binary search to lookup function in is_null_func.
---
dlls/vulkan/vulkan_thunks.c | 25 +++++++++++++++----------
1 file changed, 15 insertions(+), 10 deletions(-)
diff --git a/dlls/vulkan/vulkan_thunks.c b/dlls/vulkan/vulkan_thunks.c
index 8333cb7..4ddb352 100644
--- a/dlls/vulkan/vulkan_thunks.c
+++ b/dlls/vulkan/vulkan_thunks.c
@@ -6392,15 +6392,17 @@ VkResult WINAPI vkWaitForFences( VkDevice device, uint32_t fenceCount, const VkF
return p_vkWaitForFences( device, fenceCount, pFences, waitAll, timeout );
}
-static const struct
+struct function_entry
{
const char *name;
void **host_func;
void *null_func;
-}
-function_table[] =
+};
+
+static const struct function_entry function_table[] =
{
#define DEFINE_FUNCTION( f ) { #f, (void **)&p_##f, null_##f },
+ /* functions must be sorted alphabetically */
DEFINE_FUNCTION( vkAcquireNextImageKHR )
DEFINE_FUNCTION( vkAllocateCommandBuffers )
DEFINE_FUNCTION( vkAllocateDescriptorSets )
@@ -6594,17 +6596,20 @@ BOOL init_vulkan( void )
return TRUE;
}
+static int compare_function_entry( const void *a, const void *b )
+{
+ return strcmp( ((struct function_entry *)a)->name, ((struct function_entry *)b)->name );
+}
+
BOOL is_null_func( const char *name )
{
- int i;
+ struct function_entry search = { name, NULL, NULL };
+ struct function_entry *found;
- for (i = 0; i < ARRAY_SIZE(function_table); i++)
- {
- if (strcmp( function_table[i].name, name )) continue;
- return (*function_table[i].host_func == function_table[i].null_func);
- }
+ found = bsearch( &search, function_table, ARRAY_SIZE(function_table),
+ sizeof(function_table[0]), compare_function_entry );
- return FALSE;
+ return found ? (*found->host_func == found->null_func) : FALSE;
}
void free_vulkan( void )
--
2.7.1