Changeset 1847 for trunk/src/kmk


Ignore:
Timestamp:
Oct 12, 2008, 6:25:03 PM (17 years ago)
Author:
bird
Message:

kmk: Some optimizations for expand_deps.

Location:
trunk/src/kmk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kmk/expand.c

    r1837 r1847  
    753753expand_argument (const char *str, const char *end)
    754754{
     755#ifndef CONFIG_WITH_VALUE_LENGTH /** @todo the hacks are no longer required. Clean up !! */
    755756  char *tmp;
     757#endif
    756758
    757759  if (str == end)
     
    823825
    824826   Differs from variable_expand_for_file in that it takes a pointer to
    825    where in the variable buffer to start outputting the expanded string.  */
     827   where in the variable buffer to start outputting the expanded string,
     828   and that it can returned the length of the string if you wish.  */
    826829
    827830char *
    828 variable_expand_for_file_2 (char *o, const char *line, struct file *file)
     831variable_expand_for_file_2 (char *o, const char *line, unsigned int length,
     832                            struct file *file, unsigned int *value_lenp)
    829833{
    830834  char *result;
    831835  struct variable_set_list *save;
    832836  const struct floc *reading_file_saved;
     837  long len = length == ~0U ? (long)-1 : (long)length;
    833838  char *eol;
    834839
     840  if (!o)
     841    o = initialize_variable_output();
     842
    835843  if (file == 0)
    836     return variable_expand_string_2 (o, line, (long)-1, &eol);
    837 
    838   save = current_variable_set_list;
    839   current_variable_set_list = file->variables;
    840   reading_file_saved = reading_file;
    841   if (file->cmds && file->cmds->fileinfo.filenm)
    842     reading_file = &file->cmds->fileinfo;
     844     result = variable_expand_string_2 (o, line, len, &eol);
    843845  else
    844     reading_file = 0;
    845   result = variable_expand_string_2 (o, line, (long)-1, &eol);
    846   current_variable_set_list = save;
    847   reading_file = reading_file_saved;
     846    {
     847      save = current_variable_set_list;
     848      current_variable_set_list = file->variables;
     849      reading_file_saved = reading_file;
     850      if (file->cmds && file->cmds->fileinfo.filenm)
     851        reading_file = &file->cmds->fileinfo;
     852      else
     853        reading_file = 0;
     854      result = variable_expand_string_2 (o, line, len, &eol);
     855      current_variable_set_list = save;
     856      reading_file = reading_file_saved;
     857    }
     858
     859  if (value_lenp)
     860    *value_lenp = eol - result;
    848861
    849862  return result;
  • trunk/src/kmk/file.c

    r1833 r1847  
    507507      struct dep *new, *d1;
    508508      char *p;
     509#ifdef CONFIG_WITH_VALUE_LENGTH
     510      unsigned int len;
     511#endif
    509512
    510513      if (! d->name)
     
    518521          p = variable_expand ("");
    519522          buffer_offset = p - variable_buffer;
     523#ifndef CONFIG_WITH_VALUE_LENGTH
    520524          variable_buffer_output (p, d->name, strlen (d->name) + 1);
     525#else
     526          len = strcache_get_len (d->name);
     527          variable_buffer_output (p, d->name, len + 1);
     528#endif
    521529          p = variable_buffer + buffer_offset; /* bird - variable_buffer may have been reallocated. (observed it) */
    522530        }
     
    554562          set_file_variables (f);
    555563
     564#ifndef CONFIG_WITH_VALUE_LENGTH
    556565          p = variable_expand_for_file (d->name, f);
     566#else
     567          len = strcache_get_len (d->name);
     568          p = variable_expand_for_file_2 (NULL, d->name, len, f, &len);
     569#endif
    557570
    558571          if (d->stem != 0)
     
    561574
    562575      /* Parse the prerequisites.  */
     576#ifndef CONFIG_WITH_VALUE_LENGTH
    563577      new = parse_prereqs (p);
     578#else
     579      /** @todo make use of len here! */
     580      new = parse_prereqs (p);
     581#endif
    564582
    565583      /* If this dep list was from a static pattern rule, expand the %s.  We
     
    576594            {
    577595              char *percent;
     596#ifndef KMK
    578597              int nl = strlen (dp->name) + 1;
    579598              char *nm = alloca (nl);
    580599              memcpy (nm, dp->name, nl);
    581600              percent = find_percent (nm);
     601#else  /* KMK - don't make a stack copy unless it's actually required! */
     602              unsigned int nl = strcache_get_len (dp->name);
     603              char *nm;
     604              percent = memchr (nm, '%', nl);
     605              if (percent)
     606                {
     607                  nm = alloca (nl + 1);
     608                  memcpy (nm, dp->name, nl + 1);
     609                  percent = find_percent (nm);
     610                }
     611#endif /* KMK */
    582612              if (percent)
    583613                {
  • trunk/src/kmk/function.c

    r1838 r1847  
    39423942          if (i)
    39433943            o = variable_buffer_output (o, cmd_sep, cmd_sep_len);
    3944           o = variable_expand_for_file_2 (o, cmds->command_lines[i], file);
     3944          o = variable_expand_for_file_2 (o, cmds->command_lines[i], ~0U, file, NULL);
    39453945
    39463946          /* Skip it if it has a '%' prefix or is blank. */
  • trunk/src/kmk/variable.h

    r1830 r1847  
    182182char *variable_expand_for_file (const char *line, struct file *file);
    183183#ifdef CONFIG_WITH_COMMANDS_FUNC
    184 char *variable_expand_for_file_2 (char *o, const char *line, struct file *file);
     184char *variable_expand_for_file_2 (char *o, const char *line, unsigned int lenght,
     185                                  struct file *file, unsigned int *value_lenp);
    185186#endif
    186187char *allocated_variable_expand_for_file (const char *line, struct file *file);
Note: See TracChangeset for help on using the changeset viewer.