Commit e1764ed9 authored by Olly Betts's avatar Olly Betts
Browse files

[java] 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
Java.
parent 3f5d84b6
......@@ -763,6 +763,43 @@ 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);
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 (cursor ~S0 "); generate_AE(g, q->AE); w(g, ")~N");
write_block_start(g);
write_failure(g);
write_block_end(g);
g->unreachable = false;
g->B[0] = str_data(varname);
if (p->mode == m_forward) {
w(g, "~Mint ~B0 = limit - cursor;~N");
w(g, "~Mlimit = ");
} else {
w(g, "~Mint ~B0 = limit_backward;~N");
w(g, "~Mlimit_backward = ");
}
generate_AE(g, q->AE); writef(g, ";~N", q);
if (p->mode == m_forward) {
str_assign(g->failure_str, "limit += ");
str_append(g->failure_str, varname);
str_append_ch(g->failure_str, ';');
} else {
str_assign(g->failure_str, "limit_backward = ");
str_append(g->failure_str, varname);
str_append_ch(g->failure_str, ';');
}
} else {
write_savecursor(g, p, savevar);
generate(g, p->left);
......@@ -786,6 +823,10 @@ static void generate_setlimit(struct generator * g, struct node * p) {
str_append(g->failure_str, varname);
str_append_ch(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