From bb6d9a26f72e5f55328bcb1af0ea3bc852262099 Mon Sep 17 00:00:00 2001 From: Philippe PITTOLI Date: Tue, 7 May 2024 13:05:01 +0200 Subject: [PATCH] Don't clone data by default. User can clone only when relevant. --- src/cached.cr | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/cached.cr b/src/cached.cr index 8c46656..ad1f6c1 100644 --- a/src/cached.cr +++ b/src/cached.cr @@ -44,8 +44,12 @@ class DODB::CachedDataBase(V) < DODB::Storage(V) # FIXME: rescues any error the same way. return nil end + + # WARNING: data isn't cloned. + # You have to do it yourself in case you modify any value, + # otherwise you may encounter problems (at least with indexes). def [](key : Int32) : V - @data[key].clone rescue raise MissingEntry.new(key) + @data[key] rescue raise MissingEntry.new(key) end def []=(index : Int32, value : V)