From c5b6a8b5b950d685f2490633c8914e53a6640c05 Mon Sep 17 00:00:00 2001 From: Alex Ling Date: Sun, 5 Sep 2021 13:57:20 +0000 Subject: [PATCH] Improve instance_size for Tuple --- src/library/cache.cr | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/library/cache.cr b/src/library/cache.cr index ca6af53..612345c 100644 --- a/src/library/cache.cr +++ b/src/library/cache.cr @@ -93,7 +93,15 @@ end struct Tuple(*T) def instance_size - sizeof(T) # iterate T and add instance_size of that + sizeof(T) + # total size of non-reference types + self.sum do |e| + next 0 unless e.is_a? Reference + if e.responds_to? :instance_size + e.instance_size + else + instance_sizeof(typeof(e)) + end + end end end