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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.