VirtualBox

Changeset 1843 in kBuild for trunk/src/kmk


Ignore:
Timestamp:
Oct 12, 2008 3:40:32 PM (16 years ago)
Author:
bird
Message:

kmk/strcache: align the strings on a (somewhat) natural boundrary and offer a service for retrieving their length (which we also store now).

Location:
trunk/src/kmk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kmk/make.h

    r1842 r1843  
    504504const char *strcache_add_len (const char *str, int len);
    505505int strcache_setbufsize (int size);
     506#ifdef CONFIG_WITH_VALUE_LENGTH
     507MY_INLINE unsigned int strcache_get_len (const char *str)
     508{
     509  unsigned int len = ((unsigned int *)str)[-1];
     510  MY_ASSERT_MSG (strcache_iscached (str), ("\n"));
     511  MY_ASSERT_MSG (strlen (str) == len, ("\n"));
     512  return len;
     513}
     514#endif
    506515
    507516#ifdef  HAVE_VFORK_H
  • trunk/src/kmk/strcache.c

    r1793 r1843  
    6767  struct strcache *sp;
    6868  const char *res;
     69#ifdef CONFIG_WITH_VALUE_LENGTH
     70  int str_len = len;
     71  char *tmp;
     72
     73  /* Add space a length prefix and the terminator and assure
     74     (somewhat) natural alignment. */
     75  len += sizeof(unsigned int) + 1;
     76  len = (len + sizeof(void *) - 1) & ~(sizeof(void *) - 1);
     77  --len;
     78#endif
    6979
    7080  /* If the string we want is too large to fit into a single buffer, then
     
    8898
    8999  /* Add the string to the best cache.  */
     100#ifndef CONFIG_WITH_VALUE_LENGTH
    90101  res = best->end;
    91102  memcpy (best->end, str, len);
     
    94105  best->bytesfree -= len + 1;
    95106  ++best->count;
    96 
     107#else  /* CONFIG_WITH_VALUE_LENGTH */
     108  tmp = best->end;
     109  best->end += len + 1;
     110  assert(!((size_t)tmp & (sizeof(void *) - 1)));
     111
     112  *(unsigned int *)tmp = str_len; /* length prefix */
     113  tmp += sizeof(unsigned int);
     114
     115  res = tmp;
     116  memcpy (tmp, str, str_len);
     117  tmp += str_len;
     118  do
     119    *(tmp++) = '\0';
     120  while (tmp < best->end);
     121
     122  best->bytesfree -= len + 1;
     123  ++best->count;
     124
     125  assert (tmp == best->end);
     126  assert (!((size_t)res & (sizeof(void *) - 1)));
     127#endif /* CONFIG_WITH_VALUE_LENGTH */
    97128  return res;
    98129}
Note: See TracChangeset for help on using the changeset viewer.

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