aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--STYLE2
-rw-r--r--bench.tcl7
-rw-r--r--jim.c45
3 files changed, 43 insertions, 11 deletions
diff --git a/STYLE b/STYLE
index 6dc8063..99b02d1 100644
--- a/STYLE
+++ b/STYLE
@@ -52,3 +52,5 @@ C FEATURES
----------
Only C89 ANSI C is allowed. C99 features can't be used currently.
+
+
diff --git a/bench.tcl b/bench.tcl
index edd1bc0..45a09cc 100644
--- a/bench.tcl
+++ b/bench.tcl
@@ -2,8 +2,9 @@ proc bench {title script} {
while {[string length $title] < 20} {
append title " "
}
- catch {time $script} res
- puts "$title - $res"
+ if {[catch {puts "$title - [time $script]"}]} {
+ puts "$title - This test can't run on this interpreter"
+ }
}
### BUSY LOOP ##################################################################
@@ -197,4 +198,4 @@ bench {ary} {ary 100000}
bench {repeat} {use_repeat}
bench {upvar} {upvartest}
bench {nested loops} {nestedloops}
-bench {rotate} {rotate 100000} \ No newline at end of file
+bench {rotate} {rotate 100000}
diff --git a/jim.c b/jim.c
index 35161ba..96837e8 100644
--- a/jim.c
+++ b/jim.c
@@ -2284,23 +2284,38 @@ static void ScriptObjAddInt(struct ScriptObj *script, int val)
/* Search a Jim_Obj contained in 'script' with the same stinrg repr.
* of objPtr. Search nested script objects recursively. */
static Jim_Obj *ScriptSearchLiteral(Jim_Interp *interp, ScriptObj *script,
- Jim_Obj *objPtr)
+ ScriptObj *scriptBarrier, Jim_Obj *objPtr)
{
int i;
for (i = 0; i < script->len; i++) {
if (script->token[i].objPtr != objPtr &&
- Jim_StringEqObj(script->token[i].objPtr, objPtr, 0))
+ Jim_StringEqObj(script->token[i].objPtr, objPtr, 0)) {
+ /*
+ printf("Found at %s, %d\n", script->fileName,
+ script->token[i].linenr);
+ */
return script->token[i].objPtr;
- if (script->token[i].objPtr->typePtr == &scriptObjType) {
+ }
+ /* Enter recursively on scripts only if the object
+ * is not the same as the one we are searching for
+ * shared occurrences. */
+ if (script->token[i].objPtr->typePtr == &scriptObjType &&
+ script->token[i].objPtr != objPtr) {
Jim_Obj *foundObjPtr;
ScriptObj *subScript =
script->token[i].objPtr->internalRep.ptr;
- foundObjPtr =
- ScriptSearchLiteral(interp, subScript, objPtr);
- if (foundObjPtr != NULL)
- return foundObjPtr;
+ /* Don't recursively enter the script we are trying
+ * to make shared to avoid circular references. */
+ if (subScript == scriptBarrier) continue;
+ if (subScript != script) {
+ foundObjPtr =
+ ScriptSearchLiteral(interp, subScript,
+ scriptBarrier, objPtr);
+ if (foundObjPtr != NULL)
+ return foundObjPtr;
+ }
}
}
return NULL;
@@ -2313,17 +2328,28 @@ static void ScriptShareLiterals(Jim_Interp *interp, ScriptObj *script,
int i, j;
/* Try to share with toplevel object. */
- if (1 && topLevelScript != NULL) {
+ if (0 && topLevelScript != NULL) {
for (i = 0; i < script->len; i++) {
Jim_Obj *foundObjPtr;
char *str = script->token[i].objPtr->bytes;
if (script->token[i].objPtr->refCount != 1) continue;
+ if (script->token[i].objPtr->typePtr == &scriptObjType) continue;
if (strchr(str, ' ') || strchr(str, '\n')) continue;
foundObjPtr = ScriptSearchLiteral(interp,
topLevelScript,
+ script, /* barrier */
script->token[i].objPtr);
if (foundObjPtr != NULL) {
+ /*
+ printf("Sharing '%s' (%p), at %s, %d\n",
+ script->token[i].objPtr->bytes,
+ script->token[i].objPtr,
+ script->fileName,
+ script->token[i].linenr);
+ printf("Proc '%s'\n", interp->framePtr->procArgsObjPtr->bytes);
+ printf("---\n");
+ */
Jim_IncrRefCount(foundObjPtr);
Jim_DecrRefCount(interp,
script->token[i].objPtr);
@@ -2331,6 +2357,7 @@ static void ScriptShareLiterals(Jim_Interp *interp, ScriptObj *script,
}
}
}
+ return;
/* Try to share locally */
for (i = 0; i < script->len; i++) {
char *str = script->token[i].objPtr->bytes;
@@ -5395,11 +5422,13 @@ static void ExprShareLiterals(Jim_Interp *interp, ExprByteCode *expr,
{
int i;
+ return;
for (i = 0; i < expr->len; i++) {
Jim_Obj *foundObjPtr;
if (expr->obj[i] == NULL) continue;
foundObjPtr = ScriptSearchLiteral(interp, topLevelScript,
+ NULL,
expr->obj[i]);
if (foundObjPtr != NULL) {
Jim_IncrRefCount(foundObjPtr);