From 5235002a2f8ebc095adc72bf2ef3efdaec40e0e4 Mon Sep 17 00:00:00 2001 From: Marko Semet Date: Sun, 14 Jun 2020 22:27:57 +0200 Subject: [PATCH] Improve performance of size --- source/structs/package.d | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/source/structs/package.d b/source/structs/package.d index 68d5d2f..b3b920f 100644 --- a/source/structs/package.d +++ b/source/structs/package.d @@ -369,7 +369,15 @@ public { private { - const(Element[]) elements = parse_string(CONFIG); + static const(Element[]) elements = parse_string(CONFIG); + static const(size_t) elements_size = { + size_t size = 0; + static foreach (i; elements) + { + size += i.packSize(); + } + return size; + }(); } public @@ -380,12 +388,7 @@ public +/ static size_t size() { - size_t result = 0; - static foreach (i; elements) - { - result += i.packSize(); - } - return result; + return elements_size; } } }