Changeset 533 for trunk/src


Ignore:
Timestamp:
Sep 18, 2006, 5:02:39 AM (19 years ago)
Author:
bird
Message:

o Optimization summary: libc from ~21 seconds -> 7-8 seconds (os2/nt).
o Optimized appending new stuff to variables. (major win)
o Optimized variable memory value allocation avoiding a bunch of

unnecessary copying and allocating.

Location:
trunk/src/gmake
Files:
5 edited

Legend:

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

    r530 r533  
    2323    CONFIG_WITH_INCLUDEDEP \
    2424        CONFIG_WITH_TOUPPER_TOLOWER \
     25        KMK \
     26        \
     27        KMK_HELPERS \
     28        VARIABLE_HASH \
     29        CONFIG_WITH_OPTIMIZATION_HACKS \
    2530        CONFIG_WITH_VALUE_LENGTH \
    26         CONFIG_WITH_COMPARE \
    27         KMK \
    28         CONFIG_WITH_OPTIMIZATION_HACKS \
    29         VARIABLE_HASH
    30        
     31        CONFIG_WITH_COMPARE
     32
    3133kmk_SOURCES = \
    3234        main.c \
  • trunk/src/gmake/expand.c

    r530 r533  
    537537}
    538538
     539#ifdef CONFIG_WITH_VALUE_LENGTH
     540/* Expands the specified string, appending it to the specified variable value. */
     541void
     542append_expanded_string_to_variable (struct variable *v, char *value)
     543{
     544  char *p;
     545
     546  /* switch the variable buffer to the variable value buffer. */
     547  char *saved_buffer = variable_buffer;
     548  unsigned int saved_buffer_length = variable_buffer_length;
     549  variable_buffer = v->value;
     550  variable_buffer_length = v->value_alloc_len;
     551
     552  /* skip the current value and start appending a space and the expanded string. */
     553  p = v->value + v->value_length;
     554  if (v->value_length != 0)
     555      p = variable_buffer_output (p, " ", 1);
     556  p = variable_expand_string (p, value, (long)-1);
     557
     558  /* update the variable. (The variable_expand_string return is annoying!) */
     559  p = strchr (p, '\0');
     560  v->value = variable_buffer;
     561  v->value_length = p - v->value;
     562  v->value_alloc_len = variable_buffer_length;
     563
     564  /* restore the variable buffer. */
     565  variable_buffer = saved_buffer;
     566  variable_buffer_length = saved_buffer_length;
     567}
     568#endif /* CONFIG_WITH_VALUE_LENGTH */
    539569
    540570static char *
  • trunk/src/gmake/function.c

    r531 r533  
    3636#endif
    3737
    38 #ifdef KMK
     38#ifdef KMK_HELPERS
    3939# include "kbuild.h"
    4040#endif
     
    887887      char *result = 0;
    888888#ifdef CONFIG_WITH_VALUE_LENGTH
    889       if (len > (unsigned int)var->value_length)
     889      if (len >= (unsigned int)var->value_alloc_len)
    890890        {
    891891          free (var->value);
    892           var->value = xmalloc (len + 1);
     892          var->value_alloc_len = (len + 32) & ~31;
     893          var->value = xmalloc (var->value_alloc_len);
    893894        }
    894895      memcpy (var->value, p, len);
     
    23302331  { STRING_SIZE_TUPLE("comp-vars"),     3,  3,  1,  func_comp_vars},
    23312332#endif
    2332 #ifdef KMK
     2333#ifdef KMK_HELPERS
    23332334  { STRING_SIZE_TUPLE("kb-src-tool"),   1,  1,  0,  func_kbuild_source_tool},
    23342335  { STRING_SIZE_TUPLE("kb-obj-base"),   1,  1,  0,  func_kbuild_object_base},
  • trunk/src/gmake/variable.c

    r531 r533  
    364364          else
    365365            assert (value_length == strlen (value));
    366           v->value_length = value_length;
    367366          if (!duplicate_value)
    368367            {
     
    370369                free (v->value);
    371370              v->value = value;
     371              v->value_alloc_len = value_length + 1;
    372372            }
    373373          else
    374374            {
    375               v->value = xrealloc (v->value, v->value_length + 1);
    376               bcopy (value, v->value, v->value_length + 1);
     375              if ((unsigned int)v->value_alloc_len <= value_length)
     376                {
     377                  free (v->value);
     378                  v->value_alloc_len = (value_length + 0x40) & ~0x3f;
     379                  v->value = xmalloc (v->value_alloc_len);
     380                }
     381              memcpy (v->value, value, value_length + 1);
    377382            }
     383          v->value_length = value_length;
    378384#else
    379385          if (v->value != 0)
     
    408414  v->value_length = value_length;
    409415  if (!duplicate_value)
    410     v->value = value;
     416    {
     417      v->value_alloc_len = value_length + 1;
     418      v->value = value;
     419    }
    411420  else
    412421    {
    413       v->value = xmalloc (v->value_length + 1);
    414       bcopy (value, v->value, v->value_length + 1);
     422      v->value_alloc_len = (value_length + 32) & ~31;
     423      v->value = xmalloc (v->value_alloc_len);
     424      memcpy (v->value, value, value_length + 1);
    415425    }
    416426#else
     
    10751085#ifdef CONFIG_WITH_VALUE_LENGTH
    10761086      v->value_length = strlen (v->value);
     1087      v->value_alloc_len = v->value_length + 1;
    10771088#endif
    10781089    }
     
    12591270  return result_0;
    12601271}
     1272
     1273
     1274#ifdef CONFIG_WITH_VALUE_LENGTH
     1275static struct variable *
     1276do_variable_definition_append (const struct floc *flocp, struct variable *v, char *value,
     1277                               enum Variable_origin origin)
     1278{
     1279  if (env_overrides && origin == o_env)
     1280    origin = o_env_override;
     1281
     1282  if (env_overrides && v->origin == o_env)
     1283    /* V came from in the environment.  Since it was defined
     1284       before the switches were parsed, it wasn't affected by -e.  */
     1285    v->origin = o_env_override;
     1286
     1287  /* A variable of this name is already defined.
     1288     If the old definition is from a stronger source
     1289     than this one, don't redefine it.  */
     1290  if ((int) origin < (int) v->origin)
     1291    return v;
     1292  v->origin = origin;
     1293
     1294  /* location */
     1295  if (flocp != 0)
     1296    v->fileinfo = *flocp;
     1297
     1298  /* The juicy bits, append the specified value to the variable
     1299     This is a heavily exercied code path in kBuild. */
     1300  if (v->recursive)
     1301    {
     1302      /* The previous definition of the variable was recursive.
     1303         The new value is the unexpanded old and new values. */
     1304      unsigned int value_len = strlen (value);
     1305      unsigned int new_value_len = value_len + (v->value_length != 0 ? 1 + v->value_length : 0);
     1306
     1307      /* adjust the size. */
     1308      if ((unsigned)v->value_alloc_len <= new_value_len)
     1309        {
     1310          v->value_alloc_len = (new_value_len + 0x80) + 0x7f;
     1311          v->value = xrealloc (v->value, v->value_alloc_len);
     1312        }
     1313
     1314      /* insert the new bits */
     1315      if (v->value_length != 0)
     1316        {
     1317          v->value[v->value_length] = ' ';
     1318          memcpy (&v->value[v->value_length + 1], value, value_len + 1);
     1319        }
     1320      else
     1321          memcpy (v->value, value, value_len + 1);
     1322      v->value_length = new_value_len;
     1323    }
     1324  else
     1325    {
     1326      /* The previous definition of the variable was simple.
     1327         The new value comes from the old value, which was expanded
     1328         when it was set; and from the expanded new value. */
     1329      append_expanded_string_to_variable(v, value);
     1330    }
     1331
     1332  /* update the variable */
     1333  return v;
     1334}
     1335#endif /* CONFIG_WITH_VALUE_LENGTH */
    12611336
    12621337
     
    13351410        else
    13361411          {
     1412#ifdef CONFIG_WITH_VALUE_LENGTH
     1413            v->append = append;
     1414            return do_variable_definition_append (flocp, v, value, origin);
     1415#else /* !CONFIG_WITH_VALUE_LENGTH */
     1416
    13371417            /* Paste the old and new values together in VALUE.  */
    13381418
     
    13411421
    13421422            val = value;
    1343 #ifdef CONFIG_WITH_VALUE_LENGTH
    1344             if (v->recursive)
    1345               {
    1346                 /* The previous definition of the variable was recursive.
    1347                    The new value is the unexpanded old and new values. */
    1348                 flavor = f_recursive;
    1349                 oldlen = v->value_length; assert (oldlen == strlen (v->value));
    1350                 vallen = strlen (val);
    1351 
    1352                 value_len = oldlen + 1 + vallen;
    1353                 p = alloc_value = xmalloc (value_len + 1);
    1354                 memcpy (p, v->value, oldlen);
    1355                 p[oldlen] = ' ';
    1356                 memcpy (&p[oldlen + 1], val, vallen + 1);
    1357               }
    1358             else
    1359               {
    1360                 /* The previous definition of the variable was simple.
    1361                    The new value comes from the old value, which was expanded
    1362                    when it was set; and from the expanded new value.  Allocate
    1363                    memory for the expansion as we may still need the rest of the
    1364                    buffer if we're looking at a target-specific variable.  */
    1365                 char *buf;
    1366                 unsigned int len;
    1367                 install_variable_buffer (&buf, &len);
    1368 
    1369                 p = variable_buffer;
    1370                 if ( v->value && *v->value )
    1371                   {
    1372                     p = variable_buffer_output (p, v->value, v->value_length);
    1373                     p = variable_buffer_output (p, " ", 1);
    1374                   }
    1375                 p = variable_expand_string (p, val, (long)-1);
    1376 
    1377                 p = strchr (p, '\0'); /* returns adjusted start, not end. */
    1378                 alloc_value = variable_buffer;
    1379                 value_len = p - alloc_value;
    1380                 p = alloc_value;
    1381 
    1382                 variable_buffer = NULL; /* hackish */
    1383                 restore_variable_buffer (buf, len);
    1384               }
    1385 #else /* !CONFIG_WITH_VALUE_LENGTH */
    13861423            if (v->recursive)
    13871424              /* The previous definition of the variable was recursive.
     
    16431680  v->value = p;
    16441681#ifdef CONFIG_WITH_VALUE_LENGTH
    1645   v->value_length = -1;
     1682  v->value_length = v->value_alloc_len = -1;
    16461683#endif
    16471684
  • trunk/src/gmake/variable.h

    r531 r533  
    5959#ifdef CONFIG_WITH_VALUE_LENGTH
    6060    int value_length;           /* The length of the value, usually unused.  */
     61    int value_alloc_len;        /* The amount of memory we've actually allocated. */
     62    /* FIXME: make lengths unsigned! */
    6163#endif
    6264    char *value;                /* Variable value.  */
     
    128130extern void install_variable_buffer PARAMS ((char **bufp, unsigned int *lenp));
    129131extern void restore_variable_buffer PARAMS ((char *buf, unsigned int len));
     132#ifdef CONFIG_WITH_VALUE_LENGTH
     133extern void append_expanded_string_to_variable PARAMS ((struct variable *v, char *value));
     134#endif
    130135
    131136/* function.c */
Note: See TracChangeset for help on using the changeset viewer.