From 5e7295c2e7778f4929fa66622e342252177898b2 Mon Sep 17 00:00:00 2001
From: Simon McVittie <smcv@collabora.com>
Date: Wed, 15 Apr 2020 14:01:30 +0100
Subject: [PATCH] runtime: Preallocate more space for list of VA-API drivers

We use the same GPtrArray to accumulate both i386 and x86_64 drivers,
so ideally we allocate enough space for both and never have to
reallocate it again. (But if we guess wrong, no harm done.)

Signed-off-by: Simon McVittie <smcv@collabora.com>
---
 src/runtime.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/runtime.c b/src/runtime.c
index ce2ad0559..0391abf21 100644
--- a/src/runtime.c
+++ b/src/runtime.c
@@ -1398,8 +1398,11 @@ pv_runtime_use_host_graphics_stack (PvRuntime *self,
                                                                 multiarch_tuples[i],
                                                                 SRT_DRIVER_FLAGS_NONE);
 
+          /* Guess that there will be about the same number of VA-API ICDs
+           * for each word size. This only needs to be approximately right:
+           * g_ptr_array_add() will resize the allocated buffer if needed. */
           if (va_api_icd_details == NULL)
-            va_api_icd_details = g_ptr_array_new_full (g_list_length (va_api_drivers),
+            va_api_icd_details = g_ptr_array_new_full (g_list_length (va_api_drivers) * (G_N_ELEMENTS (multiarch_tuples) - 1),
                                                        (GDestroyNotify) G_CALLBACK (icd_details_free));
 
           for (icd_iter = va_api_drivers, j = 0; icd_iter != NULL; icd_iter = icd_iter->next, j++)
-- 
GitLab