From 0f68cd00eb06ca1d7a4bdbb9e94ec060e784bd50 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Wed, 11 Jan 2023 11:09:30 -0500 Subject: X11: Avoid potentially unnecessary allocation in Vulkan backend --- src/x11_vulkan.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/x11_vulkan.c b/src/x11_vulkan.c index 72ff701..5b6745e 100644 --- a/src/x11_vulkan.c +++ b/src/x11_vulkan.c @@ -28,19 +28,23 @@ struct PuglVulkanLoaderImpl { PuglVulkanLoader* puglNewVulkanLoader(PuglWorld* PUGL_UNUSED(world)) { + void* const libvulkan = dlopen("libvulkan.so", RTLD_LAZY); + if (!libvulkan) { + return NULL; + } + PuglVulkanLoader* const loader = (PuglVulkanLoader*)calloc(1, sizeof(PuglVulkanLoader)); - if (!loader || !(loader->libvulkan = dlopen("libvulkan.so", RTLD_LAZY))) { - free(loader); - return NULL; - } + if (loader) { + loader->libvulkan = libvulkan; - loader->vkGetInstanceProcAddr = (PFN_vkGetInstanceProcAddr)dlsym( - loader->libvulkan, "vkGetInstanceProcAddr"); + loader->vkGetInstanceProcAddr = (PFN_vkGetInstanceProcAddr)dlsym( + loader->libvulkan, "vkGetInstanceProcAddr"); - loader->vkGetDeviceProcAddr = - (PFN_vkGetDeviceProcAddr)dlsym(loader->libvulkan, "vkGetDeviceProcAddr"); + loader->vkGetDeviceProcAddr = + (PFN_vkGetDeviceProcAddr)dlsym(loader->libvulkan, "vkGetDeviceProcAddr"); + } return loader; } -- cgit v1.2.1