From cff0d7ee9ab1c7458aeba3574100c85e9f49e7c5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fredrik=20H=C3=BCbinette=20=28Hubbe=29?= <hubbe@hubbe.net>
Date: Sun, 23 Mar 1997 14:28:35 -0800
Subject: [PATCH] new function: get_storage

Rev: src/ChangeLog:1.91
Rev: src/program.c:1.29
Rev: src/program.h:1.14
---
 src/ChangeLog |  4 ++++
 src/program.c | 42 +++++++++++++++++++++++++++++++++++++++++-
 src/program.h |  1 +
 3 files changed, 46 insertions(+), 1 deletion(-)

diff --git a/src/ChangeLog b/src/ChangeLog
index 94a6ec5906..9c1a887722 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,7 @@
+Sun Mar 23 14:09:18 1997  Fredrik Hubinette  <hubbe@cytocin.hubbe.net>
+
+	* program.c (get_storage): new function
+
 Mon Mar 17 14:14:34 1997  Fredrik Hubinette  <hubbe@cytocin.hubbe.net>
 
 	* peep.c (insopt): line numbering info bug fixed
diff --git a/src/program.c b/src/program.c
index 925eeb0e2b..2a1c132299 100644
--- a/src/program.c
+++ b/src/program.c
@@ -4,7 +4,7 @@
 ||| See the files COPYING and DISCLAIMER for more information.
 \*/
 #include "global.h"
-RCSID("$Id: program.c,v 1.28 1997/03/17 03:04:43 hubbe Exp $");
+RCSID("$Id: program.c,v 1.29 1997/03/23 22:23:52 hubbe Exp $");
 #include "program.h"
 #include "object.h"
 #include "dynamic_buffer.h"
@@ -1696,3 +1696,43 @@ void pop_locals()
   local_variables=l;
   /* insert check if ( local->next == parent locals ) here */
 }
+
+
+#define GET_STORAGE_CACHE_SIZE 1024
+static struct get_storage_cache
+{
+  INT32 oid, pid, offset;
+} get_storage_cache[GET_STORAGE_CACHE_SIZE];
+
+char *get_storage(struct object *o, struct program *p)
+{
+  INT32 oid,pid, offset;
+  unsigned INT32 hval;
+  if(!o->prog) return 0;
+  oid=o->prog->id;
+  pid=p->id;
+  hval=(oid*9248339 + pid) % GET_STORAGE_CACHE_SIZE;
+  if(get_storage_cache[hval].oid == oid &&
+     get_storage_cache[hval].pid == pid)
+  {
+    offset=get_storage_cache[hval].offset;
+  }else{
+    INT32 e;
+    offset=-1;
+    for(e=0;e<o->prog->num_inherits;e++)
+    {
+      if(o->prog->inherits[e].prog==p)
+      {
+	offset=o->prog->inherits[e].storage_offset;
+	break;
+      }
+    }
+
+    get_storage_cache[hval].oid=oid;
+    get_storage_cache[hval].pid=pid;
+    get_storage_cache[hval].offset=offset;
+  }
+
+  if(offset == -1) return 0;
+  return o->storage + offset;
+}
diff --git a/src/program.h b/src/program.h
index 326913e041..900c03156d 100644
--- a/src/program.h
+++ b/src/program.h
@@ -251,6 +251,7 @@ void gc_free_all_unreferenced_programs();
 void count_memory_in_programs(INT32 *num_, INT32 *size_);
 void push_locals();
 void pop_locals();
+char *get_storage(struct object *o, struct program *p);
 /* Prototypes end here */
 
 
-- 
GitLab