Changeset: 4f06f1996188 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=4f06f1996188
Modified Files:
        common/utils/mstring.h
        gdk/gdk_bat.c
        monetdb5/mal/mal_dataflow.c
        monetdb5/mal/mal_instruction.c
Branch: default
Log Message:

Replace more commonly used snprintf calls


diffs (103 lines):

diff --git a/common/utils/mstring.h b/common/utils/mstring.h
--- a/common/utils/mstring.h
+++ b/common/utils/mstring.h
@@ -76,4 +76,25 @@ strconcat_len(char *restrict dst, size_t
        return i;
 }
 
+/* convert integer into string, BUT this code does NOT deal with NEGATIVE 
INTEGERS! */
+static inline char *
+int_to_str(char *restrict dst, int i)
+{
+       char const digit[] = "0123456789";
+       int shift = i;
+
+       assert(i > 0);
+       do { /* Find end of string */
+               ++dst;
+               shift /= 10;
+       } while (shift);
+
+       *dst = '\0';
+       do { /* Insert digits value while going back */
+               *--dst = digit[i%10];
+               i /= 10;
+       } while (i);
+       return dst;
+}
+
 #endif
diff --git a/gdk/gdk_bat.c b/gdk/gdk_bat.c
--- a/gdk/gdk_bat.c
+++ b/gdk/gdk_bat.c
@@ -139,9 +139,9 @@ BATcreatedesc(oid hseq, int tt, bool hea
                assert(bn->theap == NULL);
        }
        char name[MT_NAME_LEN];
-       snprintf(name, sizeof(name), "heaplock%d", bn->batCacheid); /* fits */
+       int_to_str(stpcpy(name, "heaplock"), bn->batCacheid); /* fits */
        MT_lock_init(&bn->theaplock, name);
-       snprintf(name, sizeof(name), "BATlock%d", bn->batCacheid); /* fits */
+       int_to_str(stpcpy(name, "BATlock"), bn->batCacheid); /* fits */
        MT_lock_init(&bn->batIdxLock, name);
        bn->batDirtydesc = true;
        return bn;
diff --git a/monetdb5/mal/mal_dataflow.c b/monetdb5/mal/mal_dataflow.c
--- a/monetdb5/mal/mal_dataflow.c
+++ b/monetdb5/mal/mal_dataflow.c
@@ -839,7 +839,8 @@ runMALdataflow(Client cntxt, MalBlkPtr m
                        }
                        workers[i].flag = RUNNING;
                        char name[MT_NAME_LEN];
-                       snprintf(name, sizeof(name), "DFLOWworker%d", i);
+                       int_to_str(stpcpy(name, "DFLOWworker"), i); /* should 
fit */
+                       assert(strlen(name) < MT_NAME_LEN);
                        if ((workers[i].errbuf = GDKmalloc(GDKMAXERRLEN)) == 
NULL ||
                                (workers[i].id = THRcreate(DFLOWworker, (void 
*) &workers[i],
                                                                                
   MT_THR_JOINABLE, name)) == 0) {
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
@@ -773,24 +773,6 @@ setVariableType(MalBlkPtr mb, const int 
        clrVarCleanup(mb, n);
 }
 
-static inline void
-myitoa(char *p, int i) /* convert integer into string, but this code doesn't 
deal with negative integers! */
-{
-       char const digit[] = "0123456789";
-       int shift = i;
-
-       do { /* Find end of string */
-               ++p;
-               shift /= 10;
-       } while (shift);
-
-       *p = '\0';
-       do { /* Insert digits value while going back */
-               *--p = digit[i%10];
-               i /= 10;
-       } while (i);
-}
-
 int
 newVariable(MalBlkPtr mb, const char *name, size_t len, malType type)
 {
@@ -810,7 +792,7 @@ newVariable(MalBlkPtr mb, const char *na
                /* Don't call snprintf because it's expensive on this common 
code */
                vname[0] = REFMARKER;
                vname[1] = TMPMARKER;
-               myitoa(vname + 2, mb->vid++);
+               int_to_str(vname + 2, mb->vid++);
 
                assert(strlen(vname) < IDLENGTH);
        } else {
@@ -958,7 +940,7 @@ trimMalVariables_(MalBlkPtr mb, MalStkPt
                        /* Don't call snprintf because it's too expensive on 
this common code */
                        vname[0] = REFMARKER;
                        vname[1] = TMPMARKER;
-                       myitoa(vname + 2, mb->vid++);
+                       int_to_str(vname + 2, mb->vid++);
 
                        assert(strlen(vname) < IDLENGTH);
                }
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to