Changeset 1931 for trunk/src


Ignore:
Timestamp:
Oct 24, 2008, 9:02:48 PM (17 years ago)
Author:
bird
Message:

kmk: recycle more allocate_variable_expand_* results.

Location:
trunk/src/kmk
Files:
3 edited

Legend:

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

    r1929 r1931  
    6060};
    6161struct recycled_buffer *recycled_head;
    62 static char *
    63 allocated_variable_expand_3 (const char *line, unsigned int length,
    64                              unsigned int *value_lenp,
    65                              unsigned int *buffer_lengthp);
    66 static void
    67 recycle_variable_buffer (char *buffer, unsigned int length);
    68 
    69 #endif
     62#endif /* CONFIG_WITH_VALUE_LENGTH */
    7063
    7164
     
    10711064}
    10721065
    1073 /* Handles a special case for variable_expand_string2 where the variable
    1074    name is expanded.  This variant allows the variable_buffer to
    1075    be recycled and thus avoid bothering with a slow free implementation
    1076    (darwin is horrible here).  */
    1077 
    1078 static char *
     1066/* Initially created for handling a special case for variable_expand_string2
     1067   where the variable name is expanded and freed right afterwards.  This
     1068   variant allows the variable_buffer to be recycled and thus avoid bothering
     1069   with a slow free implementation. (Darwin is horrible slow.)  */
     1070
     1071char *
    10791072allocated_variable_expand_3 (const char *line, unsigned int length,
    10801073                             unsigned int *value_lenp,
     
    10901083
    10911084  value = variable_expand_string_2 (NULL, line, len, &eol);
    1092   *value_lenp = eol - value;
     1085  if (value_lenp)
     1086    *value_lenp = eol - value;
    10931087  *buffer_lengthp = variable_buffer_length;
    10941088
     
    11001094
    11011095/* recycle a buffer. */
    1102 static void
     1096
     1097void
    11031098recycle_variable_buffer (char *buffer, unsigned int length)
    11041099{
     
    11331128restore_variable_buffer (char *buf, unsigned int len)
    11341129{
     1130#ifndef CONFIG_WITH_VALUE_LENGTH
    11351131  free (variable_buffer);
     1132#else
     1133  if (variable_buffer)
     1134    recycle_variable_buffer (variable_buffer, variable_buffer_length);
     1135#endif
    11361136
    11371137  variable_buffer = buf;
  • trunk/src/kmk/read.c

    r1930 r1931  
    905905                  cp = ap = allocated_variable_expand (p2);
    906906#else
    907                   cp = ap = allocated_variable_expand_2 (p2, eol - p2, NULL);
     907                  unsigned int buf_len;
     908                  cp = ap = allocated_variable_expand_3 (p2, eol - p2, NULL, &buf_len);
    908909#endif
    909910
     
    917918                    }
    918919
     920#ifndef CONFIG_WITH_VALUE_LENGTH
    919921                  free (ap);
     922#else
     923                  recycle_variable_buffer (ap, buf_len);
     924#endif
    920925                }
    921926            }
     
    939944              cp = ap = allocated_variable_expand (p2);
    940945#else
    941               cp = ap = allocated_variable_expand_2 (p2, eol - p2, NULL);
     946              unsigned int buf_len;
     947              cp = ap = allocated_variable_expand_3 (p2, eol - p2, NULL, &buf_len);
    942948#endif
    943949
     
    952958                }
    953959
     960#ifndef CONFIG_WITH_VALUE_LENGTH
    954961              free (ap);
     962#else
     963              recycle_variable_buffer (ap, buf_len);
     964#endif
    955965            }
    956966          goto rule_complete;
     
    9951005                            ? incdep_queue : incdep_flush;
    9961006          char *free_me = NULL;
     1007          unsigned int buf_len;
    9971008          char *name = p2;
    9981009
     
    10001011            {
    10011012              unsigned int name_len;
    1002               free_me = name = allocated_variable_expand_2 (name, eol - name, &name_len);
     1013              free_me = name = allocated_variable_expand_3 (name, eol - name, &name_len, &buf_len);
    10031014              eol = name + name_len;
    10041015              while (isspace ((unsigned char)*name))
     
    10131024
    10141025          if (free_me)
    1015             free (free_me);
     1026            recycle_variable_buffer (free_me, buf_len);
    10161027          goto rule_complete;
    10171028        }
     
    10321043          p = allocated_variable_expand (p2);
    10331044#else
    1034           p = allocated_variable_expand_2 (p2, eol - p2, NULL);
     1045          unsigned int buf_len;
     1046          p = allocated_variable_expand_3 (p2, eol - p2, NULL, &buf_len);
    10351047#endif
    10361048
     
    10381050          if (*p == '\0')
    10391051            {
     1052#ifndef CONFIG_WITH_VALUE_LENGTH
    10401053              free (p);
     1054#else
     1055              recycle_variable_buffer (p, buf_len);
     1056#endif
    10411057              continue;
    10421058            }
     
    10531069                              &nameseq_cache);
    10541070#endif
     1071#ifndef CONFIG_WITH_VALUE_LENGTH
    10551072          free (p);
     1073#else
     1074          recycle_variable_buffer (p, buf_len);
     1075#endif
    10561076
    10571077          /* Save the state of conditionals and start
  • trunk/src/kmk/variable.h

    r1927 r1931  
    192192# define allocated_variable_expand(line) \
    193193  allocated_variable_expand_2 (line, -1, NULL)
    194 char *allocated_variable_expand_2(const char *line, unsigned int length, unsigned int *value_lenp);
     194char *allocated_variable_expand_2 (const char *line, unsigned int length, unsigned int *value_lenp);
     195char *allocated_variable_expand_3 (const char *line, unsigned int length,
     196                                   unsigned int *value_lenp, unsigned int *buffer_lengthp);
     197void recycle_variable_buffer (char *buffer, unsigned int length);
    195198#endif /* CONFIG_WITH_VALUE_LENGTH */
    196199char *expand_argument (const char *str, const char *end);
Note: See TracChangeset for help on using the changeset viewer.