Ignore:
Timestamp:
Sep 18, 2006, 1:49:49 AM (19 years ago)
Author:
bird
Message:

skip some unnecessary copies and allocations.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/gmake/kbuild.c

    r530 r531  
    5151kbuild_get_variable(const char *pszName)
    5252{
     53#ifndef NDEBUG
     54    unsigned i;
     55#endif
    5356    struct variable *pVar = lookup_variable(pszName, strlen(pszName));
    5457    if (!pVar)
     
    5659    if (pVar->recursive)
    5760        fatal(NILF, _("variable `%s' is defined as `recursive' instead of `simple'!"), pszName);
    58     pVar->value_length = strlen(pVar->value);
     61#ifndef NDEBUG
     62    i = strlen(pVar->value);
     63    if (i != pVar->value_length)
     64    {
     65        printf("%d != %d %s\n", pVar->value_length, i, pVar->name);
     66        __asm int 3;
     67    }
     68#endif
    5969    return pVar;
    6070}
     
    7080kbuild_get_recursive_variable(const char *pszName)
    7181{
     82#ifndef NDEBUG
     83    unsigned i;
     84#endif
    7285    struct variable *pVar = lookup_variable(pszName, strlen(pszName));
    7386    if (!pVar)
    7487        fatal(NILF, _("variable `%s' isn't defined!"), pszName);
    75     pVar->value_length = strlen(pVar->value);
     88#ifndef NDEBUG
     89    i = strlen(pVar->value);
     90    if (i != pVar->value_length)
     91    {
     92        printf("%d != %d %s\n", pVar->value_length, i, pVar->name);
     93        __asm int 3;
     94    }
     95#endif
    7696    return pVar;
    7797}
     
    90110    struct variable *pVar = lookup_variable(pszName, strlen(pszName));
    91111    if (pVar)
    92         pVar->value_length = strlen(pVar->value);
     112    {
     113#ifndef NDEBUG
     114        unsigned i = strlen(pVar->value);
     115        if (i != pVar->value_length)
     116        {
     117            printf("%d != %d %s\n", pVar->value_length, i, pVar->name);
     118            __asm int 3;
     119        }
     120#endif
     121    }
    93122    return pVar;
    94123}
     
    230259            *pszEnd = '\0';
    231260            if (!strchr(pszEnd, '$'))
    232                 pVar = define_variable(pszVarName, strlen(pszVarName), psz, o_file, 0 /* !recursive */);
     261                pVar = define_variable_vl(pszVarName, strlen(pszVarName), psz, pszEnd - psz,
     262                                          1 /* duplicate */, o_file, 0 /* !recursive */);
    233263            else
    234264            {
     
    244274                {
    245275                    *pszExpEnd = '\0';
    246                     pVar = define_variable(pszVarName, strlen(pszVarName), pszExp, o_file, 0 /* !recursive */);
     276                    pVar = define_variable_vl(pszVarName, strlen(pszVarName), pszExp,
     277                                              pszExpEnd - pszExp, 1 /* duplicate */,
     278                                              o_file, 0 /* !recursive */);
    247279                }
    248280                else
     
    362394        + pszSrcEnd - pszSrc
    363395        + 1;
    364     psz = pszResult = alloca(cch);
     396    psz = pszResult = xmalloc(cch);
    365397
    366398    memcpy(psz, pPathTarget->value, pPathTarget->value_length); psz += pPathTarget->value_length;
     
    374406     * Define the variable in the current set and return it.
    375407     */
    376     return define_variable(pszVarName, strlen(pszVarName), pszResult, o_file, 0 /* !recursive */);
     408    return define_variable_vl(pszVarName, strlen(pszVarName), pszResult, cch - 1,
     409                              0 /* use pszResult */, o_file, 0 /* !recursive */);
    377410}
    378411
     
    440473            *pszEnd = '\0';
    441474            if (!strchr(pszEnd, '$'))
    442                 pVar = define_variable(pszVarName, strlen(pszVarName), psz, o_file, 0 /* !recursive */);
     475                pVar = define_variable_vl(pszVarName, strlen(pszVarName), psz, pszEnd - psz,
     476                                          1 /* duplicate */, o_file, 0 /* !recursive */);
    443477            else
    444478            {
     
    454488                {
    455489                    *pszExpEnd = '\0';
    456                     pVar = define_variable(pszVarName, strlen(pszVarName), pszExp, o_file, 0 /* !recursive */);
     490                    pVar = define_variable_vl(pszVarName, strlen(pszVarName), pszExp,
     491                                              pszExpEnd - pszExp, 1 /* duplicate */,
     492                                              o_file, 0 /* !recursive */);
    457493                }
    458494                else
     
    954990            free(paVars[iVar].pszExp);
    955991    }
    956     psz[-(cchTotal != 0)] = '\0';
    957 
    958     pVar = define_variable(pszVarName, strlen(pszVarName), pszResult, o_file, 0 /* !recursive */);
    959     free(pszResult);
     992    if (psz != pszResult)
     993        psz--;
     994    *psz = '\0';
     995    cchTotal = psz - pszResult;
     996
     997    pVar = define_variable_vl(pszVarName, strlen(pszVarName), pszResult, cchTotal,
     998                              0 /* take pszResult */ , o_file, 0 /* !recursive */);
    960999    return pVar;
    9611000}
     
    10211060    memcpy(psz, pObjSuff->value, pObjSuff->value_length);   psz += pObjSuff->value_length;
    10221061    memcpy(psz, pDepSuff->value, pDepSuff->value_length + 1);
    1023     *ppDep = define_variable("dep", 3, pszResult, o_file, 0 /* !recursive */);
     1062    *ppDep = define_variable_vl("dep", 3, pszResult, cch - 1, 1 /*dup*/, o_file, 0 /* !recursive */);
    10241063
    10251064    /*
     
    10271066     */
    10281067    *psz = '\0';
    1029     pObj = define_variable(pszVarName, strlen(pszVarName), pszResult, o_file, 0 /* !recursive */);
     1068    pObj = define_variable_vl(pszVarName, strlen(pszVarName), pszResult, psz - pszResult,
     1069                              1/* dup */, o_file, 0 /* !recursive */);
    10301070
    10311071    /*
     
    10771117
    10781118    /* set global variable */
    1079     define_variable_global(pszName, cch, pszResult, o_file, 0 /* !recursive */, NILF);
     1119    define_variable_vl_global(pszName, cch, pszResult, psz - pszResult, 1/*dup*/, o_file, 0 /* !recursive */, NILF);
    10801120
    10811121    /*
     
    10921132        *psz = '\0';
    10931133    }
    1094     *ppDirDep = define_variable("dirdep", 6, pszResult, o_file, 0 /* !recursive */);
     1134    *ppDirDep = define_variable_vl("dirdep", 6, pszResult, psz - pszResult, 1/*dup*/, o_file, 0 /* !recursive */);
    10951135
    10961136    return pObj;
Note: See TracChangeset for help on using the changeset viewer.