From 6db9dc1c4ec92d01f1c46a2fd81d74f6119820f4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fredrik=20H=C3=BCbinette=20=28Hubbe=29?= <hubbe@hubbe.net>
Date: Mon, 19 Jul 1999 01:03:59 -0700
Subject: [PATCH] optimization (set_many added)

Rev: tutorial/Cache.pike:1.3
---
 tutorial/Cache.pike | 31 +++++++++++++++++++++++++++----
 1 file changed, 27 insertions(+), 4 deletions(-)

diff --git a/tutorial/Cache.pike b/tutorial/Cache.pike
index 5dec74c3cf..6ab01792df 100644
--- a/tutorial/Cache.pike
+++ b/tutorial/Cache.pike
@@ -33,16 +33,38 @@ mixed `[]=(mixed key, mixed val)
   return val;
 }
 
+void set_many(array(mixed) key, array(mixed) val)
+{
+  if(sizeof(key) > sizeof(data)/10)
+  {
+    /* substatial update */
+    data|=mkmapping(key,val);
+    save();
+  }else{
+    /* insubstantial update */
+    data|=mkmapping(key,val);
+
+    if(!log) log=Stdio.File(file+".log","wct");
+    log->write(Array.map(Array.map(Array.transpose( ({key, val}) ),
+				   encode_value),
+			 replace,"\0","\0\1")*"\0\0" + "\0\0");
+  }
+
+}
+
 void create(string f)
 {
   werror("Cache: %s",f);
   file=f;
-  catch {
-    data=decode_value(Stdio.read_file(file));
-    werror(" %d entries",sizeof(data));
+  mixed err=catch {
+    if(string tmp=Stdio.read_file(file))
+      data=decode_value(tmp);
   };
 
-  catch {
+  if(err)  werror(master()->describe_backtrace(err));
+  werror(" %d entries",sizeof(data));
+
+  err=catch {
     if(string s=Stdio.read_file(file+".log"))
     {
       array t=s/"\0\0";
@@ -57,6 +79,7 @@ void create(string f)
       save();
     }
   };
+  if(err)  werror(master()->describe_backtrace(err));
 
   werror("\n");
 
-- 
GitLab