VirtualBox

Changeset 1929 in kBuild


Ignore:
Timestamp:
Oct 24, 2008 6:17:28 AM (16 years ago)
Author:
bird
Message:

kmk/read.c: more free() avoidance, this time some very small buffers for conditionals. Use static buffers for the first chunk, this avoids all alloc/free for a typical kBuild run. the cost is 16 bytes of stack per recursion.

Location:
trunk/src/kmk
Files:
2 edited

Legend:

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

    r1928 r1929  
    10081008  variable_buffer = 0;
    10091009
    1010   assert (v->length == strlen (v->name));
     1010  assert ((unsigned int)v->length == strlen (v->name));
    10111011  val = variable_append (v->name, strlen (v->name), current_variable_set_list);
    10121012  variable_buffer_output (val, "", 1);
  • trunk/src/kmk/read.c

    r1911 r1929  
    8686                                   2=already interpreted */
    8787    char *seen_else;            /* Have we already seen an `else'?  */
     88#ifdef KMK
     89    char ignoring_first[8];
     90    char seen_else_first[8];
     91#endif
    8892  };
    8993
     94#ifdef KMK
     95static struct conditionals toplevel_conditionals =
     96{
     97    0,
     98    sizeof (toplevel_conditionals.ignoring_first),
     99    &toplevel_conditionals.ignoring_first[0],
     100    &toplevel_conditionals.seen_else_first[0],
     101    "", ""
     102};
     103#else /* !KMK */
    90104static struct conditionals toplevel_conditionals;
     105#endif /* !KMK */
    91106static struct conditionals *conditionals = &toplevel_conditionals;
    92107
     
    331346  struct conditionals *save = conditionals;
    332347
     348#ifndef KMK
    333349  memset (new, '\0', sizeof (*new));
     350#else  /* KMK */
     351  new->if_cmds   = 0;
     352  new->allocated = sizeof (new->ignoring_first);
     353  new->ignoring  = new->ignoring_first;
     354  new->seen_else = new->seen_else_first;
     355#endif /* KMK */
    334356  conditionals = new;
    335357
     
    343365{
    344366  /* Free any space allocated by conditional_line.  */
    345   if (conditionals->ignoring)
    346     free (conditionals->ignoring);
    347   if (conditionals->seen_else)
    348     free (conditionals->seen_else);
     367#ifdef KMK
     368  if (conditionals->allocated > sizeof (conditionals->ignoring_first))
     369#endif
     370    {
     371      if (conditionals->ignoring)
     372        free (conditionals->ignoring);
     373      if (conditionals->seen_else)
     374        free (conditionals->seen_else);
     375    }
    349376
    350377  /* Restore state.  */
     
    19251952    }
    19261953
     1954#ifndef KMK
    19271955  if (conditionals->allocated == 0)
    19281956    {
     
    19311959      conditionals->seen_else = xmalloc (conditionals->allocated);
    19321960    }
     1961#endif
    19331962
    19341963  o = conditionals->if_cmds++;
    19351964  if (conditionals->if_cmds > conditionals->allocated)
    19361965    {
    1937       conditionals->allocated += 5;
    1938       conditionals->ignoring = xrealloc (conditionals->ignoring,
    1939                                          conditionals->allocated);
    1940       conditionals->seen_else = xrealloc (conditionals->seen_else,
    1941                                           conditionals->allocated);
     1966#ifdef KMK
     1967#if 0
     1968      if (conditionals->allocated == 0)
     1969        {
     1970          conditionals->allocated = sizeof (conditionals->ignoring_first);
     1971          conditionals->ignoring  = conditionals->ignoring_first;
     1972          conditionals->seen_else = conditionals->seen_else_first;
     1973        }
     1974      else
     1975#endif
     1976      if (conditionals->allocated <= sizeof (conditionals->ignoring_first))
     1977        {
     1978          assert (conditionals->allocated == sizeof (conditionals->ignoring_first));
     1979          conditionals->allocated += 16;
     1980          conditionals->ignoring = xmalloc (conditionals->allocated);
     1981          memcpy (conditionals->ignoring, conditionals->ignoring_first,
     1982                  sizeof (conditionals->ignoring_first));
     1983          conditionals->seen_else = xmalloc (conditionals->allocated);
     1984          memcpy (conditionals->seen_else, conditionals->seen_else_first,
     1985                  sizeof (conditionals->seen_else_first));
     1986        }
     1987      else
     1988        {
     1989          conditionals->allocated *= 2;
     1990#else  /* !KMK */
     1991          conditionals->allocated += 5;
     1992#endif /* !KMK */
     1993          conditionals->ignoring = xrealloc (conditionals->ignoring,
     1994                                             conditionals->allocated);
     1995          conditionals->seen_else = xrealloc (conditionals->seen_else,
     1996                                              conditionals->allocated);
     1997#ifdef KMK
     1998        }
     1999#endif
    19422000    }
    19432001
     
    29162974  const char *p = *string;
    29172975  char *new = 0;
    2918   int slen;
     2976  int slen = 0;
    29192977
    29202978  /* If the first char is a % return now.  This lets us avoid extra tests
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette