Ignore:
Timestamp:
Oct 9, 2008, 7:36:19 AM (17 years ago)
Author:
bird
Message:

kmk: More memchr and less strlen for simple assignments (var:=val).

File:
1 edited

Legend:

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

    r1805 r1808  
    228228  char *o;
    229229  unsigned int line_offset;
     230#ifdef KMK
     231  const char *eos;
     232#endif
    230233
    231234  if (!line)
     
    245248    }
    246249
     250#ifdef KMK
    247251  /* Simple first, 50% of the kBuild calls to this function does
    248252     not need any expansion at all. Should be worth a special case. */
    249 #ifdef KMK
    250   if (length > 0)
    251     {
    252       p1 = (const char *)memchr (string, '$', length);
    253       if (p1 == 0)
    254         {
    255           if (string[length] == '\0')
    256             o = variable_buffer_output (o, string, length);
    257           else
    258             o = variable_buffer_output (o, string, length);
    259           variable_buffer_output (o, "\0", 2);
    260           return (variable_buffer + line_offset);
    261         }
    262     }
    263   else
    264     {
    265       p1 = strchr (string, '$');
    266       if (p1 == 0)
    267       {
    268           length = strlen (string);
    269           o = variable_buffer_output (o, string, length);
    270           variable_buffer_output (o, "\0", 2);
    271           return (variable_buffer + line_offset);
    272       }
    273     }
     253  if (length < 0)
     254    length = strlen (string);
     255  p1 = (const char *)memchr (string, '$', length);
     256  if (p1 == 0)
     257    {
     258      o = variable_buffer_output (o, string, length);
     259      variable_buffer_output (o, "\0", 2);
     260      return (variable_buffer + line_offset);
     261    }
     262  eos = string + length;
    274263#endif /* KMK - optimization */
    275264
     
    283272#ifdef KMK
    284273      p1 += abuf - string;
     274      eos += abuf - string;
    285275#endif /* KMK - optimization */
    286276      string = abuf;
     
    337327               If so, expand it before expanding the entire reference.  */
    338328
     329#ifndef KMK
    339330            end = strchr (beg, closeparen);
     331#else  /* KMK - optimization */
     332            end = memchr (beg, closeparen, eos - beg);
     333#endif /* KMK - optimization */
    340334            if (end == 0)
    341335              /* Unterminated variable reference.  */
     
    477471        ++p;
    478472#ifdef KMK
    479       p1 = strchr (p, '$');
     473      p1 = memchr (p, '$', eos - p);
    480474#endif /* KMK - optimization */
    481475    }
     
    500494  char *o;
    501495  unsigned int line_offset;
     496#ifdef KMK
     497  const char *eos;
     498#endif
    502499
    503500  if (!line)
     
    517514    }
    518515
     516#ifdef KMK
    519517  /* Simple first, 50% of the kBuild calls to this function does
    520518     not need any expansion at all. Should be worth a special case. */
    521 #ifdef KMK
    522   if (length > 0)
    523     {
    524       p1 = (const char *)memchr (string, '$', length);
    525       if (p1 == 0)
    526         {
    527           if (string[length] == '\0')
    528             o = variable_buffer_output (o, string, length);
    529           else
    530             o = variable_buffer_output (o, string, length);
    531           o = variable_buffer_output (o, "\0", 2);
    532           *eol = o - 2;
    533           return (variable_buffer + line_offset);
    534         }
    535     }
    536   else
    537     {
    538       p1 = strchr (string, '$');
    539       if (p1 == 0)
    540       {
    541           length = strlen (string);
    542           o = variable_buffer_output (o, string, length + 1);
    543           o = variable_buffer_output (o, "\0", 2);
    544           *eol = o - 2;
    545           return (variable_buffer + line_offset);
    546       }
    547     }
    548 #endif /* KMK */
     519  if (length < 0)
     520    length = strlen (string);
     521  p1 = (const char *)memchr (string, '$', length);
     522  if (p1 == 0)
     523    {
     524      o = variable_buffer_output (o, string, length);
     525      o = variable_buffer_output (o, "\0", 2);
     526      *eol = o - 2;
     527      return (variable_buffer + line_offset);
     528    }
     529  eos = string + length;
     530#endif /* KMK - optimization */
    549531
    550532  /* If we want a subset of the string, allocate a temporary buffer for it.
     
    557539#ifdef KMK
    558540      p1 += abuf - string;
     541      eos += abuf - string;
    559542#endif
    560543      string = abuf;
     
    612595               If so, expand it before expanding the entire reference.  */
    613596
     597#ifndef KMK
    614598            end = strchr (beg, closeparen);
     599#else  /* KMK - optimization */
     600            end = memchr (beg, closeparen, eos - beg);
     601#endif /* KMK - optimization */
    615602            if (end == 0)
    616603              /* Unterminated variable reference.  */
     
    752739        ++p;
    753740#ifdef KMK
    754       p1 = strchr (p, '$');
    755 #endif
     741      p1 = memchr (p, '$', eos - p);
     742#endif /* KMK - optimization */
    756743    }
    757744
     
    10641051
    10651052char *
    1066 allocated_variable_expand_2 (const char *line, long length)
     1053allocated_variable_expand_2 (const char *line, long length, unsigned int *value_len)
    10671054{
    10681055  char *value;
     
    10771064#endif
    10781065
    1079   value = variable_expand_string (NULL, line, length);
     1066  if (!value_len)
     1067    value = variable_expand_string (NULL, line, length);
     1068  else
     1069    {
     1070      char *eol;
     1071      value = variable_expand_string_2 (NULL, line, length, &eol);
     1072      *value_len = eol - value;
     1073    }
    10801074
    10811075  variable_buffer = obuf;
Note: See TracChangeset for help on using the changeset viewer.