hash_hi() made faster by caching sch_path_hash[]
This commit is contained in:
parent
a3d2b0c162
commit
94cd0d0c7d
|
|
@ -413,6 +413,7 @@ void ask_new_file(void)
|
|||
load_schematic(1, fullname,1); /* 20180925.1 */
|
||||
Tcl_VarEval(interp, "update_recent_file {", fullname, "}", NULL);
|
||||
my_strdup(1, &xctx->sch_path[xctx->currsch],".");
|
||||
xctx->sch_path_hash[xctx->currsch] = 0;
|
||||
xctx->sch_inst_number[xctx->currsch] = 1;
|
||||
zoom_full(1, 0, 1, 0.97);
|
||||
}
|
||||
|
|
@ -1050,6 +1051,7 @@ void descend_schematic(int instnumber)
|
|||
inst_mult = 1;
|
||||
}
|
||||
my_strdup(14, &xctx->sch_path[xctx->currsch+1], xctx->sch_path[xctx->currsch]);
|
||||
xctx->sch_path_hash[xctx->currsch+1] =0;
|
||||
|
||||
inst_number = 1;
|
||||
if(inst_mult > 1) { /* on multiple instances ask where to descend, to correctly evaluate
|
||||
|
|
@ -1064,6 +1066,7 @@ void descend_schematic(int instnumber)
|
|||
dbg(1, "descend_schematic(): inum=%s\n", inum);
|
||||
if(!inum[0]) {
|
||||
my_free(710, &xctx->sch_path[xctx->currsch+1]);
|
||||
xctx->sch_path_hash[xctx->currsch+1] =0;
|
||||
return;
|
||||
}
|
||||
inst_number=atoi(inum);
|
||||
|
|
|
|||
|
|
@ -24,15 +24,20 @@
|
|||
|
||||
static unsigned int hi_hash(const char *tok)
|
||||
{
|
||||
register int hash = 0;
|
||||
register unsigned int hash = 0;
|
||||
register char *str;
|
||||
register int c;
|
||||
|
||||
str=xctx->sch_path[xctx->currsch];
|
||||
if(xctx->sch_path_hash[xctx->currsch] == 0) {
|
||||
str=xctx->sch_path[xctx->currsch];
|
||||
while ( (c = *str++) )
|
||||
hash = c + hash * 65599;
|
||||
xctx->sch_path_hash[xctx->currsch] = hash;
|
||||
} else {
|
||||
hash = xctx->sch_path_hash[xctx->currsch];
|
||||
}
|
||||
while ( (c = *tok++) )
|
||||
hash = c + (hash << 6) + (hash << 16) - hash;
|
||||
while ( (c = *str++) )
|
||||
hash = c + (hash << 6) + (hash << 16) - hash;
|
||||
hash = c + hash * 65599;
|
||||
return hash;
|
||||
}
|
||||
|
||||
|
|
@ -41,8 +46,6 @@ static struct hilight_hashentry *free_hilight_entry(struct hilight_hashentry *en
|
|||
struct hilight_hashentry *tmp;
|
||||
while(entry) {
|
||||
tmp = entry->next;
|
||||
my_free(755, &entry->token);
|
||||
my_free(756, &entry->path);
|
||||
my_free(757, &entry);
|
||||
entry = tmp;
|
||||
}
|
||||
|
|
@ -216,15 +219,17 @@ struct hilight_hashentry *hilight_lookup(const char *token, int value, int what)
|
|||
depth=0;
|
||||
while(1) {
|
||||
if( !entry ) { /* empty slot */
|
||||
int lent = (strlen(token) + 8) & ~(size_t) 0x7; /* align to 8 byte boundaries */
|
||||
int lenp = strlen(xctx->sch_path[xctx->currsch]) + 1;
|
||||
if( what==XINSERT || what == XINSERT_NOREPLACE) { /* insert data */
|
||||
s=sizeof( struct hilight_hashentry );
|
||||
s=sizeof( struct hilight_hashentry ) + lent + lenp;
|
||||
ptr= my_malloc(137, s );
|
||||
entry=(struct hilight_hashentry *)ptr;
|
||||
entry->next = NULL;
|
||||
entry->token = NULL;
|
||||
my_strdup(138, &(entry->token),token);
|
||||
entry->path = NULL;
|
||||
my_strdup(139, &(entry->path),xctx->sch_path[xctx->currsch]);
|
||||
entry->token = ptr + sizeof( struct hilight_hashentry );
|
||||
memcpy(entry->token, token, lent);
|
||||
entry->path = entry->token + lent;
|
||||
memcpy(entry->path, xctx->sch_path[xctx->currsch], lenp);
|
||||
entry->oldvalue = value-1000; /* no old value, set different value anyway*/
|
||||
entry->value = value;
|
||||
entry->time = xctx->hilight_time;
|
||||
|
|
@ -238,8 +243,6 @@ struct hilight_hashentry *hilight_lookup(const char *token, int value, int what)
|
|||
!strcmp(xctx->sch_path[xctx->currsch], entry->path) ) { /* found matching tok */
|
||||
if(what==XDELETE) { /* remove token from the hash table ... */
|
||||
saveptr=entry->next;
|
||||
my_free(762, &entry->token);
|
||||
my_free(763, &entry->path);
|
||||
my_free(764, &entry);
|
||||
*preventry=saveptr;
|
||||
} else if(what == XINSERT ) {
|
||||
|
|
|
|||
|
|
@ -24,11 +24,11 @@
|
|||
|
||||
static unsigned int nh_hash(const char *tok)
|
||||
{
|
||||
unsigned int hash = 0;
|
||||
int c;
|
||||
register unsigned int hash = 0;
|
||||
register int c;
|
||||
|
||||
while ( (c = *tok++) )
|
||||
hash = c + (hash << 6) + (hash << 16) - hash;
|
||||
hash = c + hash * 65599;
|
||||
return hash;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2228,6 +2228,7 @@ void descend_symbol(void)
|
|||
my_strdup(364, &xctx->sch_path[xctx->currsch+1], xctx->sch_path[xctx->currsch]);
|
||||
my_strcat(365, &xctx->sch_path[xctx->currsch+1], str);
|
||||
my_strcat(366, &xctx->sch_path[xctx->currsch+1], ".");
|
||||
xctx->sch_path_hash[xctx->currsch+1] = 0;
|
||||
xctx->sch_inst_number[xctx->currsch+1] = 1;
|
||||
my_free(921, &str);
|
||||
xctx->previous_instance[xctx->currsch]=xctx->sel_array[0].n;
|
||||
|
|
|
|||
|
|
@ -1383,6 +1383,7 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg
|
|||
load_schematic(1, abs_sym_path(argv[2], ""), 1);
|
||||
Tcl_VarEval(interp, "update_recent_file {", abs_sym_path(argv[2], ""), "}", NULL);
|
||||
my_strdup(375, &xctx->sch_path[xctx->currsch],".");
|
||||
xctx->sch_path_hash[xctx->currsch] = 0;
|
||||
xctx->sch_inst_number[xctx->currsch] = 1;
|
||||
zoom_full(1, 0, 1, 0.97);
|
||||
}
|
||||
|
|
@ -1419,6 +1420,7 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg
|
|||
/* load_symbol(argv[2]); */
|
||||
load_schematic(0, abs_sym_path(argv[2], ""), 1);
|
||||
my_strdup(374, &xctx->sch_path[xctx->currsch],".");
|
||||
xctx->sch_path_hash[xctx->currsch] = 0;
|
||||
xctx->sch_inst_number[xctx->currsch] = 1;
|
||||
zoom_full(1, 0, 1, 0.97);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -167,6 +167,7 @@ void global_spice_netlist(int global) /* netlister driver */
|
|||
|
||||
my_strdup(469, &xctx->sch_path[xctx->currsch+1], xctx->sch_path[xctx->currsch]);
|
||||
my_strcat(481, &xctx->sch_path[xctx->currsch+1], "->netlisting");
|
||||
xctx->sch_path_hash[xctx->currsch+1] = 0;
|
||||
xctx->currsch++;
|
||||
|
||||
dbg(1, "global_spice_netlist(): last defined symbol=%d\n",xctx->symbols);
|
||||
|
|
|
|||
|
|
@ -94,6 +94,7 @@ void global_tedax_netlist(int global) /* netlister driver */
|
|||
|
||||
my_strdup(482, &xctx->sch_path[xctx->currsch+1], xctx->sch_path[xctx->currsch]);
|
||||
my_strcat(485, &xctx->sch_path[xctx->currsch+1], "->netlisting");
|
||||
xctx->sch_path_hash[xctx->currsch+1] = 0;
|
||||
xctx->currsch++;
|
||||
|
||||
dbg(2, "global_tedax_netlist(): last defined symbol=%d\n",xctx->symbols);
|
||||
|
|
|
|||
28
src/token.c
28
src/token.c
|
|
@ -39,11 +39,11 @@ enum status {TOK_BEGIN, TOK_TOKEN, TOK_SEP, TOK_VALUE, TOK_END, TOK_ENDTOK};
|
|||
/* calculate the hash function relative to string s */
|
||||
static unsigned int hash(char *tok)
|
||||
{
|
||||
unsigned int hash = 0;
|
||||
int c;
|
||||
register unsigned int hash = 0;
|
||||
register int c;
|
||||
|
||||
while ( (c = *tok++) )
|
||||
hash = c + (hash << 6) + (hash << 16) - hash;
|
||||
hash = c + hash * 65599;
|
||||
return hash;
|
||||
}
|
||||
|
||||
|
|
@ -68,7 +68,7 @@ int name_strcmp(char *s, char *d) /* compare strings up to '\0' or'[' */
|
|||
}
|
||||
|
||||
/* 20180926 added token_size */
|
||||
/* remove:
|
||||
/* what:
|
||||
* 0,XINSERT : lookup and insert in hash table (return NULL if token was not found)
|
||||
* if token was found update value
|
||||
3,XINSERT_NOREPLACE : same as XINSERT but do not replace existing value if token found.
|
||||
|
|
@ -76,7 +76,7 @@ int name_strcmp(char *s, char *d) /* compare strings up to '\0' or'[' */
|
|||
* 2,XLOOKUP : lookup only
|
||||
*/
|
||||
static struct inst_hashentry *inst_hash_lookup(struct inst_hashentry **table, char *token,
|
||||
int value, int remove, size_t token_size)
|
||||
int value, int what, size_t token_size)
|
||||
{
|
||||
unsigned int hashcode;
|
||||
unsigned int idx;
|
||||
|
|
@ -90,7 +90,7 @@ static struct inst_hashentry *inst_hash_lookup(struct inst_hashentry **table, ch
|
|||
preventry=&table[idx];
|
||||
while(1) {
|
||||
if( !entry ) { /* empty slot */
|
||||
if(remove == XINSERT || remove == XINSERT_NOREPLACE) { /* insert data */
|
||||
if(what == XINSERT || what == XINSERT_NOREPLACE) { /* insert data */
|
||||
s=sizeof( struct inst_hashentry );
|
||||
entry=(struct inst_hashentry *) my_malloc(425, s);
|
||||
*preventry=entry;
|
||||
|
|
@ -104,13 +104,13 @@ static struct inst_hashentry *inst_hash_lookup(struct inst_hashentry **table, ch
|
|||
return NULL; /* token was not in hash */
|
||||
}
|
||||
if( entry->hash==hashcode && !strcmp(token,entry->token) ) { /* found a matching token */
|
||||
if(remove == XDELETE) { /* remove token from the hash table ... */
|
||||
if(what == XDELETE) { /* remove token from the hash table ... */
|
||||
saveptr=entry->next;
|
||||
my_free(968, &entry->token);
|
||||
my_free(969, &entry);
|
||||
*preventry=saveptr;
|
||||
return NULL;
|
||||
} else if(remove == XINSERT) {
|
||||
} else if(what == XINSERT) {
|
||||
entry->value = value;
|
||||
}
|
||||
/* dbg(1, "inst_hash_lookup(): returning: %s , %d\n", entry->token, entry->value); */
|
||||
|
|
@ -2696,17 +2696,23 @@ int isonlydigit(const char *s)
|
|||
const char *find_nth(const char *str, char sep, int n)
|
||||
{
|
||||
static char *result=NULL;
|
||||
static int result_size = 0;
|
||||
static char empty[]="";
|
||||
int i;
|
||||
int i, len;
|
||||
char *ptr;
|
||||
int count;
|
||||
|
||||
if(!str) {
|
||||
my_free(1062, &result);
|
||||
result_size = 0;
|
||||
return empty;
|
||||
}
|
||||
my_strdup(525, &result, str);
|
||||
if(!result) return empty;
|
||||
len = strlen(str) + 1;
|
||||
if(len > result_size) {
|
||||
result_size = len + CADCHUNKALLOC;
|
||||
my_realloc(138, &result, result_size);
|
||||
}
|
||||
memcpy(result, str, len);
|
||||
for(i=0, count=1, ptr=result; result[i] != 0; i++) {
|
||||
if(result[i]==sep) {
|
||||
result[i]=0;
|
||||
|
|
|
|||
|
|
@ -283,6 +283,7 @@ void global_verilog_netlist(int global) /* netlister driver */
|
|||
|
||||
my_strdup(487, &xctx->sch_path[xctx->currsch+1], xctx->sch_path[xctx->currsch]);
|
||||
my_strcat(496, &xctx->sch_path[xctx->currsch+1], "->netlisting");
|
||||
xctx->sch_path_hash[xctx->currsch+1] = 0;
|
||||
xctx->currsch++;
|
||||
|
||||
dbg(2, "global_verilog_netlist(): last defined symbol=%d\n",xctx->symbols);
|
||||
|
|
|
|||
|
|
@ -335,6 +335,7 @@ void global_vhdl_netlist(int global) /* netlister driver */
|
|||
|
||||
my_strdup(502, &xctx->sch_path[xctx->currsch+1], xctx->sch_path[xctx->currsch]);
|
||||
my_strcat(509, &xctx->sch_path[xctx->currsch+1], "->netlisting");
|
||||
xctx->sch_path_hash[xctx->currsch+1] = 0;
|
||||
xctx->currsch++;
|
||||
|
||||
dbg(2, "global_vhdl_netlist(): last defined symbol=%d\n",xctx->symbols);
|
||||
|
|
|
|||
|
|
@ -466,7 +466,10 @@ void alloc_xschem_data()
|
|||
xctx->hilight_nets = 0;
|
||||
xctx->hilight_color = 0;
|
||||
xctx->rectcolor = 0;
|
||||
for(i=0;i<CADMAXHIER;i++) xctx->sch_path[i]=NULL;
|
||||
for(i=0;i<CADMAXHIER;i++) {
|
||||
xctx->sch_path[i]=NULL;
|
||||
xctx->sch_path_hash[i]=0;
|
||||
}
|
||||
my_strdup(1187, &xctx->sch_path[0],".");
|
||||
xctx->sch_inst_number[0] = 1;
|
||||
xctx->maxt=CADMAXTEXT;
|
||||
|
|
|
|||
|
|
@ -324,7 +324,7 @@ do { \
|
|||
*size = __str_alloc_tmp__ + CADCHUNKALLOC; \
|
||||
my_realloc(1212, dest_string, *size); \
|
||||
} \
|
||||
} while(0) \
|
||||
} while(0)
|
||||
|
||||
#define INT_WIDTH(x) ( (int)(x) == 0 ? 1 : (int)(x) )
|
||||
#define INT_BUS_WIDTH(x) ( (int)( (BUS_WIDTH) * (x) ) == 0 ? 1 : (int)( (BUS_WIDTH) * (x) ) )
|
||||
|
|
@ -529,6 +529,7 @@ typedef struct {
|
|||
char current_name[PATH_MAX];
|
||||
char file_version[100];
|
||||
char *sch_path[CADMAXHIER];
|
||||
int sch_path_hash[CADMAXHIER];
|
||||
int sch_inst_number[CADMAXHIER];
|
||||
int previous_instance[CADMAXHIER]; /* to remember the instance we came from when going up the hier. */
|
||||
Zoom zoom_array[CADMAXHIER];
|
||||
|
|
|
|||
Loading…
Reference in New Issue