Changeset: 0df73662d747 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=0df73662d747
Modified Files:
        clients/Tests/exports.stable.out
        monetdb5/mal/mal_parser.c
        monetdb5/mal/mal_parser.h
Branch: default
Log Message:

small optimization and cleanup of exported mal parser symbols


diffs (truncated from 338 to 300 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
@@ -1380,8 +1380,6 @@ str MALengine(Client c);
 str MALexitClient(Client c);
 str MALgarbagesink(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci);
 str MALinitClient(Client c);
-int MALkeyword(Client cntxt, str kw, int length);
-int MALlookahead(Client cntxt, str kw, int length);
 str MALoptimizer(Client c);
 str MALparser(Client c);
 str MALpass(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci);
@@ -2101,7 +2099,6 @@ int canBeCrackedProp;
 int canBeJoinselectProp;
 str catalogRef;
 str catchKernelException(Client cntxt, str ret);
-int charCst(Client cntxt, ValPtr val);
 void chkDeclarations(stream *out, MalBlkPtr mb);
 void chkFlow(stream *out, MalBlkPtr mb);
 int chkInstruction(stream *out, Module s, MalBlkPtr mb, InstrPtr p);
@@ -2141,7 +2138,6 @@ int cpyConstant(MalBlkPtr mb, VarPtr vr)
 str createException(enum malexception, const char *, _In_z_ 
_Printf_format_string_ const char *, ...) __attribute__((__format__(__printf__, 
3, 4)));
 str createRef;
 str crossRef;
-int cstToken(Client cntxt, ValPtr val);
 str datacyclotronRef;
 str dataflowRef;
 str dateRef;
@@ -2154,7 +2150,6 @@ str dblRef;
 void debugFunction(stream *fd, MalBlkPtr mb, MalStkPtr stk, int flg, int 
first, int size);
 void debugLifespan(Client cntxt, MalBlkPtr mb, Lifespan span);
 str debugOptimizers(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci);
-void debugParser(int i);
 str debugScheduler(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci);
 int defConstant(MalBlkPtr mb, int type, ValPtr cst);
 str defineRef;
@@ -2176,7 +2171,6 @@ str divRef;
 void dumpExceptionsToStream(stream *out, str msg);
 void dumpHelpTable(stream *f, Module s, str text, int flag);
 void dumpSearchTable(stream *f, str text);
-void echoInput(Client cntxt);
 str eqRef;
 str escape_str(str *retval, str s);
 str evalFile(Client c, str fname, int listing);
@@ -2270,7 +2264,6 @@ str hgeRef;
 int hlbProp;
 int horiginProp;
 int hubProp;
-int idLength(Client cntxt);
 str identityRef;
 str ifthenelseRef;
 str ilikeRef;
@@ -2340,7 +2333,6 @@ str kdifferenceRef;
 int keepProp;
 str kunionRef;
 str languageRef;
-str lastline(Client cntxt);
 str leftfetchjoinPathRef;
 str leftfetchjoinRef;
 str leftjoinPathRef;
@@ -2488,8 +2480,6 @@ str openProfilerStream(stream *fd);
 str openRef;
 int open_block_stream(Stream *S, Stream *is);
 str open_block_streamwrap(Stream *S, Stream *is);
-str operatorCopy(Client cntxt, int length);
-int operatorLength(Client cntxt);
 str operatorName(int i);
 lng optDebug;
 str optimizeMALBlock(Client cntxt, MalBlkPtr mb);
@@ -2499,7 +2489,6 @@ str optimizer_prelude(Client cntxt, MalB
 str pack2Ref;
 str packRef;
 str parametersRef;
-str parseError(Client cntxt, str msg);
 int parseMAL(Client cntxt, Symbol curPrg, int skipcomments);
 str partitionRef;
 str passRef;
@@ -2510,7 +2499,6 @@ str pinRef;
 int pivotDisjunctiveProp;
 int pivotProp;
 str plusRef;
-ssize_t position(Client cntxt);
 str postludeRef;
 str preludeRef;
 MalStkPtr prepareMALstack(MalBlkPtr mb, int size);
@@ -2667,7 +2655,6 @@ str strEpilogue(void *ret);
 str strPrelude(void *ret);
 str strRef;
 str streamsRef;
-int stringLength(Client cntxt);
 str stringdiff_impl(int *res, str *s1, str *s2);
 str subantijoinRef;
 str subavgRef;
diff --git a/monetdb5/mal/mal_parser.c b/monetdb5/mal/mal_parser.c
--- a/monetdb5/mal/mal_parser.c
+++ b/monetdb5/mal/mal_parser.c
@@ -28,13 +28,14 @@
 static str idCopy(Client cntxt, int len);
 static str strCopy(Client cntxt, int len);
 
-
+static str parseError(Client cntxt, str msg);
 
 /* Before a line is parsed we check for a request to echo it.
  * This command should be executed at the beginning of a parse
  * request and each time we encounter EOL.
 */
-void echoInput(Client cntxt)
+static void 
+echoInput(Client cntxt)
 {
        if (cntxt->listing == 1) {
                char *c = CURRENT(cntxt);
@@ -112,7 +113,7 @@ initParser(void)
 #undef isdigit
 #define isdigit(X)  ((X) >= '0' && (X) <= '9')
 
-int
+static int
 idLength(Client cntxt)
 {
        str s, t;
@@ -169,18 +170,7 @@ idCopy(Client cntxt, int length)
        return s;
 }
 
-int
-MALkeyword(Client cntxt, str kw, int length)
-{
-       skipSpace(cntxt);
-       if (MALlookahead(cntxt, kw, length)) {
-               advance(cntxt, length);
-               return 1;
-       }
-       return 0;
-}
-
-int
+static int
 MALlookahead(Client cntxt, str kw, int length)
 {
        int i;
@@ -203,6 +193,18 @@ MALlookahead(Client cntxt, str kw, int l
        }
        return 0;
 }
+
+static inline int
+MALkeyword(Client cntxt, str kw, int length)
+{
+       skipSpace(cntxt);
+       if (MALlookahead(cntxt, kw, length)) {
+               advance(cntxt, length);
+               return 1;
+       }
+       return 0;
+}
+
 /*
  * Keyphrase testing is limited to a few characters only
  * (check manually). To speed this up we use a pipelined and inline macros.
@@ -237,7 +239,7 @@ keyphrase2(Client cntxt, str kw)
  * We should provide the C-method to split strings and
  * concatenate them upon retrieval[todo]
 */
-int
+static int
 stringLength(Client cntxt)
 {
        int l = 0;
@@ -248,18 +250,13 @@ stringLength(Client cntxt)
 
        if (*s != '"')
                return 0;
-       s++;
-       while (*s) {
+       for (s++;*s; l++, s++) {
                if (quote) {
-                       l++;
-                       s++;
                        quote = 0;
                } else {
                        if (*s == '"')
                                break;
                        quote = *s == '\\';
-                       l++;
-                       s++;
                }
        }
        return l + 2;
@@ -276,10 +273,11 @@ strCopy(Client cntxt, int length)
        int i;
 
        i = length < 4 ? 4 : length;
-       s = GDKzalloc(i);
+       s = GDKmalloc(i);
        if (s == 0)
                return NULL;
        memcpy(s, CURRENT(cntxt) + 1, (size_t) (length - 2));
+       s[length-2] = 0;
        mal_unquote(s);
        return s;
 }
@@ -289,7 +287,7 @@ strCopy(Client cntxt, int length)
  * A lookup table is considered, because it generally is
  * faster then a non-dense switch.
 */
-int
+static int
 operatorLength(Client cntxt)
 {
        int l = 0;
@@ -305,7 +303,7 @@ operatorLength(Client cntxt)
        return l;
 }
 
-str
+static str
 operatorCopy(Client cntxt, int length)
 {
        return idCopy(cntxt,length);
@@ -316,7 +314,7 @@ operatorCopy(Client cntxt, int length)
  * which, ofcourse, is easy given the client buffer.
  * The remaining functions are self-explanatory.
 */
-str
+static str
 lastline(Client cntxt)
 {
        str s = CURRENT(cntxt);
@@ -329,7 +327,7 @@ lastline(Client cntxt)
        return s;
 }
 
-ssize_t
+static ssize_t
 position(Client cntxt)
 {
        str s = lastline(cntxt);
@@ -355,7 +353,7 @@ skipToEnd(Client cntxt)
  * Aside from getting its length, we need an indication of its type.
  * The constant structure is initialized for later use.
  */
-int
+static int
 cstToken(Client cntxt, ValPtr cst)
 {
        int i = 0;
@@ -682,7 +680,7 @@ parseTypeId(Client cntxt, int defaultTyp
        int i = TYPE_any, ht, tt, kh = 0, kt = 0;
        char *s = CURRENT(cntxt);
 
-       if (strncmp(s, ":bat[", 5) == 0) {
+       if (s[0] == ':' && s[1] == 'b' && s[2] == 'a' && s[3] == 't' && s[4] == 
'[') {
                /* parse :bat[:type,:type] */
                advance(cntxt, 5);
                if (currChar(cntxt) == ':') {
@@ -715,12 +713,15 @@ parseTypeId(Client cntxt, int defaultTyp
                skipSpace(cntxt);
                return i;
        }
-       if ((strncmp(s, ":bat", 4) == 0 ||
-                strncmp(s, ":BAT", 4) == 0) && !idCharacter[(int) s[4]]) {
+       if (s[0] == ':' && 
+          ((s[1] == 'b' && s[2] == 'a' && s[3] == 't')  || 
+           (s[1] == 'B' && s[2] == 'A' && s[3] == 'T')) && 
+          !idCharacter[(int) s[4]]) {
                advance(cntxt, 4);
                return TYPE_bat;
        }
-       if (strncmp(s, ":col", 4) == 0 && !idCharacter[(int) s[4]]) {
+       if (s[0] == ':' && s[1] == 'c' && s[2] == 'o' && s[3] == 'l' &&
+          !idCharacter[(int) s[4]]) {
                /* parse default for :col[:any] */
                advance(cntxt, 4);
                return newColumnType(TYPE_any);
@@ -1384,6 +1385,7 @@ parseCommandPattern(Client cntxt, int ki
        Symbol curPrg = 0;
        InstrPtr curInstr = 0;
        str modnme = NULL;
+       int l = 0;
 
        curBlk = fcnHeader(cntxt, kind);
        if (curBlk == NULL) 
@@ -1398,8 +1400,10 @@ parseCommandPattern(Client cntxt, int ki
                return (MalBlkPtr) parseError(cntxt, "<module> not defined\n");
        modnme = modnme ? modnme : cntxt->nspace->name;
 
-       if (isModuleDefined(cntxt->nspace, putName(modnme, strlen(modnme))))
-               insertSymbol(findModule(cntxt->nspace, putName(modnme, 
strlen(modnme))), curPrg);
+       l = strlen(modnme);
+       modnme = putName(modnme, l);
+       if (isModuleDefined(cntxt->nspace, modnme))
+               insertSymbol(findModule(cntxt->nspace, modnme), curPrg);
        else
                return (MalBlkPtr) parseError(cntxt, "<module> not found\n");
        trimMalBlk(curBlk);
@@ -1434,7 +1438,7 @@ parseCommandPattern(Client cntxt, int ki
                if (getModuleId(curInstr))
                        setModuleId(curInstr, NULL);
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to