Tcl Source Code

Artifact [3a4127d419]
Login

Artifact 3a4127d419151a0f6cf182229d1fa6637ffc36aa:

Attachment "lazyfree.patch" to ticket [886231ffff] added by nobody 2004-01-28 21:37:18.
--- ../../tcl/generic/tclObj.c	2004-01-21 18:03:23.000000000 +0100
+++ ../generic/tclObj.c	2004-01-26 14:58:32.000000000 +0100
@@ -736,7 +736,7 @@
  */
 
 void
-TclFreeObj(objPtr)
+TclReallyFreeObj(objPtr)
     register Tcl_Obj *objPtr;	/* The object to be freed. */
 {
     register Tcl_ObjType *typePtr = objPtr->typePtr;
@@ -775,6 +775,51 @@
     tclObjsFreed++;
 #endif /* TCL_COMPILE_STATS */
 }
+
+#define TCL_FREESTACK_INIT_LEN 10000
+static Tcl_Obj **LazyFreeStack = NULL;
+static LazyFreeStack_Len = 0;
+static LazyFreeStack_Used = 0;
+static TclFreeObj_Depth = 0;
+
+void LazyPush(Tcl_Obj *objPtr)
+{
+	int left = LazyFreeStack_Len - LazyFreeStack_Used;
+
+	if (!left) {
+		int newlen = LazyFreeStack_Len * 2;
+
+		if (!newlen) newlen = TCL_FREESTACK_INIT_LEN;
+		LazyFreeStack = (Tcl_Obj**) ckrealloc((char*)LazyFreeStack,
+				newlen*sizeof(Tcl_Obj*));
+		LazyFreeStack_Len = newlen;
+	}
+	LazyFreeStack[LazyFreeStack_Used++] = objPtr;
+}
+
+Tcl_Obj *LazyPop(void)
+{
+	if (LazyFreeStack_Used == 0)
+		return NULL;
+	return LazyFreeStack[--LazyFreeStack_Used];
+}
+
+void
+TclFreeObj(objPtr)
+    register Tcl_Obj *objPtr;	/* The object to be freed. */
+{
+	TclFreeObj_Depth++;
+	LazyPush(objPtr);
+	if (TclFreeObj_Depth == 1) {
+		Tcl_Obj *o;
+		while((o = LazyPop())) {
+			TclReallyFreeObj(o);
+		}
+	}
+	TclFreeObj_Depth--;
+}
+
+
 
 /*
  *----------------------------------------------------------------------