aboutsummaryrefslogtreecommitdiffhomepage
path: root/parser.cpp
diff options
context:
space:
mode:
authorGravatar Jan Kanis <jan.code@jankanis.nl>2013-01-14 00:49:32 +0100
committerGravatar Jan Kanis <jan.code@jankanis.nl>2013-01-14 00:49:32 +0100
commit44f70d2b5219c421ebe1cfaf90b07752a29360fb (patch)
tree32a58ca942b6c32a0e6ed7f12e2b9a6ec3c7b0d9 /parser.cpp
parentacbb6fb8e2a12c9071b9729e4033cdb2a3d39c07 (diff)
stop profile switch from crashing (issue #517); also make print_profile use a loop instead of recursion
Diffstat (limited to 'parser.cpp')
-rw-r--r--parser.cpp95
1 files changed, 46 insertions, 49 deletions
diff --git a/parser.cpp b/parser.cpp
index 76862479..7b762c69 100644
--- a/parser.cpp
+++ b/parser.cpp
@@ -639,72 +639,70 @@ void parser_t::error(int ec, int p, const wchar_t *str, ...)
/**
Print profiling information to the specified stream
*/
-static void print_profile(const std::vector<profile_item_t> &items,
- size_t pos,
+static void print_profile(const std::vector<profile_item_t*> &items,
FILE *out)
{
- const profile_item_t *me, *prev;
- size_t i;
- int my_time;
-
- if (pos >= items.size())
- {
- return;
- }
-
- me= &items.at(pos);
- if (!me->skipped)
+ size_t pos;
+ for (pos = 0; pos < items.size(); pos++)
{
- my_time=me->parse+me->exec;
+ const profile_item_t *me, *prev;
+ size_t i;
+ int my_time;
- for (i=pos+1; i<items.size(); i++)
+ me = items.at(pos);
+ if (!me->skipped)
{
- prev = &items.at(i);
- if (prev->skipped)
- {
- continue;
- }
+ my_time=me->parse+me->exec;
- if (prev->level <= me->level)
+ for (i=pos+1; i<items.size(); i++)
{
- break;
- }
+ prev = items.at(i);
+ if (prev->skipped)
+ {
+ continue;
+ }
- if (prev->level > me->level+1)
- {
- continue;
- }
+ if (prev->level <= me->level)
+ {
+ break;
+ }
- my_time -= prev->parse;
- my_time -= prev->exec;
- }
+ if (prev->level > me->level+1)
+ {
+ continue;
+ }
- if (me->cmd.size() > 0)
- {
- if (fwprintf(out, L"%d\t%d\t", my_time, me->parse+me->exec) < 0)
- {
- wperror(L"fwprintf");
- return;
+ my_time -= prev->parse;
+ my_time -= prev->exec;
}
- for (i=0; i<me->level; i++)
+ if (me->cmd.size() > 0)
{
- if (fwprintf(out, L"-") < 0)
+ if (fwprintf(out, L"%d\t%d\t", my_time, me->parse+me->exec) < 0)
{
wperror(L"fwprintf");
return;
}
- }
- if (fwprintf(out, L"> %ls\n", me->cmd.c_str()) < 0)
- {
- wperror(L"fwprintf");
- return;
- }
+ for (i=0; i<me->level; i++)
+ {
+ if (fwprintf(out, L"-") < 0)
+ {
+ wperror(L"fwprintf");
+ return;
+ }
+ }
+ if (fwprintf(out, L"> %ls\n", me->cmd.c_str()) < 0)
+ {
+ wperror(L"fwprintf");
+ return;
+ }
+
+ }
+ delete me;
}
}
- print_profile(items, pos+1, out);
}
void parser_t::destroy()
@@ -729,7 +727,7 @@ void parser_t::destroy()
}
else
{
- print_profile(profile_items, 0, f);
+ print_profile(profile_items, f);
}
if (fclose(f))
@@ -2408,10 +2406,9 @@ void parser_t::eval_job(tokenizer_t *tok)
if (do_profile)
{
- profile_items.resize(profile_items.size() + 1);
- profile_item = &profile_items.back();
- profile_item->cmd = L"";
+ profile_item = new profile_item_t();
profile_item->skipped = 1;
+ profile_items.push_back(profile_item);
t1 = get_time();
}