Ignore:
Timestamp:
Sep 17, 2006, 10:38:57 PM (19 years ago)
Author:
bird
Message:

Added kBuild specific functions for speeding up source processing.

File:
1 edited

Legend:

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

    r527 r530  
    1717Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.  */
    1818
     19#ifdef CONFIG_WITH_OPTIMIZATION_HACKS
     20# include <assert.h>
     21#endif
    1922#include "make.h"
    2023#include "filedef.h"
     
    3235# include "pathstuff.h"
    3336#endif
    34 #include <assert.h> /* bird */
     37
     38#ifdef KMK
     39# include "kbuild.h"
     40#endif
    3541
    3642
     
    265271   it can't be function and we can skip the hash lookup drop out. */
    266272
    267 #define MAX_FUNCTION_LENGTH 10 /* bird */
     273#ifdef KMK
     274# define MAX_FUNCTION_LENGTH 12
     275#else
     276# define MAX_FUNCTION_LENGTH 10
     277#endif
    268278
    269279/* Look up a function by name.  */
     
    14111421  /* Copy its value into the output buffer without expanding it.  */
    14121422  if (v)
     1423#ifdef CONFIG_WITH_VALUE_LENGTH
     1424    o = variable_buffer_output (o, v->value,
     1425                                v->value_length >= 0 ? v->value_length : strlen(v->value));
     1426#else
    14131427    o = variable_buffer_output (o, v->value, strlen(v->value));
     1428#endif
    14141429
    14151430  return o;
     
    21172132}
    21182133#endif /* CONFIG_WITH_TOUPPER_TOLOWER */
     2134
     2135#if defined(CONFIG_WITH_VALUE_LENGTH) && defined(CONFIG_WITH_COMPARE)
     2136/* Returns empty string if equal, returns the third arg if not equal. */
     2137static char *
     2138func_comp_vars (char *o, char **argv, const char *funcname)
     2139{
     2140  const char *s1, *e1, *x1, *s2, *e2, *x2;
     2141  char *a1 = NULL, *a2 = NULL;
     2142  size_t l, l1, l2;
     2143  struct variable *var1 = lookup_variable (argv[0], strlen (argv[0]));
     2144  struct variable *var2 = lookup_variable (argv[1], strlen (argv[1]));
     2145
     2146  /* the simple cases */
     2147  if (var1 == var2)
     2148    return variable_buffer_output (o, "", 1);       /* eq */
     2149  if (!var1 || !var2)
     2150    return variable_buffer_output (o, argv[2], strlen(argv[2]));
     2151  if (var1->value == var2->value)
     2152    return variable_buffer_output (o, "", 1);       /* eq */
     2153  if (!var1->recursive && !var2->recursive)
     2154  {
     2155    if (    var1->value_length == var2->value_length
     2156        &&  !memcmp (var1->value, var2->value, var1->value_length))
     2157      return variable_buffer_output (o, "", 1);     /* eq */
     2158
     2159    /* ignore trailing and leading blanks */
     2160    s1 = var1->value;
     2161    while (isblank ((unsigned char) *s1))
     2162      s1++;
     2163    e1 = s1 + var1->value_length;
     2164    while (e1 > s1 && isblank ((unsigned char) e1[-1]))
     2165      e1--;
     2166
     2167    s2 = var2->value;
     2168    while (isblank ((unsigned char) *s2))
     2169      s2++;
     2170    e2 = s2 + var2->value_length;
     2171    while (e2 > s2 && isblank ((unsigned char) e2[-1]))
     2172      e2--;
     2173
     2174    if (e1 - s1 != e2 - s2)
     2175      return variable_buffer_output (o, "", 1);     /* eq */
     2176l_simple_compare:
     2177    if (!memcmp (s1, s2, e1 - s1))
     2178      return variable_buffer_output (o, "", 1);     /* eq */
     2179    return variable_buffer_output (o, argv[2], strlen(argv[2]));
     2180  }
     2181
     2182  /* ignore trailing and leading blanks */
     2183  s1 = var1->value;
     2184  e1 = s1 + var1->value_length;
     2185  while (isblank ((unsigned char) *s1))
     2186    s1++;
     2187  while (e1 > s1 && isblank ((unsigned char) e1[-1]))
     2188    e1--;
     2189
     2190  s2 = var2->value;
     2191  e2 = s2 + var2->value_length;
     2192  while (isblank((unsigned char)*s2))
     2193    s2++;
     2194  while (e2 > s2 && isblank ((unsigned char) e2[-1]))
     2195    e2--;
     2196
     2197  /* both empty after stripping? */
     2198  if (s1 == e1 && s2 == e2)
     2199    return variable_buffer_output (o, "", 1);       /* eq */
     2200
     2201  /* optimist. */
     2202  if (   e1 - s1 == e2 - s2
     2203      && !memcmp(s1, s2, e1 - s1))
     2204    return variable_buffer_output (o, "", 1);       /* eq */
     2205
     2206  /* compare up to the first '$' or the end. */
     2207  x1 = var1->recursive ? memchr (s1, '$', e1 - s1) : NULL;
     2208  x2 = var2->recursive ? memchr (s2, '$', e2 - s2) : NULL;
     2209  if (!x1 && !x2)
     2210    return variable_buffer_output (o, argv[2], strlen (argv[2]));
     2211
     2212  l1 = x1 ? x1 - s1 : e1 - s1;
     2213  l2 = x2 ? x2 - s2 : e2 - s2;
     2214  l = l1 <= l2 ? l1 : l2;
     2215  if (l && memcmp (s1, s2, l))
     2216      return variable_buffer_output (o, argv[2], strlen (argv[2]));
     2217
     2218  /* one or both buffers now require expanding. */
     2219  if (!x1)
     2220    s1 += l;
     2221  else
     2222    {
     2223      s1 = a1 = allocated_variable_expand ((char *)s1 + l);
     2224      if (!l)
     2225        while (isblank ((unsigned char) *s1))
     2226          s1++;
     2227      e1 = strchr (s1, '\0'); /*hmm*/
     2228      while (e1 > s1 && isblank ((unsigned char) e1[-1]))
     2229        e1--;
     2230    }
     2231
     2232  if (!x2)
     2233    s2 += l;
     2234  else
     2235    {
     2236      s2 = a2 = allocated_variable_expand ((char *)s2 + l);
     2237      if (!l)
     2238        while (isblank ((unsigned char) *s2))
     2239          s2++;
     2240      e2 = strchr (s2, '\0'); /*hmm*/
     2241      while (e2 > s2 && isblank ((unsigned char) e2[-1]))
     2242        e2--;
     2243    }
     2244
     2245  /* the final compare */
     2246  l = (   e1 - s1 != e2 - s2
     2247       || memcmp (s1, s2, e1 - s1));
     2248  if (a1)
     2249    free (a1);
     2250  if (a2)
     2251    free (a2);
     2252  if (l)
     2253    return variable_buffer_output (o, "", 1);
     2254  return variable_buffer_output (o, argv[2], strlen (argv[2]));
     2255}
     2256#endif
    21192257
    21202258/* Lookup table for builtin functions.
     
    21792317  { STRING_SIZE_TUPLE("tolower"),       0,  1,  1,  func_toupper_tolower},
    21802318#endif
     2319#if defined(CONFIG_WITH_VALUE_LENGTH) && defined(CONFIG_WITH_COMPARE)
     2320  { STRING_SIZE_TUPLE("comp-vars"),     3,  3,  1,  func_comp_vars},
     2321#endif
     2322#ifdef KMK
     2323  { STRING_SIZE_TUPLE("kb-src-tool"),   1,  1,  0,  func_kbuild_source_tool},
     2324  { STRING_SIZE_TUPLE("kb-obj-base"),   1,  1,  0,  func_kbuild_object_base},
     2325  { STRING_SIZE_TUPLE("kb-obj-suff"),   1,  1,  0,  func_kbuild_object_suffix},
     2326  { STRING_SIZE_TUPLE("kb-src-prop"),   3,  3,  0,  func_kbuild_source_prop},
     2327  { STRING_SIZE_TUPLE("kb-src-one"),    1,  1,  0,  func_kbuild_source_one},
     2328#endif
    21812329};
    21822330
Note: See TracChangeset for help on using the changeset viewer.