Skip to content

Commit

Permalink
Always parse buffer instead of file
Browse files Browse the repository at this point in the history
This brings the linux kernel parsing time from about 20s to 12s on my machine.
  • Loading branch information
techee committed Nov 5, 2014
1 parent 448f1fd commit 29000cf
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions tagmanager/src/tm_source_file.c
Expand Up @@ -253,15 +253,27 @@ gboolean tm_source_file_parse(TMSourceFile *source_file, guchar* text_buf, gint
g_warning("Attempt to parse NULL file");
return FALSE;
}

file_name = source_file->file_name;

if (!use_buffer)
{
if (!g_file_get_contents(file_name, (gchar**)&text_buf, (gsize*)&buf_size, NULL))
{
g_warning("Unable to open %s", file_name);
return FALSE;
}
}

if (use_buffer && (NULL == text_buf || 0 == buf_size))
if (NULL == text_buf || 0 == buf_size)
{
/* Empty buffer, "parse" by setting empty tag array */
tm_tags_array_free(source_file->tags_array, FALSE);
if (!use_buffer)
g_free(text_buf);
return TRUE;
}

file_name = source_file->file_name;
if (NULL == LanguageTable)
{
initializeParsing();
Expand Down Expand Up @@ -292,7 +304,7 @@ gboolean tm_source_file_parse(TMSourceFile *source_file, guchar* text_buf, gint
while (retry && passCount < 3)
{
tm_tags_array_free(source_file->tags_array, FALSE);
if (use_buffer && bufferOpen (text_buf, buf_size, file_name, source_file->lang))
if (bufferOpen (text_buf, buf_size, file_name, source_file->lang))
{
if (LanguageTable [source_file->lang]->parser != NULL)
{
Expand All @@ -305,19 +317,6 @@ gboolean tm_source_file_parse(TMSourceFile *source_file, guchar* text_buf, gint
retry = LanguageTable [source_file->lang]->parser2 (passCount);
bufferClose ();
}
else if (!use_buffer && fileOpen (file_name, source_file->lang))
{
if (LanguageTable [source_file->lang]->parser != NULL)
{
LanguageTable [source_file->lang]->parser ();
fileClose ();
retry = FALSE;
break;
}
else if (LanguageTable [source_file->lang]->parser2 != NULL)
retry = LanguageTable [source_file->lang]->parser2 (passCount);
fileClose ();
}
else
{
g_warning("Unable to open %s", file_name);
Expand All @@ -326,6 +325,9 @@ gboolean tm_source_file_parse(TMSourceFile *source_file, guchar* text_buf, gint
++ passCount;
}
}

if (!use_buffer)
g_free(text_buf);
return !retry;
}

Expand Down

0 comments on commit 29000cf

Please sign in to comment.