Changeset: 1a05a67cc8f4 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=1a05a67cc8f4
Modified Files:
        clients/Tests/exports.stable.out
        monetdb5/mal/mal_instruction.c
        monetdb5/mal/mal_instruction.h
        monetdb5/optimizer/opt_dataflow.c
Branch: default
Log Message:

Extended the pushArgument() function call with two cases to avoid a linear 
search
thru the plan to cope with changing points after a realloc().

pushArgumentIdx(MalBlkPtr mb, int idx, int varid) uses the statement index to 
extend an instruction record.
addArgument(MalBlkPtr mb, InstrPtr p, int varid) simply extends the argument 
list

There are over 400 places to check for these faster versions.


diffs (171 lines):

diff --git a/clients/Tests/exports.stable.out b/clients/Tests/exports.stable.out
--- a/clients/Tests/exports.stable.out
+++ b/clients/Tests/exports.stable.out
@@ -1972,6 +1972,7 @@ str XMLxml2xml(xml *x, xml *s);
 str XMLxmltext(str *s, xml *x);
 str abortRef;
 str actionRef;
+InstrPtr addArgument(MalBlkPtr mb, InstrPtr p, int varid);
 void addMalException(MalBlkPtr mb, str msg);
 str addOptimizerPipe(Client cntxt, MalBlkPtr mb, const char *name);
 str addPipeDefinition(Client cntxt, const char *name, const char *pipe);
@@ -2486,6 +2487,7 @@ str projectionRef;
 str projectionpathRef;
 InstrPtr pushArgument(MalBlkPtr mb, InstrPtr p, int varid);
 InstrPtr pushArgumentId(MalBlkPtr mb, InstrPtr p, const char *name);
+InstrPtr pushArgumentIdx(MalBlkPtr mb, int idx, int varid);
 InstrPtr pushBit(MalBlkPtr mb, InstrPtr q, bit val);
 InstrPtr pushBte(MalBlkPtr mb, InstrPtr q, bte val);
 InstrPtr pushDbl(MalBlkPtr mb, InstrPtr q, dbl val);
