VirtualBox

Changeset 1927 in kBuild for trunk/src


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

kmk: Inlined much of handle_function/lookup_function so variable_expand_string_2 can avoid having to make the call for every variable it encounters. Also fixed the func_char_map generation.

Location:
trunk/src/kmk
Files:
2 edited

Legend:

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

    r1880 r1927  
    549549            op = o;
    550550            begp = p;
    551             if (handle_function (&op, &begp, eos))
     551            end = may_be_function_name (p + 1, eos);
     552            if (    end
     553                &&  handle_function (&op, &begp, end, eos))
    552554              {
    553555                o = op;
     
    766768  memcpy (tmp, str, end - str);
    767769  tmp[end - str] = '\0';
     770  return allocated_variable_expand (tmp);
    768771#else  /* CONFIG_WITH_VALUE_LENGTH */
    769772  if (!end)
  • trunk/src/kmk/variable.h

    r1889 r1927  
    217217int handle_function (char **op, const char **stringp);
    218218#else
    219 int handle_function (char **op, const char **stringp, const char *eol);
     219int handle_function (char **op, const char **stringp, const char *nameend, const char *eol);
    220220#endif
    221221int pattern_matches (const char *pattern, const char *percent, const char *str);
     
    230230char *func_commands (char *o, char **argv, const char *funcname);
    231231#endif
     232#if defined (CONFIG_WITH_VALUE_LENGTH)
     233/* Avoid calling handle_function for every variable, do the
     234   basic checks in variable_expand_string_2. */
     235extern char func_char_map[256];
     236# define MAX_FUNCTION_LENGTH    12
     237# define MIN_FUNCTION_LENGTH    2
     238MY_INLINE const char *
     239may_be_function_name (const char *name, const char *eos)
     240{
     241  unsigned char ch;
     242  unsigned int len = name - eos;
     243
     244  /* Minimum length is MIN + whitespace. Check this directly.
     245     ASSUMES: MIN_FUNCTION_LENGTH == 2 */
     246
     247  if (MY_PREDICT_TRUE(len < MIN_FUNCTION_LENGTH + 1
     248                      || !func_char_map[(int)(name[0])]
     249                      || !func_char_map[(int)(name[1])]))
     250    return 0;
     251  if (MY_PREDICT_TRUE(!func_char_map[ch = name[2]]))
     252    return isspace (ch) ? name + 2 : 0;
     253
     254  name += 3;
     255  if (len > MAX_FUNCTION_LENGTH)
     256    len = MAX_FUNCTION_LENGTH - 3;
     257  else if (len == 3)
     258    len -= 3;
     259  if (!len)
     260    return 0;
     261
     262  /* Loop over the remaining possiblities. */
     263
     264  while (func_char_map[ch = *name])
     265    {
     266      if (!len--)
     267        return 0;
     268      name++;
     269    }
     270  if (ch == '\0' || isblank (ch))
     271    return name;
     272  return 0;
     273}
     274#endif /* CONFIG_WITH_VALUE_LENGTH */
    232275
    233276/* expand.c */
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette