From 7a11d1aa6b3fb20d974ce17a79b24d0da1cfdcc8 Mon Sep 17 00:00:00 2001 From: baldurk Date: Mon, 27 Nov 2017 20:35:00 +0000 Subject: [PATCH] Where possible use memset to default initialise types like byte/int/etc --- renderdoc/api/replay/basic_types.h | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/renderdoc/api/replay/basic_types.h b/renderdoc/api/replay/basic_types.h index 0b21c1d2f..c9b5c33a3 100644 --- a/renderdoc/api/replay/basic_types.h +++ b/renderdoc/api/replay/basic_types.h @@ -89,6 +89,22 @@ struct null_terminator inline static void fixup(char *elems, size_t count) { elems[count] = 0; } }; +template ::value> +struct ItemHelper +{ + static void initRange(T *first, int32_t count) + { + for(int32_t i = 0; i < count; i++) + new(first + i) T(); + } +}; + +template +struct ItemHelper +{ + static void initRange(T *first, int32_t itemCount) { memset(first, 0, itemCount * sizeof(T)); } +}; + template struct rdcarray { @@ -222,8 +238,7 @@ public: setUsedCount((int32_t)s); // default initialise the new elements - for(int32_t i = oldCount; i < usedCount; i++) - new(elems + i) T(); + ItemHelper::initRange(elems + oldCount, usedCount - oldCount); } else {