avoid empty hash tables

This commit is contained in:
Vitor Santos Costa 2014-09-23 22:37:08 +01:00
parent fcc0c51ce7
commit 429e87404f
2 changed files with 10 additions and 3 deletions

View File

@ -168,9 +168,12 @@ static PredEntry *
LookupPredEntry(PredEntry *op) LookupPredEntry(PredEntry *op)
{ {
CACHE_REGS CACHE_REGS
CELL hash = (CELL)(op) % LOCAL_ImportPredEntryHashTableSize; CELL hash;
import_pred_entry_hash_entry_t *p; import_pred_entry_hash_entry_t *p;
if (LOCAL_ImportPredEntryHashTableSize == 0)
return NULL;
hash = (CELL)(op) % LOCAL_ImportPredEntryHashTableSize;
p = LOCAL_ImportPredEntryHashChain[hash]; p = LOCAL_ImportPredEntryHashChain[hash];
while (p) { while (p) {
if (p->oval == op) { if (p->oval == op) {
@ -186,9 +189,12 @@ static void
InsertPredEntry(PredEntry *op, PredEntry *pe) InsertPredEntry(PredEntry *op, PredEntry *pe)
{ {
CACHE_REGS CACHE_REGS
CELL hash = (CELL)(op) % LOCAL_ImportPredEntryHashTableSize; CELL hash;
import_pred_entry_hash_entry_t *p; import_pred_entry_hash_entry_t *p;
if (LOCAL_ImportPredEntryHashTableSize == 0)
return NULL;
hash = (CELL)(op) % LOCAL_ImportPredEntryHashTableSize;
p = LOCAL_ImportPredEntryHashChain[hash]; p = LOCAL_ImportPredEntryHashChain[hash];
while (p) { while (p) {
if (p->oval == op) { if (p->oval == op) {
@ -807,7 +813,7 @@ ReadHash(IOSTREAM *stream)
} }
RCHECK(read_tag(stream) == QLY_START_DBREFS); RCHECK(read_tag(stream) == QLY_START_DBREFS);
LOCAL_ImportDBRefHashTableNum = read_UInt(stream); LOCAL_ImportDBRefHashTableNum = read_UInt(stream);
LOCAL_ImportDBRefHashTableSize = 2*LOCAL_ImportDBRefHashTableNum; LOCAL_ImportDBRefHashTableSize = 2*LOCAL_ImportDBRefHashTableNum+17;
LOCAL_ImportDBRefHashChain = (import_dbref_hash_entry_t **)calloc(LOCAL_ImportDBRefHashTableSize, sizeof(import_dbref_hash_entry_t *)); LOCAL_ImportDBRefHashChain = (import_dbref_hash_entry_t **)calloc(LOCAL_ImportDBRefHashTableSize, sizeof(import_dbref_hash_entry_t *));
for (i = 0; i < LOCAL_ImportDBRefHashTableNum; i++) { for (i = 0; i < LOCAL_ImportDBRefHashTableNum; i++) {
LogUpdClause *ocl = (LogUpdClause *)read_UInt(stream); LogUpdClause *ocl = (LogUpdClause *)read_UInt(stream);

View File

@ -875,6 +875,7 @@ p_save_module_preds( USES_REGS1 )
Yap_Error(TYPE_ERROR_ATOM,tmod,"save_module/2"); Yap_Error(TYPE_ERROR_ATOM,tmod,"save_module/2");
return FALSE; return FALSE;
} }
save_header( stream );
return save_module(stream, tmod) != 0; return save_module(stream, tmod) != 0;
} }