From 086b1e48828740ce215ba3609dcb899c8687bfa0 Mon Sep 17 00:00:00 2001 From: mrb0nk500 Date: Thu, 2 Mar 2023 12:17:44 -0400 Subject: TArray: Make `{,fast_}fill_with()` type generic --- include/pso/TArray.h | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) (limited to 'include') diff --git a/include/pso/TArray.h b/include/pso/TArray.h index 7f53785..8dd736b 100644 --- a/include/pso/TArray.h +++ b/include/pso/TArray.h @@ -59,12 +59,14 @@ public: memset(m_data, val, byte_size()); }; - void fill_with(u8 val) { - _fill_with(val); + template + void fill_with(const T2 val) { + _fill_with(val); }; - void fast_fill_with(u8 val) { - _fill_with(val); + template + void fast_fill_with(const T2 val) { + _fill_with(val); }; template @@ -88,26 +90,26 @@ public: }; private: - template - void _fill_with(u8 val) { - u8 *bytes = as_bytes(); - size_t size = byte_size(); + template + void _fill_with(const T2 val) { + T2 *data = as(); + size_t size = size_as(); if (do_unroll_check && size <= 8) { int i = 0; switch (size) { - case 8: bytes[i++] = val; - case 7: bytes[i++] = val; - case 6: bytes[i++] = val; - case 5: bytes[i++] = val; - case 4: bytes[i++] = val; - case 3: bytes[i++] = val; - case 2: bytes[i++] = val; - case 1: bytes[i++] = val; + case 8: data[i++] = val; + case 7: data[i++] = val; + case 6: data[i++] = val; + case 5: data[i++] = val; + case 4: data[i++] = val; + case 3: data[i++] = val; + case 2: data[i++] = val; + case 1: data[i++] = val; default: break; } } else { for (int i = 0; i < size; ++i) { - bytes[i] = val; + data[i] = val; } } }; -- cgit v1.2.3-13-gbd6f