eliminated some redundant operations on instance flags (set_inst_flags() does the job)

This commit is contained in:
stefan schippers 2023-12-07 18:07:42 +01:00
parent 8c81f629d0
commit a0237b59b3
7 changed files with 74 additions and 44 deletions

View File

@ -1504,7 +1504,7 @@ int place_symbol(int pos, const char *symbol_name, double x, double y, short rot
xctx->inst[n].instname=NULL;
dbg(1, "place_symbol() :all inst_ptr members set\n"); /* 03-02-2000 */
if(inst_props) {
new_prop_string(n, inst_props,!first_call, tclgetboolvar("disable_unique_names")); /* 20171214 first_call */
new_prop_string(n, inst_props, tclgetboolvar("disable_unique_names")); /* 20171214 first_call */
}
else {
set_inst_prop(n); /* no props, get from sym template, also calls new_prop_string() */

View File

@ -682,7 +682,7 @@ void set_inst_prop(int i)
my_strdup(_ALLOC_ID_, &xctx->inst[i].prop_ptr, ptr);
if(get_tok_value(ptr, "name",0)[0]) {
my_strdup(_ALLOC_ID_, &tmp, xctx->inst[i].prop_ptr);
new_prop_string(i, tmp, 0, tclgetboolvar("disable_unique_names")); /* sets also inst[].instname */
new_prop_string(i, tmp, tclgetboolvar("disable_unique_names")); /* sets also inst[].instname */
my_free(_ALLOC_ID_, &tmp);
}
}
@ -1306,8 +1306,7 @@ static int update_symbol(const char *result, int x, int selected_inst)
int prefix=0, old_prefix = 0;
char *name = NULL, *ptr = NULL, *new_prop = NULL;
char symbol[PATH_MAX], *translated_sym = NULL, *old_translated_sym = NULL;
char *type;
int cond, changed_symbol = 0;
int changed_symbol = 0;
int pushed=0;
int *ii = &xctx->edit_sym_i; /* static var */
int *netl_com = &xctx->netlist_commands; /* static var */
@ -1357,7 +1356,6 @@ static int update_symbol(const char *result, int x, int selected_inst)
/* 20171220 calculate bbox before changes to correctly redraw areas */
/* must be recalculated as cairo text extents vary with zoom factor. */
symbol_bbox(*ii, &xctx->inst[*ii].x1, &xctx->inst[*ii].y1, &xctx->inst[*ii].x2, &xctx->inst[*ii].y2);
my_strdup2(_ALLOC_ID_, &old_translated_sym, translate(*ii, xctx->inst[*ii].name));
/* update property string from tcl dialog */
if(!no_change_props)
@ -1391,6 +1389,7 @@ static int update_symbol(const char *result, int x, int selected_inst)
* to use for inst name (from symbol template) */
prefix = 0;
sym_number = -1;
my_strdup2(_ALLOC_ID_, &old_translated_sym, translate(*ii, xctx->inst[*ii].name));
my_strdup2(_ALLOC_ID_, &translated_sym, translate(*ii, symbol));
dbg(1, "update_symbol: %s -- %s\n", translated_sym, old_translated_sym);
if(changed_symbol ||
@ -1430,21 +1429,12 @@ static int update_symbol(const char *result, int x, int selected_inst)
if(!k) hash_names(-1, XINSERT);
hash_names(*ii, XDELETE);
dbg(1, "update_symbol(): delete %s\n", xctx->inst[*ii].instname);
new_prop_string(*ii, ptr, k, /* sets also inst[].instname */
new_prop_string(*ii, ptr, /* sets also inst[].instname */
tclgetboolvar("disable_unique_names")); /* set new prop_ptr */
hash_names(*ii, XINSERT);
dbg(1, "update_symbol(): insert %s\n", xctx->inst[*ii].instname);
}
set_inst_flags(&xctx->inst[*ii]);
/* set cached flags in instances */
type=xctx->sym[xctx->inst[*ii].ptr].type;
cond= type && IS_LABEL_SH_OR_PIN(type);
if(cond) {
xctx->inst[*ii].flags |= PIN_OR_LABEL;
my_strdup2(_ALLOC_ID_, &xctx->inst[*ii].lab,
get_tok_value(xctx->inst[*ii].prop_ptr, "lab",0));
}
else xctx->inst[*ii].flags &= ~PIN_OR_LABEL;
} /* end for(k=0;k<xctx->lastsel; ++k) */
if(pushed) modified = 1;

View File

@ -834,7 +834,8 @@ void copy_objects(int what)
/* the newpropcnt argument is zero for the 1st call and used in */
/* new_prop_string() for cleaning some internal caches. */
if(!newpropcnt) hash_names(-1, XINSERT);
new_prop_string(xctx->instances, xctx->inst[n].prop_ptr,newpropcnt++, /* sets also inst[].instname */
newpropcnt++;
new_prop_string(xctx->instances, xctx->inst[n].prop_ptr, /* sets also inst[].instname */
tclgetboolvar("disable_unique_names"));
hash_names(xctx->instances, XINSERT);
symbol_bbox(xctx->instances,

View File

@ -276,7 +276,7 @@ static void merge_inst(int k,FILE *fd)
my_strdup(_ALLOC_ID_, &xctx->inst[i].prop_ptr, prop_ptr);
set_inst_flags(&xctx->inst[i]);
if(!k) hash_names(-1, XINSERT);
new_prop_string(i, prop_ptr, k, tclgetboolvar("disable_unique_names")); /* will also assign .instname */
new_prop_string(i, prop_ptr, tclgetboolvar("disable_unique_names")); /* will also assign .instname */
/* the final tmp argument is zero for the 1st call and used in */
/* new_prop_string() for cleaning some internal caches. */
hash_names(i, XINSERT);

View File

@ -133,6 +133,62 @@ static void xschem_cmd_help(int argc, const char **argv)
Tcl_ResetResult(interp);
}
#if 0
static void change_symbol(int inst, char *symbol, int pushed, int old_prefix) {
int prefix, sym_number;
char *old_translated_sym = NULL, *translated_sym = NULL, *name = NULL, *ptr = NULL;
/* symbol reference changed? --> sym_number >=0, set prefix to 1st char
* to use for inst name (from symbol template) */
prefix = 0;
sym_number = -1;
my_strdup2(_ALLOC_ID_, &old_translated_sym, translate(inst, xctx->inst[inst].name));
my_strdup2(_ALLOC_ID_, &translated_sym, translate(inst, symbol));
dbg(1, "update_symbol: %s -- %s\n", translated_sym, old_translated_sym);
if( (!strcmp(symbol, xctx->inst[inst].name) && strcmp(translated_sym, old_translated_sym) ) ) {
sym_number=match_symbol(translated_sym); /* check if exist */
if(sym_number>=0) {
prefix=(get_tok_value((xctx->sym+sym_number)->templ, "name",0))[0]; /* get new symbol prefix */
}
}
if(sym_number>=0) /* changing symbol ! */
{
if(!pushed) { xctx->push_undo(); pushed=1;}
delete_inst_node(inst); /* 20180208 fix crashing bug: delete node info if changing symbol */
/* if number of pins is different we must delete these data *before* */
/* changing ysmbol, otherwise inst might end up deleting non allocated data. */
my_strdup2(_ALLOC_ID_, &xctx->inst[inst].name, rel_sym_path(symbol));
xctx->inst[inst].ptr=sym_number; /* update instance to point to new symbol */
}
my_free(_ALLOC_ID_, &translated_sym);
my_free(_ALLOC_ID_, &old_translated_sym);
/* if symbol changed ensure instance name (with new prefix char) is unique */
/* preserve backslashes in name ---------0---------------------------------->. */
my_strdup(_ALLOC_ID_, &name, get_tok_value(xctx->inst[inst].prop_ptr, "name", 1));
if(name && name[0] ) {
dbg(1, "update_symbol(): prefix!='\\0', name=%s\n", name);
/* change prefix if changing symbol type; */
if(prefix && old_prefix && old_prefix != prefix) {
name[0]=(char)prefix;
my_strdup(_ALLOC_ID_, &ptr, subst_token(xctx->inst[inst].prop_ptr, "name", name) );
} else {
my_strdup(_ALLOC_ID_, &ptr, xctx->inst[inst].prop_ptr);
}
/* set unique name of current inst */
if(!pushed) { xctx->push_undo(); pushed=1;}
hash_names(-1, XINSERT);
hash_names(inst, XDELETE);
dbg(1, "update_symbol(): delete %s\n", xctx->inst[inst].instname);
new_prop_string(inst, ptr, /* sets also inst[].instname */
tclgetboolvar("disable_unique_names")); /* set new prop_ptr */
hash_names(inst, XINSERT);
dbg(1, "update_symbol(): insert %s\n", xctx->inst[inst].instname);
}
set_inst_flags(&xctx->inst[inst]);
}
#endif
/* can be used to reach C functions from the Tk shell. */
int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * argv[])
{
@ -3556,8 +3612,7 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg
return TCL_ERROR;
} else {
char symbol[PATH_MAX];
int sym_number, prefix, cond;
char *type;
int sym_number, prefix;
char *name=NULL;
char *ptr=NULL;
char *sym = NULL;
@ -3589,18 +3644,10 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg
my_strdup(_ALLOC_ID_, &ptr,subst_token(xctx->inst[inst].prop_ptr, "name", name) );
if(!fast) hash_names(-1, XINSERT);
hash_names(inst, XDELETE);
new_prop_string(inst, ptr, fast, /* sets also inst[].instname */
new_prop_string(inst, ptr, /* sets also inst[].instname */
tclgetboolvar("disable_unique_names")); /* set new prop_ptr */
hash_names(inst, XINSERT);
type=xctx->sym[xctx->inst[inst].ptr].type;
cond= type && IS_LABEL_SH_OR_PIN(type);
if(cond) {
xctx->inst[inst].flags |= PIN_OR_LABEL;
my_strdup2(_ALLOC_ID_, &xctx->inst[inst].lab, get_tok_value(xctx->inst[inst].prop_ptr, "lab", 0));
}
else xctx->inst[inst].flags &= ~PIN_OR_LABEL;
xctx->inst[inst].embed = !strboolcmp(get_tok_value(xctx->inst[inst].prop_ptr, "embed", 2), "true");
set_inst_flags(&xctx->inst[inst]);
my_free(_ALLOC_ID_, &ptr);
}
my_free(_ALLOC_ID_, &name);
@ -4355,8 +4402,7 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg
Tcl_SetResult(interp, "xschem setprop: instance not found", TCL_STATIC);
return TCL_ERROR;
} else {
char *type;
int floaters = 0, cond;
int floaters = 0;
char *subst = NULL;
int s_pnetname = tclgetboolvar("show_pin_net_names");
floaters = set_modify(1);
@ -4378,18 +4424,10 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg
my_strdup2(_ALLOC_ID_, &subst, subst_token(xctx->inst[inst].prop_ptr, argv[4], NULL));
}
hash_names(inst, XDELETE);
new_prop_string(inst, subst, fast, tclgetboolvar("disable_unique_names"));
new_prop_string(inst, subst, tclgetboolvar("disable_unique_names"));
my_free(_ALLOC_ID_, &subst);
set_inst_flags(&xctx->inst[inst]);
hash_names(inst, XINSERT);
type=xctx->sym[xctx->inst[inst].ptr].type;
cond= type && IS_LABEL_SH_OR_PIN(type);
if(cond) {
xctx->inst[inst].flags |= PIN_OR_LABEL;
my_strdup2(_ALLOC_ID_, &xctx->inst[inst].lab, get_tok_value(xctx->inst[inst].prop_ptr, "lab", 0));
}
else xctx->inst[inst].flags &= ~PIN_OR_LABEL;
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

@ -740,7 +740,7 @@ static int name_is_used(char *name, const char *old_basename, const char *brkt,
* if old_prop=NULL return NULL
* if old_prop does not contain a valid "name" or empty return old_prop
* hash_names(-1, XINSERT) must be called before using this function */
void new_prop_string(int i, const char *old_prop, int fast, int dis_uniq_names)
void new_prop_string(int i, const char *old_prop, int dis_uniq_names)
{
char *old_name=NULL, *new_name=NULL;
const char *brkt;
@ -751,7 +751,7 @@ void new_prop_string(int i, const char *old_prop, int fast, int dis_uniq_names)
char *up_new_name = NULL;
int is_used;
dbg(1, "new_prop_string(): i=%d, old_prop=%s, fast=%d\n", i, old_prop, fast);
dbg(1, "new_prop_string(): i=%d, old_prop=%s\n", i, old_prop);
if(old_prop==NULL) {
my_free(_ALLOC_ID_, &xctx->inst[i].prop_ptr);
return;
@ -847,7 +847,8 @@ void check_unique_names(int rename)
if(rename) for(i=0;i<xctx->instances; ++i) {
if( (xctx->inst[i].color != -10000)) {
my_strdup(_ALLOC_ID_, &tmp, xctx->inst[i].prop_ptr);
new_prop_string(i, tmp, newpropcnt++, 0);
newpropcnt++;
new_prop_string(i, tmp, 0);
hash_names(i, XINSERT);
symbol_bbox(i, &xctx->inst[i].x1, &xctx->inst[i].y1, &xctx->inst[i].x2, &xctx->inst[i].y2);
bbox(ADD, xctx->inst[i].x1, xctx->inst[i].y1, xctx->inst[i].x2, xctx->inst[i].y2);

View File

@ -1593,7 +1593,7 @@ extern int count_lines_bytes(int fd, size_t *lines, size_t *bytes);
extern double my_atod(const char *p);
extern float my_atof(const char *p);
extern const char *subst_token(const char *s, const char *tok, const char *new_val);
extern void new_prop_string(int i, const char *old_prop,int fast, int dis_uniq_names);
extern void new_prop_string(int i, const char *old_prop, int dis_uniq_names);
extern void hash_name(char *token, int remove);
extern void hash_names(int inst, int action); /* if i == -1 hash all instances, else do only inst */
extern void floater_hash_all_names(void);