Skip to content

Commit

Permalink
Merge pull request #147 from Turnerj/static-among-values
Browse files Browse the repository at this point in the history
Basic optimizations for C# stemmer output
  • Loading branch information
ojwb authored Apr 11, 2021
2 parents 6bf75dc + d29ba2e commit 6d609cd
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions compiler/generator_csharp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1186,21 +1186,14 @@ static void generate_class_end(struct generator * g) {
w(g, "~N");
}

static void generate_among_declaration(struct generator * g, struct among * x) {

g->I[0] = x->number;
g->I[1] = x->literalstring_count;

w(g, "~Mprivate readonly Among[] a_~I0;~N");
}

static void generate_among_table(struct generator * g, struct among * x) {
static void generate_among_table(struct generator * g, struct among * x, const char * type) {

struct amongvec * v = x->b;

g->I[0] = x->number;
g->S[0] = type;
w(g, "~M~S0a_~I0 = new[] ~N~M{~N~+");

w(g, "~Ma_~I0 = new[] ~N~M{~N~+");
{
int i;
for (i = 0; i < x->literalstring_count; i++) {
Expand All @@ -1222,24 +1215,35 @@ static void generate_among_table(struct generator * g, struct among * x) {
}

static void generate_amongs(struct generator * g) {
struct among * x;
int amongs_with_functions = 0;
struct among * x = g->analyser->amongs;

/* Generate declarations. */
x = g->analyser->amongs;
while (x != 0) {
generate_among_declaration(g, x);
if (x->function_count) {
g->I[0] = x->number;
g->I[1] = x->literalstring_count;

w(g, "~Mprivate readonly Among[] a_~I0;~N");
++amongs_with_functions;
} else {
generate_among_table(g, x, "private static readonly Among[] ");
}
x = x->next;
}

w(g, "~N");

if (!amongs_with_functions) return;

w(g, "~M/// <summary>~N");
w(g, "~M/// Initializes a new instance of the <see cref=\"~n\"/> class.~N");
w(g, "~M/// </summary>~N");
w(g, "~M/// ~N");
w(g, "~Mpublic ~n()~N~{");
x = g->analyser->amongs;
while (x != 0) {
generate_among_table(g, x);
if (x->function_count) {
generate_among_table(g, x, "");
}
x = x->next;
}

Expand Down

0 comments on commit 6d609cd

Please sign in to comment.