diff --git a/monetdb5/mal/mal_instruction.c b/monetdb5/mal/mal_instruction.c
--- a/monetdb5/mal/mal_instruction.c
+++ b/monetdb5/mal/mal_instruction.c
@@ -1138,21 +1138,14 @@ defConstant(MalBlkPtr mb, int type, ValP
  * limited. Furthermore, we should assure that no variable is
  * referenced before being assigned. Failure to obey should mark the
  * instruction as type-error. */
-InstrPtr
-pushArgument(MalBlkPtr mb, InstrPtr p, int varid)
+
+static InstrPtr 
+extendInstruction(MalBlkPtr mb, InstrPtr p)
 {
-       if (p == NULL)
-               return NULL;
-       if (varid < 0) {
-               /* leave everything as is in this exceptional programming error 
*/
-               mb->errors = createMalException(mb, 0, TYPE,"improper variable 
id");
-               return p;
-       }
-
+       InstrPtr pn = p;
        if (p->argc + 1 == p->maxarg) {
-               int i = 0;
                int space = p->maxarg * sizeof(p->argv[0]) + 
offsetof(InstrRecord, argv);
-               InstrPtr pn = (InstrPtr) GDKrealloc(p,space + MAXARG * 
sizeof(p->argv[0]));
+               pn = (InstrPtr) GDKrealloc(p,space + MAXARG * 
sizeof(p->argv[0]));
 
                if (pn == NULL) {
                        /* In the exceptional case we can not allocate more 
space
@@ -1164,6 +1157,27 @@ pushArgument(MalBlkPtr mb, InstrPtr p, i
                }
                memset( ((char*)pn) + space, 0, MAXARG * sizeof(pn->argv[0]));
                pn->maxarg += MAXARG;
+       }
+       return pn;
+}
+
+InstrPtr
+pushArgument(MalBlkPtr mb, InstrPtr p, int varid)
+{
+       InstrPtr pn;
+       if (p == NULL)
+               return NULL;
+       if (varid < 0) {
+               /* leave everything as is in this exceptional programming error 
*/
+               mb->errors = createMalException(mb, 0, TYPE,"improper variable 
id");
+               return p;
+       }
+
+       if (p->argc + 1 == p->maxarg) {
+               int i = 0;
+               pn = extendInstruction(mb, p);
+               if ( mb->errors)
+                       return p;
 
                /* if the instruction is already stored in the MAL block
                 * it should be replaced by an extended version.
@@ -1190,6 +1204,69 @@ pushArgument(MalBlkPtr mb, InstrPtr p, i
        return p;
 }
 
+/* If the instruction is already stored in the MAL block then a
+ * reference to its position avoids an expensive search.
+ */
+InstrPtr
+pushArgumentIdx(MalBlkPtr mb, int idx, int varid)
+{
+       InstrPtr p, pn;
+
+       pn = p = getInstrPtr(mb, idx);
+       if (p == NULL)
+               return NULL;
+       if (varid < 0) {
+               /* leave everything as is in this exceptional programming error 
*/
+               mb->errors = createMalException(mb, 0, TYPE,"improper variable 
id");
+               return p;
+       }
+
+       if (p->argc + 1 == p->maxarg) {
+               pn = extendInstruction(mb, p);
+               if ( mb->errors)
+                       return p;
+               mb->stmt[idx]= pn;
+               p = pn;
+       }
+       /* protect against the case that the instruction is malloced in 
isolation */
+       if( mb->maxarg < p->maxarg)
+               mb->maxarg= p->maxarg;
+
+       p->argv[p->argc++] = varid;
+       return p;
+}
+
+/* the next version assumes that we have allocated an isolated instruction
+ * using newInstruction. As long as it is not stored in the MAL block
+ * we can simpy extend it with arguments
+ */
+InstrPtr
+addArgument(MalBlkPtr mb, InstrPtr p, int varid)
+{
+       InstrPtr pn = p;
+
+       if (p == NULL)
+               return NULL;
+       if (varid < 0) {
+               /* leave everything as is in this exceptional programming error 
*/
+               mb->errors = createMalException(mb, 0, TYPE,"improper variable 
id");
+               return p;
+       }
+
+       if (p->argc + 1 == p->maxarg) {
+               pn = extendInstruction(mb, p);
+               if ( mb->errors)
+                       return p;
+               p = pn;
+       }
+       /* protect against the case that the instruction is malloced in 
isolation */
+       if( mb->maxarg < p->maxarg)
+               mb->maxarg= p->maxarg;
+
+       p->argv[p->argc++] = varid;
+       return p;
+}
+
 InstrPtr
 setArgument(MalBlkPtr mb, InstrPtr p, int idx, int varid)
 {
diff --git a/monetdb5/mal/mal_instruction.h b/monetdb5/mal/mal_instruction.h
--- a/monetdb5/mal/mal_instruction.h
+++ b/monetdb5/mal/mal_instruction.h
@@ -175,6 +175,8 @@ mal_export str convertConstant(malType t
 
 mal_export void pushInstruction(MalBlkPtr mb, InstrPtr p);
 mal_export InstrPtr pushArgument(MalBlkPtr mb, InstrPtr p, int varid);
+mal_export InstrPtr pushArgumentIdx(MalBlkPtr mb, int idx, int varid);
+mal_export InstrPtr addArgument(MalBlkPtr mb, InstrPtr p, int varid);
 mal_export InstrPtr setArgument(MalBlkPtr mb, InstrPtr p, int idx, int varid);
 mal_export InstrPtr pushReturn(MalBlkPtr mb, InstrPtr p, int varid);
 mal_export InstrPtr pushArgumentId(MalBlkPtr mb, InstrPtr p, const char *name);
diff --git a/monetdb5/optimizer/opt_dataflow.c 
b/monetdb5/optimizer/opt_dataflow.c
--- a/monetdb5/optimizer/opt_dataflow.c
+++ b/monetdb5/optimizer/opt_dataflow.c
@@ -167,7 +167,7 @@ dflowGarbagesink(Client cntxt, MalBlkPtr
        
        r = newInstruction(NULL,languageRef, passRef);
        getArg(r,0) = newTmpVariable(mb,TYPE_void);
-       r= pushArgument(mb,r, var);
+       r= addArgument(mb,r, var);
        sink[top++] = r;
        return top;
 }
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to