• R/O
  • SSH
  • HTTPS

yash: Commit


Commit MetaInfo

Revision3892 (tree)
Time2018-09-23 17:00:19
Authormagicant

Log Message

parser: Reorder result construction

Allocate the results later for locality.

Change Summary

Incremental Difference

--- yash/trunk/parser.c (revision 3891)
+++ yash/trunk/parser.c (revision 3892)
@@ -1220,7 +1220,6 @@
12201220 * If there is no parameter, the position is put back to L'$'. */
12211221 wordunit_T *tryparse_paramexp_raw(parsestate_T *ps)
12221222 {
1223- paramexp_T *pe;
12241223 size_t namelen; /* parameter name length */
12251224
12261225 maybe_line_continuations(ps, ps->index);
@@ -1237,8 +1236,8 @@
12371236 else
12381237 namelen = count_name_length(ps, is_portable_name_char);
12391238
1240-success:
1241- pe = xmalloc(sizeof *pe);
1239+success:;
1240+ paramexp_T *pe = xmalloc(sizeof *pe);
12421241 pe->pe_type = PT_NONE;
12431242 pe->pe_name = xwcsndup(&ps->src.contents[ps->index], namelen);
12441243 pe->pe_start = pe->pe_end = pe->pe_match = pe->pe_subst = NULL;
@@ -1452,10 +1451,7 @@
14521451 */
14531452 wordunit_T *parse_cmdsubst_in_paren(parsestate_T *ps)
14541453 {
1455- wordunit_T *result = xmalloc(sizeof *result);
1456- result->next = NULL;
1457- result->wu_type = WT_CMDSUB;
1458- result->wu_cmdsub = extract_command_in_paren(ps);
1454+ embedcmd_T cmd = extract_command_in_paren(ps);
14591455
14601456 maybe_line_continuations(ps, ps->index);
14611457 if (ps->src.contents[ps->index] == L')')
@@ -1462,6 +1458,11 @@
14621458 ps->index++;
14631459 else
14641460 serror(ps, Ngt("`%ls' is missing"), L")");
1461+
1462+ wordunit_T *result = xmalloc(sizeof *result);
1463+ result->next = NULL;
1464+ result->wu_type = WT_CMDSUB;
1465+ result->wu_cmdsub = cmd;
14651466 return result;
14661467 }
14671468
@@ -1523,13 +1524,9 @@
15231524 * are left intact. */
15241525 wordunit_T *parse_cmdsubst_in_backquote(parsestate_T *ps, bool bsbq)
15251526 {
1527+ assert(ps->src.contents[ps->index - 1] == L'`');
1528+
15261529 xwcsbuf_T buf;
1527- wordunit_T *result = xmalloc(sizeof *result);
1528- result->next = NULL;
1529- result->wu_type = WT_CMDSUB;
1530- result->wu_cmdsub.is_preparsed = false;
1531-
1532- assert(ps->src.contents[ps->index - 1] == L'`');
15331530 wb_init(&buf);
15341531 for (;;) {
15351532 maybe_line_continuations(ps, ps->index);
@@ -1563,7 +1560,11 @@
15631560 break;
15641561 }
15651562 }
1566-end:
1563+end:;
1564+ wordunit_T *result = xmalloc(sizeof *result);
1565+ result->next = NULL;
1566+ result->wu_type = WT_CMDSUB;
1567+ result->wu_cmdsub.is_preparsed = false;
15671568 result->wu_cmdsub.value.unparsed = wb_towcs(&buf);
15681569 return result;
15691570 }
@@ -2317,14 +2318,10 @@
23172318 }
23182319 next_token(ps);
23192320
2320- command_T *result = xmalloc(sizeof *result);
2321- result->next = NULL;
2322- result->refcount = 1;
2323- result->c_type = type;
2324- result->c_lineno = ps->info->lineno;
2325- result->c_redirs = NULL;
2326- result->c_subcmds = parse_compound_list(ps);
2327- if (posixly_correct && result->c_subcmds == NULL)
2321+ unsigned long lineno = ps->info->lineno;
2322+ and_or_T *cmd = parse_compound_list(ps);
2323+
2324+ if (posixly_correct && cmd == NULL)
23282325 serror(ps, Ngt("commands are missing between `%ls' and `%ls'"),
23292326 starts, ends);
23302327 if (ps->tokentype == endtt)
@@ -2331,6 +2328,14 @@
23312328 next_token(ps);
23322329 else
23332330 print_errmsg_token_missing(ps, ends);
2331+
2332+ command_T *result = xmalloc(sizeof *result);
2333+ result->next = NULL;
2334+ result->refcount = 1;
2335+ result->c_type = type;
2336+ result->c_lineno = lineno;
2337+ result->c_redirs = NULL;
2338+ result->c_subcmds = cmd;
23342339 return result;
23352340 }
23362341
Show on old repository browser