abusalimov

make-perf.patch

Mar 7th, 2012
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 12.43 KB | None | 0 0
  1. ### Eclipse Workspace Patch 1.0
  2. #P make
  3. Index: expand.c
  4. ===================================================================
  5. RCS file: /sources/make/make/expand.c,v
  6. retrieving revision 1.62
  7. diff -u -r1.62 expand.c
  8. --- expand.c    5 Mar 2012 14:10:43 -0000   1.62
  9. +++ expand.c    7 Mar 2012 14:33:25 -0000
  10. @@ -137,7 +137,14 @@
  11.    if (v->append)
  12.      value = allocated_variable_append (v);
  13.    else
  14. -    value = allocated_variable_expand (v->value);
  15. +    {
  16. +      /* We need a copy of STRING: due to eval, it's possible that it will get
  17. +         freed as we process it (it might be the value of a variable that's
  18. +         reset for example). */
  19. +      char *saved_value = xstrdup (v->value);
  20. +      value = allocated_variable_expand (saved_value);
  21. +      free(saved_value);
  22. +    }
  23.    v->expanding = 0;
  24.  
  25.    if (set_reading)
  26. @@ -191,14 +198,17 @@
  27.     NULL.
  28.   */
  29.  char *
  30. -variable_expand_string (char *line, const char *string, long length)
  31. +variable_expand_string (char *line, const char *str, long length)
  32.  {
  33.    struct variable *v;
  34.    const char *p, *p1;
  35. -  char *save;
  36. +//  char *save;
  37. +  char end_ch = 0;
  38.    char *o;
  39.    unsigned int line_offset;
  40.  
  41. +  char *string = (char *) str;
  42. +
  43.    if (!line)
  44.      line = initialize_variable_output();
  45.    o = line;
  46. @@ -213,8 +223,12 @@
  47.    /* We need a copy of STRING: due to eval, it's possible that it will get
  48.       freed as we process it (it might be the value of a variable that's reset
  49.       for example).  Also having a nil-terminated string is handy.  */
  50. -  save = length < 0 ? xstrdup (string) : xstrndup (string, length);
  51. -  p = save;
  52. +  if (length > 0)
  53. +    {
  54. +      end_ch = string[length];
  55. +      string[length] = '\0';
  56. +    }
  57. +  p = string;
  58.  
  59.    while (1)
  60.      {
  61. @@ -404,7 +418,8 @@
  62.        ++p;
  63.      }
  64.  
  65. -  free (save);
  66. +  if (length > 0)
  67. +    string[length] = end_ch;
  68.  
  69.    variable_buffer_output (o, "", 1);
  70.    return (variable_buffer + line_offset);
  71. @@ -414,12 +429,6 @@
  72.     Build in 'variable_buffer' the result of expanding the references and calls.
  73.     Return the address of the resulting string, which is null-terminated
  74.     and is valid only until the next time this function is called.  */
  75. -
  76. -char *
  77. -variable_expand (const char *line)
  78. -{
  79. -  return variable_expand_string(NULL, line, (long)-1);
  80. -}
  81.  
  82.  /* Expand an argument for an expansion function.
  83.     The text starting at STR and ending at END is variable-expanded
  84. @@ -430,27 +439,39 @@
  85.  char *
  86.  expand_argument (const char *str, const char *end)
  87.  {
  88. -  char *tmp, *alloc = NULL;
  89. +//  char *tmp, *alloc = NULL;
  90.    char *r;
  91. +  char *strend = (char *) end;
  92. +  char end_ch = 0;
  93. +
  94.  
  95.    if (str == end)
  96.      return xstrdup("");
  97.  
  98. -  if (!end || *end == '\0')
  99. -    return allocated_variable_expand (str);
  100. +//  if (!end || *end == '\0')
  101. +//    return allocated_variable_expand (str);
  102. +//
  103. +//  if (end - str + 1 > 1000)
  104. +//    tmp = alloc = xmalloc (end - str + 1);
  105. +//  else
  106. +//    tmp = alloca (end - str + 1);
  107. +//
  108. +//  memcpy (tmp, str, end - str);
  109. +//  tmp[end - str] = '\0';
  110.  
  111. -  if (end - str + 1 > 1000)
  112. -    tmp = alloc = xmalloc (end - str + 1);
  113. -  else
  114. -    tmp = alloca (end - str + 1);
  115. +  if (strend)
  116. +    {
  117. +      end_ch = *strend;
  118. +      *strend = '\0';
  119. +    }
  120.  
  121. -  memcpy (tmp, str, end - str);
  122. -  tmp[end - str] = '\0';
  123. +  r = allocated_variable_expand (str);
  124.  
  125. -  r = allocated_variable_expand (tmp);
  126. +  if (strend)
  127. +    *strend = end_ch;
  128.  
  129. -  if (alloc)
  130. -    free (alloc);
  131. +//  if (alloc)
  132. +//    free (alloc);
  133.  
  134.    return r;
  135.  }
  136. Index: function.c
  137. ===================================================================
  138. RCS file: /sources/make/make/function.c,v
  139. retrieving revision 1.133
  140. diff -u -r1.133 function.c
  141. --- function.c  5 Mar 2012 14:10:43 -0000   1.133
  142. +++ function.c  7 Mar 2012 14:33:26 -0000
  143. @@ -828,38 +828,42 @@
  144.    /* expand only the first two.  */
  145.    char *varname = expand_argument (argv[0], NULL);
  146.    char *list = expand_argument (argv[1], NULL);
  147. -  const char *body = argv[2];
  148. +  char *body = argv[2];
  149.  
  150. -  int doneany = 0;
  151.    const char *list_iterator = list;
  152. -  const char *p;
  153. +  char *p;
  154. +  char *saved_value;
  155.    unsigned int len;
  156.    struct variable *var;
  157.  
  158. -  push_new_variable_scope ();
  159. +  struct variable_scope scope;
  160. +
  161. +  push_variable_scope (&scope);
  162. +
  163.    var = define_variable (varname, strlen (varname), "", o_automatic, 0);
  164. +  saved_value = var->value;
  165.  
  166.    /* loop through LIST,  put the value in VAR and expand BODY */
  167.    while ((p = find_next_token (&list_iterator, &len)) != 0)
  168.      {
  169. -      char *result = 0;
  170. -
  171. -      free (var->value);
  172. -      var->value = xstrndup (p, len);
  173. +      char end_ch = p[len];
  174. +      p[len] = '\0';
  175.  
  176. -      result = allocated_variable_expand (body);
  177. +      var->value = p;
  178. +      o = variable_expand_string (o, body, (long) -1);
  179. +      o = variable_buffer_output (o + strlen (o), " ", 1);
  180.  
  181. -      o = variable_buffer_output (o, result, strlen (result));
  182. -      o = variable_buffer_output (o, " ", 1);
  183. -      doneany = 1;
  184. -      free (result);
  185. +      p[len] = end_ch;
  186.      }
  187.  
  188. -  if (doneany)
  189. +  if (var->value != saved_value)
  190.      /* Kill the last space.  */
  191.      --o;
  192.  
  193. +  var->value = saved_value;
  194. +
  195.    pop_variable_scope ();
  196. +
  197.    free (varname);
  198.    free (list);
  199.  
  200. @@ -2391,20 +2395,22 @@
  201.    static int max_args = 0;
  202.    char *fname;
  203.    char *cp;
  204. -  char *body;
  205.    int flen;
  206.    int i;
  207.    int saved_args;
  208.    const struct function_table_entry *entry_p;
  209.    struct variable *v;
  210. +  struct variable_scope scope;
  211.  
  212.    /* There is no way to define a variable with a space in the name, so strip
  213. -     leading and trailing whitespace as a favor to the user.  */
  214. +     trailing whitespace as a favor to the user.  */
  215.    fname = argv[0];
  216.    while (*fname != '\0' && isspace ((unsigned char)*fname))
  217.      ++fname;
  218.  
  219. -  cp = fname + strlen (fname) - 1;
  220. +  flen = strlen (fname);
  221. +
  222. +  cp = fname + flen - 1;
  223.    while (cp > fname && isspace ((unsigned char)*cp))
  224.      --cp;
  225.    cp[1] = '\0';
  226. @@ -2413,6 +2419,9 @@
  227.    if (*fname == '\0')
  228.      return o;
  229.  
  230. +  /* Fix up the length after stripping a trailing whitespace. */
  231. +  flen = cp - fname + 1;
  232. +
  233.    /* Are we invoking a builtin function?  */
  234.  
  235.    entry_p = lookup_function (fname);
  236. @@ -2426,7 +2435,6 @@
  237.  
  238.    /* Not a builtin, so the first argument is the name of a variable to be
  239.       expanded and interpreted as a function.  Find it.  */
  240. -  flen = strlen (fname);
  241.  
  242.    v = lookup_variable (fname, flen);
  243.  
  244. @@ -2436,16 +2444,9 @@
  245.    if (v == 0 || *v->value == '\0')
  246.      return o;
  247.  
  248. -  body = alloca (flen + 4);
  249. -  body[0] = '$';
  250. -  body[1] = '(';
  251. -  memcpy (body + 2, fname, flen);
  252. -  body[flen+2] = ')';
  253. -  body[flen+3] = '\0';
  254. -
  255.    /* Set up arguments $(1) .. $(N).  $(0) is the function name.  */
  256.  
  257. -  push_new_variable_scope ();
  258. +  push_variable_scope (&scope);
  259.  
  260.    for (i=0; *argv; ++i, ++argv)
  261.      {
  262. @@ -2468,21 +2469,30 @@
  263.        define_variable (num, strlen (num), "", o_automatic, 0);
  264.      }
  265.  
  266. -  /* Expand the body in the context of the arguments, adding the result to
  267. +  /* Expand the variable in the context of the arguments, adding the result to
  268.       the variable buffer.  */
  269.  
  270.    v->exp_count = EXP_COUNT_MAX;
  271.  
  272.    saved_args = max_args;
  273.    max_args = i;
  274. -  o = variable_expand_string (o, body, flen+3);
  275. +
  276. +  {
  277. +    char *value = (v->recursive ? recursively_expand (v) : v->value);
  278. +
  279. +    o = variable_buffer_output (o, value, strlen (value));
  280. +
  281. +    if (v->recursive)
  282. +      free (value);
  283. +  }
  284. +
  285.    max_args = saved_args;
  286.  
  287.    v->exp_count = 0;
  288.  
  289.    pop_variable_scope ();
  290.  
  291. -  return o + strlen (o);
  292. +  return o;
  293.  }
  294.  
  295.  void
  296. Index: variable.c
  297. ===================================================================
  298. RCS file: /sources/make/make/variable.c,v
  299. retrieving revision 1.112
  300. diff -u -r1.112 variable.c
  301. --- variable.c  5 Mar 2012 14:10:45 -0000   1.112
  302. +++ variable.c  7 Mar 2012 14:33:26 -0000
  303. @@ -666,23 +666,33 @@
  304.     directly to the global_setlist so we need to replace that with the new one.
  305.   */
  306.  
  307. -struct variable_set_list *
  308. -push_new_variable_scope (void)
  309. +void
  310. +push_variable_scope (struct variable_scope *scope)
  311.  {
  312. -  current_variable_set_list = create_new_variable_set();
  313. -  if (current_variable_set_list->next == &global_setlist)
  314. +  register struct variable_set_list *setlist = &scope->list;
  315. +  register struct variable_set *set = &scope->set;
  316. +
  317. +  hash_init (&set->table, SMALL_SCOPE_VARIABLE_BUCKETS,
  318. +        variable_hash_1, variable_hash_2, variable_hash_cmp);
  319. +
  320. +  setlist->set = set;
  321. +  setlist->next = current_variable_set_list;
  322. +  setlist->next_is_parent = 0;
  323. +
  324. +  if (setlist->next != &global_setlist)
  325. +    current_variable_set_list = setlist;
  326. +  else
  327.      {
  328.        /* It was the global, so instead of new -> &global we want to replace
  329.           &global with the new one and have &global -> new, with current still
  330.           pointing to &global  */
  331. -      struct variable_set *set = current_variable_set_list->set;
  332. -      current_variable_set_list->set = global_setlist.set;
  333. +      setlist->set = global_setlist.set;
  334.        global_setlist.set = set;
  335. -      current_variable_set_list->next = global_setlist.next;
  336. -      global_setlist.next = current_variable_set_list;
  337. +      setlist->next = global_setlist.next;
  338. +      global_setlist.next = setlist;
  339. +
  340.        current_variable_set_list = &global_setlist;
  341.      }
  342. -  return (current_variable_set_list);
  343.  }
  344.  
  345.  void
  346. @@ -713,11 +723,8 @@
  347.        global_setlist.next_is_parent = setlist->next_is_parent;
  348.      }
  349.  
  350. -  /* Free the one we no longer need.  */
  351. -  free (setlist);
  352.    hash_map (&set->table, free_variable_name_and_value);
  353.    hash_free (&set->table, 1);
  354. -  free (set);
  355.  }
  356.  
  357.  /* Merge FROM_SET into TO_SET, freeing unused storage in FROM_SET.  */
  358. Index: variable.h
  359. ===================================================================
  360. RCS file: /sources/make/make/variable.h,v
  361. retrieving revision 1.51
  362. diff -u -r1.51 variable.h
  363. --- variable.h  5 Mar 2012 14:10:45 -0000   1.51
  364. +++ variable.h  7 Mar 2012 14:33:26 -0000
  365. @@ -96,6 +96,15 @@
  366.      int next_is_parent;                 /* True if next is a parent target.  */
  367.    };
  368.  
  369. +/* Structure for pushing (popping) it into (from) a variable set stack.
  370. + * It is also suitable for allocating it on the stack.  */
  371. +
  372. +struct variable_scope
  373. +  {
  374. +    struct variable_set_list list;
  375. +    struct variable_set set;
  376. +  };
  377. +
  378.  /* Structure used for pattern-specific variables.  */
  379.  
  380.  struct pattern_var
  381. @@ -113,7 +122,8 @@
  382.  
  383.  /* expand.c */
  384.  char *variable_buffer_output (char *ptr, const char *string, unsigned int length);
  385. -char *variable_expand (const char *line);
  386. +#define variable_expand(line) \
  387. +  variable_expand_string(NULL, line, (long)-1)
  388.  char *variable_expand_for_file (const char *line, struct file *file);
  389.  char *allocated_variable_expand_for_file (const char *line, struct file *file);
  390.  #define    allocated_variable_expand(line) \
  391. @@ -143,7 +153,7 @@
  392.  /* variable.c */
  393.  struct variable_set_list *create_new_variable_set (void);
  394.  void free_variable_set (struct variable_set_list *);
  395. -struct variable_set_list *push_new_variable_scope (void);
  396. +void push_variable_scope (struct variable_scope *);
  397.  void pop_variable_scope (void);
  398.  void define_automatic_variables (void);
  399.  void initialize_file_variables (struct file *file, int reading);
  400. Index: vpath.c
  401. ===================================================================
  402. RCS file: /sources/make/make/vpath.c,v
  403. retrieving revision 1.56
  404. diff -u -r1.56 vpath.c
  405. --- vpath.c 5 Mar 2012 14:10:46 -0000   1.56
  406. +++ vpath.c 7 Mar 2012 14:33:26 -0000
  407. @@ -73,13 +73,15 @@
  408.       calling lookup_variable so that it will be recursively expanded.  */
  409.  
  410.    {
  411. +    char *str = xstrdup("$(strip $(VPATH))");
  412.      /* Turn off --warn-undefined-variables while we expand SHELL and IFS.  */
  413.      int save = warn_undefined_variables_flag;
  414.      warn_undefined_variables_flag = 0;
  415.  
  416. -    p = variable_expand ("$(strip $(VPATH))");
  417. +    p = variable_expand (str);
  418.  
  419.      warn_undefined_variables_flag = save;
  420. +    free(str);
  421.    }
  422.  
  423.    if (*p != '\0')
  424. @@ -106,13 +108,15 @@
  425.       calling lookup_variable so that it will be recursively expanded.  */
  426.  
  427.    {
  428. +    char *str = xstrdup("$(strip $(GPATH))");
  429.      /* Turn off --warn-undefined-variables while we expand SHELL and IFS.  */
  430.      int save = warn_undefined_variables_flag;
  431.      warn_undefined_variables_flag = 0;
  432.  
  433. -    p = variable_expand ("$(strip $(GPATH))");
  434. +    p = variable_expand (str);
  435.  
  436.      warn_undefined_variables_flag = save;
  437. +    free(str);
  438.    }
  439.  
  440.    if (*p != '\0')
Advertisement
Add Comment
Please, Sign In to add comment