Skip to content

Commit

Permalink
r6264: Save namepos with constraint
Browse files Browse the repository at this point in the history
Need to call `next_constr_namepos` function only once for each
constraint.
  • Loading branch information
coldfix committed Jun 26, 2017
1 parent 0dea93a commit 345bd86
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
27 changes: 15 additions & 12 deletions src/mad_const.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ grow_constraint_list(struct constraint_list* p)
}

static struct constraint*
make_constraint(int type, struct command_parameter* par)
make_constraint(int type, int find_npos, struct command_parameter* par)
/* makes + stores a constraint from command parameter */
{
struct constraint* new = new_constraint(par->c_type);
Expand Down Expand Up @@ -56,6 +56,17 @@ make_constraint(int type, struct command_parameter* par)
}
if (type == 1) new->weight = command_par_value(new->name, current_weight);
else new->weight = command_par_value(new->name, current_gweight);

new->n_pos = find_npos ? next_constr_namepos(new->name) : 0;
if (find_npos && new->n_pos == 0) {
fatal_error(
" +-+-+- fatal error\n"
"match - collect: illegal name\n"
" - try with the \"slow\" option\n"
" - name = ", new->name
);
}

return new;
}

Expand Down Expand Up @@ -150,12 +161,12 @@ fill_constraint_list(int type /* 1 node, 2 global */,
struct command_parameter_list* pl = cd->par;
struct name_list* nl = cd->par_names;
struct constraint* l_cons;
int j;
int j, find_npos = type == 1 && !get_option("slow");
for (j = 0; j < pl->curr; j++)
{
if (nl->inform[j] && pl->parameters[j]->type == 4)
{
l_cons = make_constraint(type, pl->parameters[j]);
l_cons = make_constraint(type, find_npos, pl->parameters[j]);
add_to_constraint_list(l_cons, cl);
}
}
Expand Down Expand Up @@ -253,15 +264,7 @@ next_constraint(char* name, int* name_l, int* type, double* value,
double_from_table_row("twiss ", name, pos, val);
}
else {
int n_pos = next_constr_namepos(name);
if (n_pos == 0)
fatal_error(
" +-+-+- fatal error\n"
"match - collect: illegal name\n"
" - try with the \"slow\" option\n"
" - name = ", name
);
*val = current_node->match_data[n_pos-1];
*val = current_node->match_data[c_c->n_pos-1];
current_node_name(node_name, nn_len);
}

Expand Down
1 change: 1 addition & 0 deletions src/mad_const.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ struct constraint /* contains one constraint */
/* 3 both 1 + 2 */
/* 4 value */
int stamp;
int n_pos;
double value, c_min, c_max, weight;
struct expression *ex_value, *ex_c_min, *ex_c_max;
};
Expand Down

0 comments on commit 345bd86

Please sign in to comment.