commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r938502 - in /commons/sandbox/runtime/trunk/src/main/native: configure shared/tables.c
Date Tue, 27 Apr 2010 15:14:11 GMT
Author: mturk
Date: Tue Apr 27 15:14:11 2010
New Revision: 938502

URL: http://svn.apache.org/viewvc?rev=938502&view=rev
Log:
Tables needs to be reindexed when array is expanded

Modified:
    commons/sandbox/runtime/trunk/src/main/native/configure
    commons/sandbox/runtime/trunk/src/main/native/shared/tables.c

Modified: commons/sandbox/runtime/trunk/src/main/native/configure
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/configure?rev=938502&r1=938501&r2=938502&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/configure (original)
+++ commons/sandbox/runtime/trunk/src/main/native/configure Tue Apr 27 15:14:11 2010
@@ -649,8 +649,12 @@ esac
 
 case "$host-$cc" in
     *-gcc      )
-        v=(`echo __GNUC__ __GNUC_MINOR__ __GNUC_PATCHLEVEL__ | gcc -E - | tail -1`)
+        v=(`$cc -dumpversion 2>/dev/null | sed 's/\./ /g'`)
         cc_ver_major=${v[0]}
+        if [ ".$cc_ver_major" = . ]; then
+        	echo "Error: Cannot determine $cc version"
+        	exit 1
+        fi
         cc_ver_minor=${v[1]}
         if [ ".$has_maintainer_mode" != .yes ]; then
             varadds cppopts -fno-stack-protector

Modified: commons/sandbox/runtime/trunk/src/main/native/shared/tables.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/tables.c?rev=938502&r1=938501&r2=938502&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/tables.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/tables.c Tue Apr 27 15:14:11 2010
@@ -132,6 +132,21 @@ static ACR_INLINE unsigned int times33ha
     return hash & ACR_TABLE_HASH_MASK;
 }
 
+static void reindexTable(acr_table_t *t)
+{
+    size_t i;
+    table_entry_t *e = (table_entry_t *)t->a.elts;
+
+    memset(t->hash, 0, sizeof(t->hash));                    
+    for (i = 0; i < t->a.nelts; i++, e++) {
+        unsigned int hash;
+
+        hash = times33hash(e->key);
+        e->next = t->hash[hash];
+        t->hash[hash] = e;                    
+    }
+}
+
 ACR_DECLARE(acr_table_t *) ACR_TableMake(JNIEnv *_E, const char *file, int line,
                                          acr_size_t nelts)
 {
@@ -158,6 +173,7 @@ ACR_DECLARE(void *) ACR_TableSet(JNIEnv 
 {
     table_entry_t *e = NULL;
     unsigned int hash;
+    int          reindex;
     void *o = NULL;
 
     if (!key || !*key) {
@@ -178,6 +194,7 @@ ACR_DECLARE(void *) ACR_TableSet(JNIEnv 
         }
     }
     if (e == NULL) {
+        reindex = t->a.nelts == t->a.nalloc;
         e = (table_entry_t *)ACR_ArrayPush(_E, file, line, &(t->a));
         if (!e) {
             /* The exception has already been thrown.
@@ -186,9 +203,15 @@ ACR_DECLARE(void *) ACR_TableSet(JNIEnv 
             return NULL;
         }
         e->key  = ACR_StrdupA(_E, file, line, key);
-        /* Insert new bucket into the list */
-        e->next = t->hash[hash];
-        t->hash[hash] = e;
+        if (reindex) {
+            /* Array was resized so we need to reindex the table */
+            reindexTable(t);
+        }
+        else {
+            /* Insert new bucket into the list */
+            e->next = t->hash[hash];
+            t->hash[hash] = e;
+        }
     }
     else
         o = e->data;
@@ -204,6 +227,7 @@ ACR_DECLARE(void) ACR_TableAdd(JNIEnv *_
 {
     table_entry_t *e;
     unsigned int hash;
+    int          reindex;
 
     if (!key || !*key) {
         ACR_ThrowException(_E, file, line, ACR_EX_ENULL,
@@ -212,6 +236,7 @@ ACR_DECLARE(void) ACR_TableAdd(JNIEnv *_
     }
     hash = times33hash(key);
 
+       reindex = t->a.nelts == t->a.nalloc;
     e = (table_entry_t *)ACR_ArrayPush(_E, file, line, &(t->a));
     if (!e) {
         /* The exception has already been thrown.
@@ -222,9 +247,15 @@ ACR_DECLARE(void) ACR_TableAdd(JNIEnv *_
     e->key  = ACR_StrdupA(_E, file, line, key);
     e->data = (void *)data;
     e->dlen = dlen;
-    /* Insert new bucket into the list */
-    e->next = t->hash[hash];
-    t->hash[hash] = e;
+    if (reindex) {
+        /* Array was resized so we need to reindex the table */
+        reindexTable(t);
+    }
+    else {
+        /* Insert new bucket into the list */
+        e->next = t->hash[hash];
+        t->hash[hash] = e;
+    }
 }
 
 ACR_DECLARE(int) ACR_TableGet(acr_table_t *t, const char *key,



Mime
View raw message