Ignore:
Timestamp:
Oct 11, 2008, 12:56:20 PM (17 years ago)
Author:
bird
Message:

kmk: more insane optimizations.

File:
1 edited

Legend:

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

    r1827 r1830  
    127127extern char *variable_buffer;
    128128extern struct variable_set_list *current_variable_set_list;
     129#ifdef KMK
     130extern unsigned int variable_buffer_length;
     131#define VARIABLE_BUFFER_ZONE    5
     132#endif
    129133
    130134/* expand.c */
     135#ifndef KMK
    131136char *variable_buffer_output (char *ptr, const char *string, unsigned int length);
     137#else /* KMK */
     138/* Subroutine of variable_expand and friends:
     139   The text to add is LENGTH chars starting at STRING to the variable_buffer.
     140   The text is added to the buffer at PTR, and the updated pointer into
     141   the buffer is returned as the value.  Thus, the value returned by
     142   each call to variable_buffer_output should be the first argument to
     143   the following call.  */
     144
     145__inline static char *
     146variable_buffer_output (char *ptr, const char *string, unsigned int length)
     147{
     148  register unsigned int newlen = length + (ptr - variable_buffer);
     149
     150  if ((newlen + VARIABLE_BUFFER_ZONE) > variable_buffer_length)
     151    {
     152      unsigned int offset = ptr - variable_buffer;
     153      variable_buffer_length = variable_buffer_length <= 1024
     154                             ? 2048 : variable_buffer_length * 4;
     155      if (variable_buffer_length < newlen + 100)
     156          variable_buffer_length = (newlen + 100 + 1023) & ~1023U;
     157      variable_buffer = xrealloc (variable_buffer, variable_buffer_length);
     158      ptr = variable_buffer + offset;
     159    }
     160
     161# ifndef _MSC_VER
     162  switch (length)
     163    {
     164      case 4: ptr[3] = string[3];
     165      case 3: ptr[2] = string[2];
     166      case 2: ptr[1] = string[1];
     167      case 1: ptr[0] = string[0];
     168      case 0:
     169          break;
     170      default:
     171          memcpy (ptr, string, length);
     172          break;
     173    }
     174# else
     175  memcpy (ptr, string, length);
     176# endif
     177  return ptr + length;
     178}
     179
     180#endif /* KMK */
    132181char *variable_expand (const char *line);
    133182char *variable_expand_for_file (const char *line, struct file *file);
Note: See TracChangeset for help on using the changeset viewer.