Changeset 1932


Ignore:
Timestamp:
Oct 24, 2008, 10:22:22 PM (17 years ago)
Author:
bird
Message:

kmk: Made struct variable capable of holding read only variables to speed up set_file_variables.

Location:
trunk/src/kmk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kmk/Makefile.am

    r1918 r1932  
    139139        -DCONFIG_PRETTY_COMMAND_PRINTING \
    140140        -DCONFIG_WITH_PRINT_STATS_SWITCH \
     141        -DCONFIG_WITH_RDONLY_VARIABLE_VALUE \
    141142        \
    142143        -DKBUILD_HOST=\"$(BUILD_TARGET)\" \
  • trunk/src/kmk/Makefile.kmk

    r1925 r1932  
    169169        CONFIG_PRETTY_COMMAND_PRINTING \
    170170        CONFIG_WITH_PRINT_STATS_SWITCH \
     171        CONFIG_WITH_RDONLY_VARIABLE_VALUE \
    171172        \
    172173        KBUILD_HOST=\"$(KBUILD_TARGET)\" \
  • trunk/src/kmk/commands.c

    r1898 r1932  
    8585      const char *name;
    8686      unsigned int len;
     87#ifdef CONFIG_WITH_STRCACHE2
     88      static const char *suffixes_strcache = 0; /* XXX: make this global */
     89
     90      if (!suffixes_strcache)
     91        suffixes_strcache = strcache_add_len (".SUFFIXES", sizeof (".SUFFIXES") - 1);
     92#endif /* CONFIG_WITH_STRCACHE2 */
    8793
    8894#ifndef NO_ARCHIVES
     
    103109        }
    104110
     111#ifndef CONFIG_WITH_STRCACHE2
    105112      for (d = enter_file (strcache_add (".SUFFIXES"))->deps; d ; d = d->next)
    106113        {
    107 #ifndef CONFIG_WITH_STRCACHE2
    108114          unsigned int slen = strlen (dep_name (d));
    109115#else
     116      for (d = enter_file (suffixes_strcache)->deps; d ; d = d->next)
     117        {
    110118          unsigned int slen = strcache2_get_len (&file_strcache, dep_name (d));
    111119#endif
     
    140148  /* Define the variables.  */
    141149
     150#ifndef CONFIG_WITH_RDONLY_VARIABLE_VALUE
    142151  DEFINE_VARIABLE ("<", 1, less);
    143152  DEFINE_VARIABLE ("*", 1, star);
    144153  DEFINE_VARIABLE ("@", 1, at);
    145154  DEFINE_VARIABLE ("%", 1, percent);
     155#else  /* CONFIG_WITH_RDONLY_VARIABLE_VALUE */
     156# define DEFINE_VARIABLE_RO_VAL(name, len, value, value_len) \
     157  define_variable_in_set((name), (len), (value), (value_len), -1, \
     158        (o_automatic), 0, (file)->variables->set, NILF)
     159
     160  if (*less == '\0')
     161    DEFINE_VARIABLE_RO_VAL ("<", 1, "", 0);
     162  else if (less != at || at == file->name)
     163    DEFINE_VARIABLE_RO_VAL ("<", 1, less, strcache_get_len (less));
     164  else
     165    DEFINE_VARIABLE ("<", 1, less);
     166
     167  if (*star == '\0')
     168    DEFINE_VARIABLE_RO_VAL ("*", 1, "", 0);
     169  else
     170    DEFINE_VARIABLE_RO_VAL ("*", 1, star, strcache_get_len (star));
     171
     172  if (at == file->name)
     173    DEFINE_VARIABLE_RO_VAL ("@", 1, at, strcache_get_len (at));
     174  else
     175    DEFINE_VARIABLE ("@", 1, at);
     176
     177  if (*percent == '\0')
     178    DEFINE_VARIABLE_RO_VAL ("%", 1, "", 0);
     179  else
     180    DEFINE_VARIABLE ("%", 1, percent);
     181#endif /* CONFIG_WITH_RDONLY_VARIABLE_VALUE */
    146182
    147183  /* Compute the values for $^, $+, $?, and $|.  */
  • trunk/src/kmk/expand.c

    r1931 r1932  
    976976
    977977      /* Replace the variable with the variable buffer. */
    978       free (v->value);
     978#ifdef CONFIG_WITH_RDONLY_VARIABLE_VALUE
     979      if (v->rdonly_val)
     980        v->rdonly_val = 0;
     981      else
     982#endif
     983        free (v->value);
    979984      v->value = variable_buffer;
    980985      v->value_length = p - v->value;
  • trunk/src/kmk/function.c

    r1926 r1932  
    10411041      if (len >= (unsigned int)var->value_alloc_len)
    10421042        {
    1043           free (var->value);
     1043# ifdef CONFIG_WITH_RDONLY_VARIABLE_VALUE
     1044          if (var->rdonly_val)
     1045            var->rdonly_val = 0;
     1046          else
     1047# endif
     1048            free (var->value);
    10441049          var->value_alloc_len = (len + 32) & ~31;
    10451050          var->value = xmalloc (var->value_alloc_len);
  • trunk/src/kmk/kbuild.c

    r1924 r1932  
    572572        unsigned int value_len;
    573573        char *pszExpanded = allocated_variable_expand_2(pVar->value, pVar->value_length, &value_len);
    574         free(pVar->value);
     574#ifdef CONFIG_WITH_RDONLY_VARIABLE_VALUE
     575        if (pVar->rdonly_val)
     576            pVar->rdonly_val = 0;
     577        else
     578#endif
     579            free(pVar->value);
     580        assert (pVar->origin != o_automatic);
    575581        pVar->value = pszExpanded;
    576582        pVar->value_length = value_len;
     
    643649    struct variable *pVar = kbuild_lookup_variable_n(pszName, cchName);
    644650    if (pVar && pDefPath)
     651    {
     652        assert(pVar->origin != o_automatic);
     653#ifdef CONFIG_WITH_RDONLY_VARIABLE_VALUE
     654        assert(!pVar->rdonly_val);
     655#endif
    645656        kbuild_apply_defpath(pDefPath, &pVar->value, (unsigned int *)&pVar->value_length, &pVar->value_alloc_len, 1);
     657    }
    646658    return pVar;
    647659}
     
    661673    struct variable *pVar = kbuild_lookup_variable(pszName);
    662674    if (pVar && pDefPath)
     675    {
     676        assert(pVar->origin != o_automatic);
     677#ifdef CONFIG_WITH_RDONLY_VARIABLE_VALUE
     678        assert(!pVar->rdonly_val);
     679#endif
    663680        kbuild_apply_defpath(pDefPath, &pVar->value, (unsigned int *)&pVar->value_length, &pVar->value_alloc_len, 1);
     681    }
    664682    return pVar;
    665683}
     
    20442062     */
    20452063    if (pDefPath)
     2064    {
     2065        /** @todo assert(pSource->origin != o_automatic);  We're changing 'source'
     2066         *        from the foreach loop!  */
     2067#ifdef CONFIG_WITH_RDONLY_VARIABLE_VALUE
     2068        assert(!pSource->rdonly_val);
     2069#endif
    20462070        kbuild_apply_defpath(pDefPath, &pSource->value, (unsigned int *)&pSource->value_length, &pSource->value_alloc_len, 1 /* can free */);
     2071    }
    20472072
    20482073    /*
  • trunk/src/kmk/variable.c

    r1918 r1932  
    254254          else
    255255            assert (value_len == strlen (value));
    256           if (!duplicate_value)
     256          if (!duplicate_value || duplicate_value == -1)
    257257            {
     258# ifdef CONFIG_WITH_RDONLY_VARIABLE_VALUE
     259              if (v->value != 0 && !v->rdonly_val)
     260                  free (v->value);
     261              v->rdonly_val = duplicate_value == -1;
     262              v->value = (char *)value;
     263              v->value_alloc_len = 0;
     264# else
    258265              if (v->value != 0)
    259266                free (v->value);
    260267              v->value = (char *)value;
    261268              v->value_alloc_len = value_len + 1;
     269# endif
    262270            }
    263271          else
     
    265273              if ((unsigned int)v->value_alloc_len <= value_len)
    266274                {
    267                   free (v->value);
     275# ifdef CONFIG_WITH_RDONLY_VARIABLE_VALUE
     276                  if (v->rdonly_val)
     277                    v->rdonly_val = 0;
     278                  else
     279# endif
     280                    free (v->value);
    268281                  v->value_alloc_len = (value_len + 0x40) & ~0x3f;
    269282                  v->value = xmalloc (v->value_alloc_len);
     
    272285            }
    273286          v->value_length = value_len;
    274 #else
     287#else  /* !CONFIG_WITH_VALUE_LENGTH */
    275288          if (v->value != 0)
    276289            free (v->value);
    277290          v->value = xstrdup (value);
    278 #endif
     291#endif /* !CONFIG_WITH_VALUE_LENGTH */
    279292          if (flocp != 0)
    280293            v->fileinfo = *flocp;
     
    307320    assert (value_len == strlen (value));
    308321  v->value_length = value_len;
    309   if (!duplicate_value)
    310     {
    311       v->value_alloc_len = value_len + 1;
     322  if (!duplicate_value || duplicate_value == -1)
     323    {
     324# ifdef CONFIG_WITH_RDONLY_VARIABLE_VALUE
     325      v->rdonly_val = duplicate_value == -1;
     326      v->value_alloc_len = v->rdonly_val ? 0 : value_len + 1;
     327# endif
    312328      v->value = (char *)value;
    313329    }
    314330  else
    315331    {
     332# ifdef CONFIG_WITH_RDONLY_VARIABLE_VALUE
     333      v->rdonly_val = 0;
     334# endif
    316335      v->value_alloc_len = (value_len + 32) & ~31;
    317336      v->value = xmalloc (v->value_alloc_len);
     
    13451364  if (*v->value == '\0' || v->origin == o_env || v->origin == o_env_override)
    13461365    {
    1347       free (v->value);
     1366#ifdef CONFIG_WITH_RDONLY_VARIABLE_VALUE
     1367      if (v->rdonly_val)
     1368        v->rdonly_val = 0;
     1369      else
     1370#endif
     1371        free (v->value);
    13481372      v->origin = o_file;
    13491373      v->value = xstrdup (default_shell);
     
    15891613      if ((unsigned)v->value_alloc_len < new_value_len + 1)
    15901614          v->value_alloc_len = (new_value_len + 1 + value_len + 0x7f) + ~0x7fU;
     1615# ifdef CONFIG_WITH_RDONLY_VARIABLE_VALUE
     1616      if ((append || !v->value_length) && !v->rdonly_val)
     1617# else
    15911618      if (append || !v->value_length)
     1619# endif
    15921620        v->value = xrealloc (v->value, v->value_alloc_len);
    15931621      else
     
    15971625          memcpy (&new_buf[value_len + 1], v->value, v->value_length + 1);
    15981626          done_1st_prepend_copy = 1;
    1599           free (v->value);
     1627# ifdef CONFIG_WITH_RDONLY_VARIABLE_VALUE
     1628          if (v->rdonly_val)
     1629            v->rdonly_val = 0;
     1630          else
     1631# endif
     1632            free (v->value);
    16001633          v->value = new_buf;
    16011634        }
     
    20942127  v->value_length = eos != NULL ? eos - p : -1;
    20952128  assert (eos == NULL || strchr (p, '\0') == eos);
     2129# ifdef CONFIG_WITH_RDONLY_VARIABLE_VALUE
     2130  v->rdonly_val = 0;
     2131# endif
    20962132#endif
    20972133
  • trunk/src/kmk/variable.h

    r1931 r1932  
    8282                                /* If >1, allow this many self-referential
    8383                                   expansions.  */
     84#ifdef CONFIG_WITH_RDONLY_VARIABLE_VALUE
     85    unsigned int rdonly_val:1;  /* VALUE is read only (strcache/const). */
     86#endif
    8487    enum variable_flavor
    8588      flavor ENUM_BITFIELD (3); /* Variable flavor.  */
Note: See TracChangeset for help on using the changeset viewer.