Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

main: make the implementation of --list-languages=_CATEGORY efficient #4047

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions main/parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@
is set here if this parser is OLDLANG.
LANG_IGNORE is set if no being pretended. */

enum parserCategory category; /* Used when --languages=_CATEGORY is specified. */

parserDefinitionFunc *parserDefFunc; /* Used when --languages=_CATEGORY
is specified. */
} parserObject;

/*
Expand Down Expand Up @@ -1974,7 +1974,7 @@

/* Used in both builtin and optlib parsers. */
static void initializeParsingCommon (parserDefinition *def, bool is_builtin,
enum parserCategory category)
parserDefinitionFunc* parserDefFunc)
{
parserObject *parser;

Expand All @@ -1986,7 +1986,7 @@
def->id = LanguageCount++;
parser = LanguageTable + def->id;
parser->def = def;
parser->category = category;
parser->parserDefFunc = parserDefFunc;

hashTablePutItem (LanguageHTable, def->name, def);

Expand Down Expand Up @@ -2061,7 +2061,6 @@
verbose ("Installing parsers: ");
for (i = 0 ; i < builtInCount ; ++i)
{
enum parserCategory category = getCategoryForParserFunc(BuiltInParsers [i]);
parserDefinition* const def = (*BuiltInParsers [i]) ();
if (def != NULL)
{
Expand All @@ -2076,7 +2075,7 @@
/* parser definition must define one and only one parsing routine */
Assert ((!!def->parser) + (!!def->parser2) == 1);

initializeParsingCommon (def, true, category);
initializeParsingCommon (def, true, BuiltInParsers [i]);
}
}
verbose ("\n");
Expand Down Expand Up @@ -2450,7 +2449,7 @@
def->versionCurrent = data.versionCurrent;
def->versionAge = data.versionAge;

initializeParsingCommon (def, false, PARSER_CATEGORY_NONE);
initializeParsingCommon (def, false, NULL);
linkDependenciesAtInitializeParsing (def);

LanguageTable [def->id].currentPatterns = stringListNew ();
Expand Down Expand Up @@ -3911,12 +3910,13 @@
ltable = xMalloc (LanguageCount, parserDefinition*);
for (i = 0, n = 0 ; i < LanguageCount ; ++i)
{
parserObject *pobj = LanguageTable + i;
if (category != PARSER_CATEGORY_NONE)
{
if (LanguageTable[i].category != category)
if (getCategoryForParserFunc(pobj->parserDefFunc) != category)

Check warning on line 3916 in main/parse.c

View check run for this annotation

Codecov / codecov/patch

main/parse.c#L3916

Added line #L3916 was not covered by tests
continue;
}
ltable[n] = LanguageTable[i].def;
ltable[n] = pobj->def;
++n;
}
qsort (ltable, n, sizeof (parserDefinition*), compareParsersByName);
Expand Down
Loading