cache embed attribute of instances for faster lookup

This commit is contained in:
Stefan Frederik 2022-10-21 11:04:20 +02:00
parent e34211368f
commit a6dc3d47c3
8 changed files with 31 additions and 48 deletions

View File

@ -1048,14 +1048,9 @@ int place_symbol(int pos, const char *symbol_name, double x, double y, short rot
cond= !type || !IS_LABEL_SH_OR_PIN(type);
if(cond) xctx->inst[n].flags|=2;
else my_strdup(145, &xctx->inst[n].lab, get_tok_value(xctx->inst[n].prop_ptr,"lab",0));
xctx->inst[n].embed = !strcmp(get_tok_value(xctx->inst[n].prop_ptr, "embed", 2), "true");
if(first_call && (draw_sym & 3) ) bbox(START, 0.0 , 0.0 , 0.0 , 0.0);
xctx->instances++; /* must be updated before calling symbol_bbox() */
/* force these vars to 0 to trigger a prepare_netlist_structs(0) needed by symbol_bbox->translate
* to translate @#n:net_name texts */
xctx->prep_net_structs=0;

View File

@ -1225,6 +1225,7 @@ static void update_symbol(const char *result, int x)
if(!strcmp(get_tok_value(xctx->inst[*ii].prop_ptr,"highlight",0), "true"))
xctx->inst[*ii].flags |= HILIGHT_CONN;
else xctx->inst[*ii].flags &= ~HILIGHT_CONN;
xctx->inst[*ii].embed = !strcmp(get_tok_value(xctx->inst[*ii].prop_ptr, "embed", 2), "true");
} /* end for(k=0;k<xctx->lastsel;k++) */
/* new symbol bbox after prop changes (may change due to text length) */
if(xctx->modified) {

View File

@ -985,6 +985,7 @@ void copy_objects(int what)
xctx->inst[xctx->instances].instname = NULL; /* will be set in new_prop_string() */
my_strdup(312, &xctx->inst[xctx->instances].lab, xctx->inst[n].lab);
xctx->inst[n].sel=0;
xctx->inst[xctx->instances].embed = xctx->inst[n].embed;
xctx->inst[xctx->instances].flags = xctx->inst[n].flags;
xctx->inst[xctx->instances].color = -10000;
xctx->inst[xctx->instances].x0 = xctx->rx1+xctx->deltax;

View File

@ -300,7 +300,7 @@ static void merge_inst(int k,FILE *fd)
/* new_prop_string() for cleaning some internal caches. */
if(!strcmp(get_tok_value(xctx->inst[i].prop_ptr,"highlight",0), "true"))
xctx->inst[i].flags |= HILIGHT_CONN;
xctx->inst[i].embed = !strcmp(get_tok_value(xctx->inst[i].prop_ptr, "embed", 2), "true");
my_free(871, &prop_ptr);
xctx->instances++;
set_modify(1);

View File

@ -1349,35 +1349,33 @@ static void save_embedded_symbol(xSymbol *s, FILE *fd)
static void save_inst(FILE *fd, int select_only)
{
int i, oldversion;
xInstance *ptr;
xInstance *inst;
char *tmp = NULL;
int *embedded_saved = NULL;
ptr=xctx->inst;
inst=xctx->inst;
oldversion = !strcmp(xctx->file_version, "1.0");
for(i=0;i<xctx->symbols;i++) xctx->sym[i].flags &=~EMBEDDED;
embedded_saved = my_calloc(663, xctx->symbols, sizeof(int));
for(i=0;i<xctx->instances;i++)
{
if (select_only && ptr[i].sel != SELECTED) continue;
if (select_only && inst[i].sel != SELECTED) continue;
fputs("C ", fd);
if(oldversion) {
my_strdup2(57, &tmp, add_ext(ptr[i].name, ".sym"));
my_strdup2(57, &tmp, add_ext(inst[i].name, ".sym"));
save_ascii_string(tmp, fd, 0);
my_free(882, &tmp);
} else {
save_ascii_string(ptr[i].name, fd, 0);
save_ascii_string(inst[i].name, fd, 0);
}
fprintf(fd, " %.16g %.16g %hd %hd ",ptr[i].x0, ptr[i].y0, ptr[i].rot, ptr[i].flip );
save_ascii_string(ptr[i].prop_ptr,fd, 1);
if( embedded_saved && !embedded_saved[ptr[i].ptr] &&
!strcmp(get_tok_value(ptr[i].prop_ptr, "embed", 0), "true") ) {
/* && !(xctx->sym[ptr[i].ptr].flags & EMBEDDED)) { */
embedded_saved[ptr[i].ptr] = 1;
fprintf(fd, " %.16g %.16g %hd %hd ",inst[i].x0, inst[i].y0, inst[i].rot, inst[i].flip );
save_ascii_string(inst[i].prop_ptr,fd, 1);
if( embedded_saved && !embedded_saved[inst[i].ptr] && inst[i].embed) {
embedded_saved[inst[i].ptr] = 1;
fprintf(fd, "[\n");
save_embedded_symbol( xctx->sym+ptr[i].ptr, fd);
save_embedded_symbol( xctx->sym+inst[i].ptr, fd);
fprintf(fd, "]\n");
xctx->sym[ptr[i].ptr].flags |= EMBEDDED;
xctx->sym[inst[i].ptr].flags |= EMBEDDED;
}
}
my_free(539, &embedded_saved);
@ -1651,6 +1649,7 @@ static void load_inst(int k, FILE *fd)
dbg(2, "load_inst(): n=%d name=%s prop=%s\n", i, xctx->inst[i].name? xctx->inst[i].name:"<NULL>",
xctx->inst[i].prop_ptr? xctx->inst[i].prop_ptr:"<NULL>");
xctx->inst[i].embed = !strcmp(get_tok_value(xctx->inst[i].prop_ptr, "embed", 2), "true");
xctx->instances++;
}
my_free(885, &prop_ptr);
@ -3622,8 +3621,7 @@ void descend_symbol(void)
xctx->zoom_array[xctx->currsch].y=xctx->yorigin;
xctx->zoom_array[xctx->currsch].zoom=xctx->zoom;
++xctx->currsch;
if((xctx->inst[n].ptr+ xctx->sym)->flags & EMBEDDED ||
!strcmp(get_tok_value(xctx->inst[n].prop_ptr,"embed", 0), "true")) {
if((xctx->inst[n].ptr+ xctx->sym)->flags & EMBEDDED || xctx->inst[n].embed) {
/* save embedded symbol into a temporary file */
my_snprintf(name_embedded, S(name_embedded),
"%s/.xschem_embedded_%d_%s", tclgetvar("XSCHEM_TMP_DIR"), getpid(), get_cell_w_ext(name, 0));

View File

@ -2298,6 +2298,7 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg
xctx->inst[inst].flags &=~2;
my_strdup(872, &xctx->inst[inst].lab, get_tok_value(xctx->inst[inst].prop_ptr, "lab", 0));
}
xctx->inst[inst].embed = !strcmp(get_tok_value(xctx->inst[inst].prop_ptr, "embed", 2), "true");
my_free(922, &ptr);
}
my_free(923, &name);
@ -2635,6 +2636,7 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg
xctx->inst[inst].flags &=~2;
my_strdup(1215, &xctx->inst[inst].lab, get_tok_value(xctx->inst[inst].prop_ptr, "lab", 0));
}
xctx->inst[inst].embed = !strcmp(get_tok_value(xctx->inst[inst].prop_ptr, "embed", 2), "true");
if(!fast) {
/* new symbol bbox after prop changes (may change due to text length) */
symbol_bbox(inst, &xctx->inst[inst].x1, &xctx->inst[inst].y1, &xctx->inst[inst].x2, &xctx->inst[inst].y2);

View File

@ -372,7 +372,7 @@ const char *get_tok_value(const char *s,const char *tok, int with_quotes)
}
return "";
}
/* dbg(2, "get_tok_value(): looking for <%s> in <%s>\n",tok,s); */
/* dbg(0, "get_tok_value(): looking for <%s> in <%.30s>\n",tok,s); */
if( size == 0 ) {
sizetok = size = CADCHUNKALLOC;
my_realloc(454, &result, size);
@ -3396,17 +3396,11 @@ const char *translate2(Lcc *lcc, int level, char* s)
{
static const char *empty="";
static char *result = NULL;
int i;
size_t save_tok_size, size = 0;
size_t tmp;
int i, escape = 0;
register int c, state = TOK_BEGIN, space;
char *token = NULL;
const char *tmp_sym_name;
size_t sizetok = 0;
size_t result_pos = 0, token_pos = 0;
char *value = NULL;
char *value2 = NULL;
int escape = 0;
size_t sizetok = 0, result_pos = 0, token_pos = 0, size = 0, tmp = 0;
char *token = NULL, *value = NULL;
if(!s) {
my_free(1068, &result);
@ -3453,14 +3447,11 @@ const char *translate2(Lcc *lcc, int level, char* s)
i = level;
/* recursive substitution of value using parent level prop_str attributes */
while(i > 1) {
save_tok_size = xctx->tok_size;
my_strdup2(440, &value2, get_tok_value(lcc[i-1].prop_ptr, value, 0));
dbg(1, "translate2(): lcc[%d].prop_ptr=%s value2=%s\n", i-1, lcc[i-1].prop_ptr, value2);
if(xctx->tok_size && value2[0]) {
my_strdup2(1615, &value, value2);
const char *upperval = get_tok_value(lcc[i-1].prop_ptr, value, 0);
dbg(1, "translate2(): lcc[%d].prop_ptr=%s upperval=%s\n", i-1, lcc[i-1].prop_ptr, upperval);
if(xctx->tok_size && upperval[0]) {
my_strdup2(1615, &value, upperval);
} else {
/* restore last successful get_tok_value() size parameters */
xctx->tok_size = save_tok_size;
break;
}
i--;
@ -3474,13 +3465,8 @@ const char *translate2(Lcc *lcc, int level, char* s)
memcpy(result + result_pos + 1 , value, tmp + 1);
result_pos += tmp + 1;
}
else if (strncmp(token, "@spice_get_voltage", 18) == 0) { /* return unchanged */
tmp = strlen(token);
STR_ALLOC(&result, tmp + result_pos, &size);
memcpy(result + result_pos, token, tmp + 1);
result_pos += tmp;
}
else if (strncmp(token, "@spice_get_current", 18) == 0) { /* return unchanged */
else if (strncmp(token, "@spice_get_voltage", 18) == 0 ||
strncmp(token, "@spice_get_current", 18) == 0) { /* return unchanged */
tmp = strlen(token);
STR_ALLOC(&result, tmp + result_pos, &size);
memcpy(result + result_pos, token, tmp + 1);
@ -3500,7 +3486,7 @@ const char *translate2(Lcc *lcc, int level, char* s)
memcpy(result + result_pos, tmp_sym_name, tmp + 1);
result_pos += tmp;
}
if (c == '@') s--;
if (c == '@') s--; /* push back to input for next token */
else result[result_pos++] = (char)c;
state = TOK_BEGIN;
}
@ -3512,7 +3498,6 @@ const char *translate2(Lcc *lcc, int level, char* s)
} /* while(1) */
my_free(1532, &token);
my_free(1533, &value);
my_free(1071, &value2);
dbg(1, "translate2(): result=%s\n", result);
return tcl_hook2(&result);
}

View File

@ -511,6 +511,7 @@ typedef struct
short rot;
short flip;
short sel;
short embed; /* cache embed=true|false attribute in prop_ptr */
int color; /* hilight color */
short flags; /* bit 0: skip field,
* bit 1: flag for different textlayer for pin/labels,