Ignore:
Timestamp:
Oct 10, 2008, 4:27:38 AM (17 years ago)
Author:
bird
Message:

kmk: More length and alloc optimizations. Made all the length optimizations from yesterday CONFIG_WITH_VALUE_LENGTH instead of KMK.

File:
1 edited

Legend:

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

    r1808 r1809  
    467467struct variable *
    468468define_variable_in_set (const char *name, unsigned int length,
    469                         const char *value, unsigned int value_length, int duplicate_value,
    470                         enum variable_origin origin, int recursive,
    471                         struct variable_set *set, const struct floc *flocp)
     469                        const char *value, unsigned int value_len,
     470                        int duplicate_value, enum variable_origin origin,
     471                        int recursive, struct variable_set *set,
     472                        const struct floc *flocp)
    472473#else
    473474struct variable *
     
    510511        {
    511512#ifdef CONFIG_WITH_VALUE_LENGTH
    512           if (value_length == ~0U)
    513             value_length = strlen (value);
     513          if (value_len == ~0U)
     514            value_len = strlen (value);
    514515          else
    515             assert (value_length == strlen (value));
     516            assert (value_len == strlen (value));
    516517          if (!duplicate_value)
    517518            {
     
    519520                free (v->value);
    520521              v->value = (char *)value;
    521               v->value_alloc_len = value_length + 1;
     522              v->value_alloc_len = value_len + 1;
    522523            }
    523524          else
    524525            {
    525               if ((unsigned int)v->value_alloc_len <= value_length)
     526              if ((unsigned int)v->value_alloc_len <= value_len)
    526527                {
    527528                  free (v->value);
    528                   v->value_alloc_len = (value_length + 0x40) & ~0x3f;
     529                  v->value_alloc_len = (value_len + 0x40) & ~0x3f;
    529530                  v->value = xmalloc (v->value_alloc_len);
    530531                }
    531               memcpy (v->value, value, value_length + 1);
     532              memcpy (v->value, value, value_len + 1);
    532533            }
    533           v->value_length = value_length;
     534          v->value_length = value_len;
    534535#else
    535536          if (v->value != 0)
     
    558559  hash_insert_at (&set->table, v, var_slot);
    559560#ifdef CONFIG_WITH_VALUE_LENGTH
    560   if (value_length == ~0U)
    561     value_length = strlen (value);
     561  if (value_len == ~0U)
     562    value_len = strlen (value);
    562563  else
    563     assert (value_length == strlen (value));
    564   v->value_length = value_length;
     564    assert (value_len == strlen (value));
     565  v->value_length = value_len;
    565566  if (!duplicate_value)
    566567    {
    567       v->value_alloc_len = value_length + 1;
     568      v->value_alloc_len = value_len + 1;
    568569      v->value = (char *)value;
    569570    }
    570571  else
    571572    {
    572       v->value_alloc_len = (value_length + 32) & ~31;
     573      v->value_alloc_len = (value_len + 32) & ~31;
    573574      v->value = xmalloc (v->value_alloc_len);
    574       memcpy (v->value, value, value_length + 1);
     575      memcpy (v->value, value, value_len + 1);
    575576    }
    576577#else
     
    16181619    {
    16191620      v->value_alloc_len *= 2;
    1620       if (v->value_alloc_len < new_value_len + 1)
     1621      if ((unsigned)v->value_alloc_len < new_value_len + 1)
    16211622          v->value_alloc_len = (new_value_len + 1 + value_len + 0x7f) + ~0x7fU;
    16221623      if (append || !v->value_length)
     
    16551656
    16561657static struct variable *
    1657 do_variable_definition_append (const struct floc *flocp, struct variable *v, const char *value,
    1658                                enum variable_origin origin, int append)
     1658do_variable_definition_append (const struct floc *flocp, struct variable *v,
     1659                               const char *value, unsigned int value_len,
     1660                               int simple_value, enum variable_origin origin,
     1661                               int append)
    16591662{
    16601663  if (env_overrides && origin == o_env)
     
    16791682  /* The juicy bits, append the specified value to the variable
    16801683     This is a heavily exercised code path in kBuild. */
    1681   if (v->recursive)
    1682     append_string_to_variable (v, value, strlen (value), append);
     1684  if (value_len == ~0U)
     1685    value_len = strlen (value);
     1686  if (v->recursive || simple_value)
     1687    append_string_to_variable (v, value, value_len, append);
    16831688  else
    16841689    /* The previous definition of the variable was simple.
    16851690       The new value comes from the old value, which was expanded
    16861691       when it was set; and from the expanded new value. */
    1687     append_expanded_string_to_variable (v, value, append);
     1692    append_expanded_string_to_variable (v, value, value_len, append);
    16881693
    16891694  /* update the variable */
     
    16971702
    16981703struct variable *
     1704#ifndef CONFIG_WITH_VALUE_LENGTH
    16991705do_variable_definition (const struct floc *flocp, const char *varname,
    17001706                        const char *value, enum variable_origin origin,
    17011707                        enum variable_flavor flavor, int target_var)
     1708#else  /* CONFIG_WITH_VALUE_LENGTH */
     1709do_variable_definition_2 (const struct floc *flocp,
     1710                          const char *varname, const char *value,
     1711                          unsigned int value_len, int simple_value,
     1712                          char *free_value,
     1713                          enum variable_origin origin,
     1714                          enum variable_flavor flavor,
     1715                          int target_var)
     1716#endif /* CONFIG_WITH_VALUE_LENGTH */
    17021717{
    17031718  const char *p;
     
    17081723  const size_t varname_len = strlen (varname); /* bird */
    17091724#ifdef CONFIG_WITH_VALUE_LENGTH
    1710   unsigned int value_len = ~0U;
     1725  assert (value_len == ~0U || value_len == strlen (value));
    17111726#endif
    17121727
     
    17241739         variable buffer, and we may still need that if we're looking at a
    17251740         target-specific variable.  */
    1726 #if !defined(KMK) || !defined(CONFIG_WITH_VALUE_LENGTH)
     1741#ifndef CONFIG_WITH_VALUE_LENGTH
    17271742      p = alloc_value = allocated_variable_expand (value);
    1728 #else  /* KMK - optimization */
    1729       p = alloc_value = allocated_variable_expand_2 (value, -1, &value_len);
    1730 #endif /* KMK - optimization */
     1743#else  /* CONFIG_WITH_VALUE_LENGTH */
     1744      if (!simple_value)
     1745        p = alloc_value = allocated_variable_expand_2 (value, value_len, &value_len);
     1746      else
     1747      {
     1748        if (value_len == ~0U)
     1749          value_len = strlen (value);
     1750        if (!free_value)
     1751          p = alloc_value = savestring (value, value_len);
     1752        else
     1753          {
     1754            assert (value == free_value);
     1755            p = alloc_value = free_value;
     1756            free_value = 0;
     1757          }
     1758      }
     1759#endif /* CONFIG_WITH_VALUE_LENGTH */
    17311760      break;
    17321761    case f_conditional:
     
    17891818#ifdef CONFIG_WITH_VALUE_LENGTH
    17901819            v->append = append;
     1820            v = do_variable_definition_append (flocp, v, value, value_len,
     1821                                               simple_value, origin,
    17911822# ifdef CONFIG_WITH_PREPEND_ASSIGNMENT
    1792             return do_variable_definition_append (flocp, v, value, origin, org_flavor == f_append);
     1823                                              org_flavor == f_append);
    17931824# else
    1794             return do_variable_definition_append (flocp, v, value, origin, 1);
     1825                                              1);
    17951826# endif
     1827            if (free_value)
     1828               free (free_value);
     1829            return v;
    17961830#else /* !CONFIG_WITH_VALUE_LENGTH */
    17971831
     
    19732007  if (alloc_value)
    19742008    free (alloc_value);
     2009#else
     2010  if (free_value)
     2011    free (free_value);
    19752012#endif
    19762013
     
    20002037  register char *end;
    20012038  enum variable_flavor flavor = f_bogus;
    2002 #ifndef KMK
     2039#ifndef CONFIG_WITH_VALUE_LENGTH
    20032040  char *name;
    2004 #endif /* KMK - optimization */
     2041#endif
    20052042
    20062043  while (1)
     
    20862123
    20872124  /* Expand the name, so "$(foo)bar = baz" works.  */
    2088 #ifndef KMK
     2125#ifndef CONFIG_WITH_VALUE_LENGTH
    20892126  name = alloca (end - beg + 1);
    20902127  memcpy (name, beg, end - beg);
    20912128  name[end - beg] = '\0';
    20922129  v->name = allocated_variable_expand (name);
    2093 #else  /* KMK - optimizations */
    2094   //if (memchr (beg, '$', end - beg)) /* (Mostly for cleaning up the profiler result.) */
    2095       v->name = allocated_variable_expand_2 (beg, end - beg, NULL);
    2096   //else
    2097   //  {
    2098   //    v->name = memcpy (xmalloc (end - beg + 1), beg, end - beg);
    2099   //    v->name[end - beg] = '\0';
    2100   //  }
    2101 #endif /* KMK - optimizations */
     2130#else  /* CONFIG_WITH_VALUE_LENGTH */
     2131  v->name = allocated_variable_expand_2 (beg, end - beg, NULL);
     2132#endif /* CONFIG_WITH_VALUE_LENGTH */
    21022133
    21032134  if (v->name[0] == '\0')
Note: See TracChangeset for help on using the changeset viewer.