Ignore:
Timestamp:
Oct 10, 2008, 4:27:38 AM (17 years ago)
Author:
bird
Message:

kmk: More length and alloc optimizations. Made all the length optimizations from yesterday CONFIG_WITH_VALUE_LENGTH instead of KMK.

File:
1 edited

Legend:

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

    r1808 r1809  
    228228  char *o;
    229229  unsigned int line_offset;
    230 #ifdef KMK
     230#ifdef CONFIG_WITH_VALUE_LENGTH
    231231  const char *eos;
    232232#endif
     
    248248    }
    249249
    250 #ifdef KMK
     250#ifdef CONFIG_WITH_VALUE_LENGTH
    251251  /* Simple first, 50% of the kBuild calls to this function does
    252252     not need any expansion at all. Should be worth a special case. */
     
    261261    }
    262262  eos = string + length;
    263 #endif /* KMK - optimization */
     263#endif /* CONFIG_WITH_VALUE_LENGTH */
    264264
    265265  /* If we want a subset of the string, allocate a temporary buffer for it.
     
    270270      memcpy(abuf, string, length);
    271271      abuf[length] = '\0';
    272 #ifdef KMK
     272#ifdef CONFIG_WITH_VALUE_LENGTH
    273273      p1 += abuf - string;
    274274      eos += abuf - string;
    275 #endif /* KMK - optimization */
     275#endif /* CONFIG_WITH_VALUE_LENGTH */
    276276      string = abuf;
    277277    }
     
    284284         at the next $ or the end of the input.  */
    285285
    286 #ifndef KMK
     286#ifndef CONFIG_WITH_VALUE_LENGTH
    287287      p1 = strchr (p, '$');
    288 #endif /* !KMK - optimization  */
     288#endif
    289289
    290290      o = variable_buffer_output (o, p, p1 != 0 ? (unsigned int)(p1 - p) : strlen (p) + 1);
     
    327327               If so, expand it before expanding the entire reference.  */
    328328
    329 #ifndef KMK
     329#ifndef CONFIG_WITH_VALUE_LENGTH
    330330            end = strchr (beg, closeparen);
    331 #else  /* KMK - optimization */
     331#else
    332332            end = memchr (beg, closeparen, eos - beg);
    333 #endif /* KMK - optimization */
     333#endif
    334334            if (end == 0)
    335335              /* Unterminated variable reference.  */
     
    470470      else
    471471        ++p;
    472 #ifdef KMK
     472#ifdef CONFIG_WITH_VALUE_LENGTH
    473473      p1 = memchr (p, '$', eos - p);
    474 #endif /* KMK - optimization */
     474#endif
    475475    }
    476476
     
    481481  return (variable_buffer + line_offset);
    482482}
    483 #ifdef KMK
     483#ifdef CONFIG_WITH_VALUE_LENGTH
    484484
    485485
     
    494494  char *o;
    495495  unsigned int line_offset;
    496 #ifdef KMK
     496#ifdef CONFIG_WITH_VALUE_LENGTH
    497497  const char *eos;
    498498#endif
     
    514514    }
    515515
    516 #ifdef KMK
     516#ifdef CONFIG_WITH_VALUE_LENGTH
    517517  /* Simple first, 50% of the kBuild calls to this function does
    518518     not need any expansion at all. Should be worth a special case. */
     
    528528    }
    529529  eos = string + length;
    530 #endif /* KMK - optimization */
     530#endif /* CONFIG_WITH_VALUE_LENGTH */
    531531
    532532  /* If we want a subset of the string, allocate a temporary buffer for it.
     
    537537      memcpy(abuf, string, length);
    538538      abuf[length] = '\0';
    539 #ifdef KMK
     539#ifdef CONFIG_WITH_VALUE_LENGTH
    540540      p1 += abuf - string;
    541541      eos += abuf - string;
     
    551551         at the next $ or the end of the input.  */
    552552
    553 #ifndef KMK
     553#ifndef CONFIG_WITH_VALUE_LENGTH
    554554      p1 = strchr (p, '$');
    555 #endif /* !KMK */
     555#endif
    556556
    557557      /*o = variable_buffer_output (o, p, p1 != 0 ? (unsigned int)(p1 - p) : strlen (p) + 1); - why +1 ? */
     
    595595               If so, expand it before expanding the entire reference.  */
    596596
    597 #ifndef KMK
     597#ifndef CONFIG_WITH_VALUE_LENGTH
    598598            end = strchr (beg, closeparen);
    599 #else  /* KMK - optimization */
     599#else
    600600            end = memchr (beg, closeparen, eos - beg);
    601 #endif /* KMK - optimization */
     601#endif
    602602            if (end == 0)
    603603              /* Unterminated variable reference.  */
     
    738738      else
    739739        ++p;
    740 #ifdef KMK
     740#ifdef CONFIG_WITH_VALUE_LENGTH
    741741      p1 = memchr (p, '$', eos - p);
    742 #endif /* KMK - optimization */
     742#endif
    743743    }
    744744
     
    750750  return (variable_buffer + line_offset);
    751751}
    752 #endif /* KMK - optimization */
     752#endif /* CONFIG_WITH_VALUE_LENGTH */
    753753
    754754
     
    904904#endif
    905905
    906 #ifndef KMK
    907 # ifdef CONFIG_WITH_VALUE_LENGTH
    908   buf = variable_expand_string (buf, v->value, v->value_length);
    909 # else
     906#ifdef CONFIG_WITH_VALUE_LENGTH
     907  variable_expand_string_2 (buf, v->value, v->value_length, &buf);
     908  return buf;
     909#else
    910910  buf = variable_expand_string (buf, v->value, strlen (v->value));
    911 # endif
    912911  return (buf + strlen (buf));
    913 #else  /* KMK - optimization */
    914 # ifdef CONFIG_WITH_VALUE_LENGTH
    915   variable_expand_string_2 (buf, v->value, v->value_length, &buf);
    916 # else
    917   variable_expand_string_2 (buf, v->value, strlen (v->value), &buf);
    918 #  error "huh, this is supposed to be defined"
    919 # endif
    920   assert (*buf == '\0');
    921   return buf;
    922 #endif /* KMK - optimization */
    923 }
    924 
    925 #ifdef CONFIG_WITH_VALUE_LENGTH
    926 /* Expands the specified string, appending it to the specified variable value. */
     912#endif
     913}
     914
     915#ifdef CONFIG_WITH_VALUE_LENGTH
     916/* Expands the specified string, appending it to the specified
     917   variable value. */
    927918void
    928 append_expanded_string_to_variable (struct variable *v, const char *value, int append)
    929 {
    930 char *tmp;
    931   unsigned int value_len = strlen (value);
     919append_expanded_string_to_variable (struct variable *v, const char *value,
     920                                    unsigned int value_len, int append)
     921{
    932922  char *p = (char *) memchr (value, '$', value_len);
    933923  if (!p)
     
    955945          /* Append the assignment value. */
    956946          p = variable_buffer_output (p, value, off_dollar);
    957 # ifndef KMK
    958           p = variable_expand_string (p, value + off_dollar, value_len - off_dollar);
    959           p = strchr (p, '\0');
    960 # else
    961           tmp = variable_expand_string_2 (p, value + off_dollar, value_len - off_dollar, &p);
    962           assert (*p == '\0');
    963           tmp = strchr (tmp, '\0');
    964           assert (tmp == p);
    965 # endif
     947          variable_expand_string_2 (p, value + off_dollar, value_len - off_dollar, &p);
    966948        }
    967949      else
     
    969951          /* Expand the assignemnt value. */
    970952          p = variable_buffer_output (p, value, off_dollar);
    971 #ifndef KMK
    972           p = variable_expand_string (p, value + off_dollar, value_len - off_dollar);
    973           p = strchr (p, '\0');
    974 #else
    975           tmp = variable_expand_string_2 (p, value + off_dollar, value_len - off_dollar, &p);
    976           assert (*p == '\0');
    977           tmp = strchr (tmp, '\0');
    978           assert (tmp == p);
    979 #endif
     953          variable_expand_string_2 (p, value + off_dollar, value_len - off_dollar, &p);
    980954
    981955          /* Append a space followed by the old value. */
     
    10461020}
    10471021
    1048 #ifdef KMK /* possible optimization... */
    1049 /* The special, and most comment case, of
    1050    allocated_variable_expand_for_file. */
     1022#ifdef CONFIG_WITH_VALUE_LENGTH
     1023/* Handle the most common case in allocated_variable_expand_for_file
     1024   specially and provide some additional string lenght features. */
    10511025
    10521026char *
    1053 allocated_variable_expand_2 (const char *line, long length, unsigned int *value_len)
     1027allocated_variable_expand_2 (const char *line, unsigned int length,
     1028                             unsigned int *value_len)
    10541029{
    10551030  char *value;
     
    10591034  variable_buffer = 0;
    10601035
    1061 #if 0 /* for profiling */
    1062   if (length < 0)
    1063     length = strlen (line);
    1064 #endif
    1065 
    10661036  if (!value_len)
    1067     value = variable_expand_string (NULL, line, length);
     1037    value = variable_expand_string (NULL, line, length != ~0U ? length : -1);
    10681038  else
    10691039    {
    10701040      char *eol;
    1071       value = variable_expand_string_2 (NULL, line, length, &eol);
     1041      value = variable_expand_string_2 (NULL, line,
     1042                                        length != ~0U ? length : -1, &eol);
    10721043      *value_len = eol - value;
    10731044    }
     
    10781049  return value;
    10791050}
    1080 
    1081 #endif
     1051#endif /* CONFIG_WITH_VALUE_LENGTH */
     1052
    10821053/* Install a new variable_buffer context, returning the current one for
    10831054   safe-keeping.  */
Note: See TracChangeset for help on using the changeset viewer.