Changeset: 9edd67ac8c81 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/9edd67ac8c81
Branch: groupjoin
Log Message:

merged with default


diffs (truncated from 1206 to 300 lines):

diff --git a/monetdb5/mal/mal_module.c b/monetdb5/mal/mal_module.c
--- a/monetdb5/mal/mal_module.c
+++ b/monetdb5/mal/mal_module.c
@@ -123,11 +123,15 @@ mal_module_reset(void)
        }
 }
 
-static int getModuleIndex(const char *name) {
+static int
+getModuleIndex(const char *name)
+{
        return (int) (strHash(name) % MODULE_HASH_SIZE);
 }
 
-static void clrModuleIndex(Module cur){
+static void
+clrModuleIndex(Module cur)
+{
        int index = getModuleIndex(cur->name);
        Module prev = NULL;
        Module m = moduleIndex[index];
@@ -145,16 +149,20 @@ static void clrModuleIndex(Module cur){
        }
 }
 
-static void addModuleToIndex(Module cur){
+static void
+addModuleToIndex(Module cur)
+{
        int index = getModuleIndex(cur->name);
        cur->link = moduleIndex[index];
        moduleIndex[index] = cur;
 }
 
-Module getModule(const char *name) {
+Module
+getModule(const char *name)
+{
        int index = getModuleIndex(name);
        Module m = moduleIndex[index];
-       while(m) {
+       while (m) {
                if (name == m->name)
                        return m;
                m = m->link;
@@ -162,7 +170,9 @@ Module getModule(const char *name) {
        return NULL;
 }
 
-void getModuleList(Module** out, int* length) {
+void
+getModuleList(Module** out, int* length)
+{
        int i;
        int moduleCount = 0;
        int currentIndex = 0;
@@ -188,7 +198,9 @@ void getModuleList(Module** out, int* le
        }
 }
 
-void freeModuleList(Module* list) {
+void
+freeModuleList(Module* list)
+{
        GDKfree(list);
 }
 
@@ -196,11 +208,13 @@ void freeModuleList(Module* list) {
  * Module scope management
  * It will contain the symbol table of all globally accessible functions.
  */
-Module globalModule(const char *nme)
-{      Module cur;
+Module
+globalModule(const char *nme)
+{
+       Module cur;
 
        // Global modules are not named 'user'
-       assert (strcmp(nme, "user"));
+       assert(strcmp(nme, "user"));
        nme = putName(nme);
        cur = (Module) GDKzalloc(sizeof(ModuleRecord));
        if (cur == NULL)
@@ -218,7 +232,9 @@ Module globalModule(const char *nme)
 
 /* Every client record has a private module name 'user'
  * for keeping around non-shared functions */
-Module userModule(void){
+Module
+userModule(void)
+{
        Module cur;
 
        cur = (Module) GDKzalloc(sizeof(ModuleRecord));
@@ -238,7 +254,9 @@ Module userModule(void){
  * The scope can be fixed. This is used by the parser.
  * Reading a module often calls for creation first.
  */
-Module fixModule(const char *nme) {
+Module
+fixModule(const char *nme)
+{
        Module m;
 
        m = getModule(nme);
@@ -249,7 +267,8 @@ Module fixModule(const char *nme) {
  * The freeModule operation throws away a symbol without
  * concerns on it whereabouts in the scope structure.
  */
-static void freeSubScope(Module scope)
+static void
+freeSubScope(Module scope)
 {
        int i;
        Symbol s;
@@ -267,7 +286,8 @@ static void freeSubScope(Module scope)
        scope->space = 0;
 }
 
-void freeModule(Module m)
+void
+freeModule(Module m)
 {
        Symbol s;
 
@@ -300,7 +320,9 @@ void freeModule(Module m)
  * This speeds up searching provided the modules adhere to the
  * structure and group the functions as well.
  */
-void insertSymbol(Module scope, Symbol prg){
+void
+insertSymbol(Module scope, Symbol prg)
+{
        InstrPtr sig;
        int t;
        Module c;
@@ -341,7 +363,9 @@ void insertSymbol(Module scope, Symbol p
  * moment of removal. This situation can not easily
  * checked at runtime, without tremendous overhead.
  */
-void deleteSymbol(Module scope, Symbol prg){
+void
+deleteSymbol(Module scope, Symbol prg)
+{
        InstrPtr sig;
        int t;
 
@@ -379,7 +403,9 @@ void deleteSymbol(Module scope, Symbol p
  * The 'user' module is an alias for the scope attached
  * to the current user.
  */
-Module findModule(Module scope, const char *name){
+Module
+findModule(Module scope, const char *name)
+{
        Module def = scope;
        Module m;
        if (name == NULL) return scope;
@@ -402,7 +428,9 @@ Module findModule(Module scope, const ch
  * The variation on this routine is to dump the definition of
  * all matching definitions.
  */
-Symbol findSymbolInModule(Module v, const char *fcn) {
+Symbol
+findSymbolInModule(Module v, const char *fcn)
+{
        Symbol s;
        if (v == NULL || fcn == NULL) return NULL;
        s = v->space[(int)(*fcn)];
@@ -413,7 +441,9 @@ Symbol findSymbolInModule(Module v, cons
        return NULL;
 }
 
-Symbol findSymbol(Module usermodule, const char *mod, const char *fcn) {
+Symbol
+findSymbol(Module usermodule, const char *mod, const char *fcn)
+{
        Module m = findModule(usermodule, mod);
        return findSymbolInModule(m, fcn);
 }
diff --git a/monetdb5/mal/mal_namespace.c b/monetdb5/mal/mal_namespace.c
--- a/monetdb5/mal/mal_namespace.c
+++ b/monetdb5/mal/mal_namespace.c
@@ -23,21 +23,23 @@
 MT_Lock mal_namespaceLock = MT_LOCK_INITIALIZER(mal_namespaceLock);
 
 /* taken from gdk_atoms */
-#define NME_HASH(_key,y,K)                                                     
        \
-       do {                                                                    
                        \
-               size_t _i;                                                      
                        \
-               for (_i = y = 0; _i < K && _key[_i]; _i++) {    \
-                       y += _key[_i];                                          
                \
-                       y += (y << 10);                                         
                \
-                       y ^= (y >> 6);                                          
                \
-               }                                                               
                                \
-               y += (y << 3);                                                  
                \
-               y ^= (y >> 11);                                                 
                \
-               y += (y << 15);                                                 
                \
-               y = y & HASHMASK;                                               
                \
-       } while (0)
+static inline size_t __attribute__((__pure__))
+nme_hash(const char *key, size_t len)
+{
+       size_t y = 0;
 
-typedef struct NAME{
+       for (size_t i = 0; i < len && key[i]; i++) {
+               y += key[i];
+               y += (y << 10);
+               y ^= (y >> 6);
+       }
+       y += (y << 3);
+       y ^= (y >> 11);
+       y += (y << 15);
+       return y & HASHMASK;
+}
+
+typedef struct NAME {
        struct NAME *next;
        char nme[IDLENGTH + 1];
        unsigned short length;
@@ -51,15 +53,18 @@ static struct namespace {
        struct namespace *next;
        int count;
        struct NAME data[4096];
-} *namespace;
+} namespace1, *namespace = &namespace1;
 
-void initNamespace(void) {
-       namespace = NULL;
+void
+initNamespace(void)
+{
        optimizerRef = putName("optimizer");
        totalRef = putName("total");
 }
 
-void mal_namespace_reset(void) {
+void
+mal_namespace_reset(void)
+{
        struct namespace *ns;
 
        /* assume we are at the end of the server session */
@@ -67,9 +72,13 @@ void mal_namespace_reset(void) {
        memset(hash, 0, sizeof(hash));
        while (namespace) {
                ns = namespace->next;
-               GDKfree(namespace);
+               if (namespace != &namespace1)
+                       GDKfree(namespace);
                namespace = ns;
        }
+       namespace1.count = 0;
+       namespace1.next = NULL;
+       namespace = &namespace1;
        MT_lock_unset(&mal_namespaceLock);
 }
 
@@ -80,7 +89,8 @@ void mal_namespace_reset(void) {
  * is conflict free.
  */
 
-static const char *findName(const char *nme, size_t len, bool allocate)
+static const char *
+findName(const char *nme, size_t len, bool allocate)
 {
        NamePtr *n, m;
        size_t key;
@@ -91,31 +101,13 @@ static const char *findName(const char *
        if (len > IDLENGTH) {
                len = IDLENGTH;
        }
-       NME_HASH(nme, key, len);
+       key = nme_hash(nme, len);
        MT_lock_set(&mal_namespaceLock);
        for (n = &hash[key]; *n; n = &(*n)->next) {
-#ifdef KEEP_SORTED
-               /* keep each list sorted on length, then name */
-               if (len < (*n)->length)
-                       continue;
-               if (len == (*n)->length) {
-                       int c;
-                       if ((c = strncmp(nme, (*n)->nme, len)) < 0)
-                               continue;
-                       if (c == 0) {
-                               MT_lock_unset(&mal_namespaceLock);
-                               return (*n)->nme;
-                       }
-                       break;
-               }
-               break;
-#else
-               /* append entries to list */
                if (len == (*n)->length && strncmp(nme, (*n)->nme, len) == 0) {
                        MT_lock_unset(&mal_namespaceLock);
                        return (*n)->nme;
                }
-#endif
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to