Commit 283d7c9e authored by Olly Betts's avatar Olly Betts
Browse files

[go] Optimise setlimit tomark AE for ...

All uses of setlimit in the current stemmers we ship follow this
pattern, and by special-casing we can avoid having to save and restore
the cursor.

Addresses https://github.com/snowballstem/snowball/issues/74 for Go.
parent cf54a0e3
......@@ -780,19 +780,32 @@ static void generate_setlimit(struct generator * g, struct node * p) {
struct str * savevar = vars_newname(g);
struct str * varname = vars_newname(g);
write_comment(g, p);
write_savecursor(g, p, savevar);
generate(g, p->left);
if (p->left && p->left->type == c_tomark && !p->left->right) {
/* Special case for:
*
* setlimit tomark AE for C
*
* All uses of setlimit in the current stemmers we ship follow this
* pattern, and by special-casing we can avoid having to save and
* restore c.
*/
struct node * q = p->left;
g->S[0] = q->mode == m_forward ? ">" : "<";
w(g, "~Mif env.Cursor ~S0 "); generate_AE(g, q->AE); w(g, " ");
write_block_start(g);
write_failure(g);
write_block_end(g);
g->unreachable = false;
if (!g->unreachable) {
g->B[0] = str_data(varname);
if (p->mode == m_forward) {
w(g, "~Mvar ~B0 = env.Limit - env.Cursor~N");
w(g, "~Menv.Limit = env.Cursor~N");
w(g, "~Menv.Limit = ");
} else {
w(g, "~Mvar ~B0 = env.LimitBackward~N");
w(g, "~Menv.LimitBackward = env.Cursor~N");
w(g, "~Menv.LimitBackward = ");
}
write_restorecursor(g, p, savevar);
generate_AE(g, q->AE); writef(g, ";~N", q);
if (p->mode == m_forward) {
str_assign(g->failure_str, "env.Limit += ");
......@@ -803,7 +816,34 @@ static void generate_setlimit(struct generator * g, struct node * p) {
str_append(g->failure_str, varname);
str_append_string(g->failure_str, ";");
}
} else {
write_savecursor(g, p, savevar);
generate(g, p->left);
if (!g->unreachable) {
g->B[0] = str_data(varname);
if (p->mode == m_forward) {
w(g, "~Mvar ~B0 = env.Limit - env.Cursor~N");
w(g, "~Menv.Limit = env.Cursor~N");
} else {
w(g, "~Mvar ~B0 = env.LimitBackward~N");
w(g, "~Menv.LimitBackward = env.Cursor~N");
}
write_restorecursor(g, p, savevar);
if (p->mode == m_forward) {
str_assign(g->failure_str, "env.Limit += ");
str_append(g->failure_str, varname);
str_append_string(g->failure_str, ";");
} else {
str_assign(g->failure_str, "env.LimitBackward = ");
str_append(g->failure_str, varname);
str_append_string(g->failure_str, ";");
}
}
}
if (!g->unreachable) {
generate(g, p->aux);
if (!g->unreachable) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment