Changeset: bdc962b4e085 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=bdc962b4e085
Modified Files:
        sql/common/sql_list.c
Branch: Aug2011
Log Message:

sql_list: don't use alloca

If this is very requently used code, it is probably worth switching on
cnt, e.g. < 20 to use a simple array for pos (int[20]), and for larger
sizes the malloc.


diffs (40 lines):

diff --git a/sql/common/sql_list.c b/sql/common/sql_list.c
--- a/sql/common/sql_list.c
+++ b/sql/common/sql_list.c
@@ -285,7 +285,7 @@ list_keysort(list *l, int *keys, fdup du
        node *n = NULL;
        int i, j, *pos, cnt = list_length(l);
 
-       pos = (int*)alloca(cnt*sizeof(int));
+       pos = (int*)GDKmalloc(cnt*sizeof(int));
        for (n = l->h, i = 0; n; n = n->next, i++) {
                pos[i] = i;
        }
@@ -296,6 +296,7 @@ list_keysort(list *l, int *keys, fdup du
                        assert(n);
                list_append(res, dup?dup(n->data):n->data);
        }
+       GDKfree(pos);
        return res;
 }
 
@@ -306,8 +307,8 @@ list_sort(list *l, fkeyvalue key, fdup d
        node *n = NULL;
        int i, j, *keys, *pos, cnt = list_length(l);
 
-       keys = (int*)alloca(cnt*sizeof(int));
-       pos = (int*)alloca(cnt*sizeof(int));
+       keys = (int*)GDKmalloc(cnt*sizeof(int));
+       pos = (int*)GDKmalloc(cnt*sizeof(int));
        for (n = l->h, i = 0; n; n = n->next, i++) {
                keys[i] = key(n->data);
                pos[i] = i;
@@ -319,6 +320,8 @@ list_sort(list *l, fkeyvalue key, fdup d
                        assert(n);
                list_append(res, dup?dup(n->data):n->data);
        }
+       GDKfree(keys);
+       GDKfree(pos);
        return res;
 }
 
_______________________________________________
Checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to