VirtualBox

Changeset 1811 in kBuild


Ignore:
Timestamp:
Oct 10, 2008 5:19:58 AM (16 years ago)
Author:
bird
Message:

kmk: More string length optimizations.

Location:
trunk/src/kmk
Files:
6 edited

Legend:

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

    r1809 r1811  
    28052805    /* Ignore plain `-' for compatibility.  */
    28062806    return;
     2807#ifndef CONFIG_WITH_VALUE_LENGTH
    28072808  v = try_variable_definition (0, arg, o_command, 0);
     2809#else
     2810  v = try_variable_definition (0, arg, NULL, o_command, 0);
     2811#endif
    28082812  if (v != 0)
    28092813    {
  • trunk/src/kmk/make.h

    r1793 r1811  
    386386char *next_token (const char *);
    387387char *end_of_token (const char *);
     388#ifndef CONFIG_WITH_VALUE_LENGTH
    388389void collapse_continuations (char *);
     390#else
     391char *collapse_continuations (char *, unsigned int);
     392#endif
    389393#ifdef CONFIG_WITH_OPTIMIZATION_HACKS /* memchr is usually compiler intrinsic, thus faster. */
    390394# define lindex(s, limit, c) ((char *)memchr((s), (c), (limit) - (s)))
  • trunk/src/kmk/misc.c

    r1535 r1811  
    2020#include "dep.h"
    2121#include "debug.h"
     22#ifdef CONFIG_WITH_VALUE_LENGTH
     23# include <assert.h>
     24#endif
    2225
    2326/* All bcopy calls in this file can be replaced by memcpy and save a tick or two. */
     
    8386   This is done by copying the text at LINE into itself.  */
    8487
     88#ifndef CONFIG_WITH_VALUE_LENGTH
    8589void
    8690collapse_continuations (char *line)
     91#else
     92char *
     93collapse_continuations (char *line, unsigned int linelen)
     94#endif
    8795{
    8896  register char *in, *out, *p;
     
    9098  register unsigned int bs_write;
    9199
     100#ifndef CONFIG_WITH_VALUE_LENGTH
    92101  in = strchr (line, '\n');
    93102  if (in == 0)
    94103    return;
     104#else
     105  assert (strlen (line) == linelen);
     106  in = memchr (line, '\n', linelen);
     107  if (in == 0)
     108      return line + linelen;
     109#endif
    95110
    96111  out = in;
     
    158173
    159174  *out = '\0';
     175#ifdef CONFIG_WITH_VALUE_LENGTH
     176  assert (strchr (line, '\0') == out);
     177  return out;
     178#endif
    160179}
    161180
  • trunk/src/kmk/read.c

    r1809 r1811  
    5454    char *bufnext;      /* Start of the next line in the buffer.  */
    5555    char *bufstart;     /* Start of the entire buffer.  */
     56#ifdef CONFIG_WITH_VALUE_LENGTH
     57    char *eol;          /* End of the current line in the buffer. */
     58#endif
    5659    unsigned int size;  /* Malloc'd size of buffer. */
    5760    FILE *fp;           /* File, or NULL if this is an internal buffer.  */
     
    149152static enum make_word_type get_next_mword (char *buffer, char *delim,
    150153                                           char **startp, unsigned int *length);
     154#ifndef CONFIG_WITH_VALUE_LENGTH
    151155static void remove_comments (char *line);
     156#else
     157static char *remove_comments (char *line, char *eol);
     158#endif
    152159static char *find_char_unquote (char *string, int stop1, int stop2,
    153160                                int blank, int ignorevars);
     
    430437  ebuf.size = 200;
    431438  ebuf.buffer = ebuf.bufnext = ebuf.bufstart = xmalloc (ebuf.size);
     439#ifdef CONFIG_WITH_VALUE_LENGTH
     440  ebuf.eol = NULL;
     441#endif
    432442
    433443  curfile = reading_file;
     
    464474  ebuf.buffer = ebuf.bufnext = ebuf.bufstart = buffer;
    465475  ebuf.fp = NULL;
     476#ifdef CONFIG_WITH_VALUE_LENGTH
     477  ebuf.eol = ebuf.buffer + ebuf.size;
     478#endif
    466479
    467480  ebuf.floc = *reading_file;
     
    546559    {
    547560      unsigned int linelen;
     561#ifdef CONFIG_WITH_VALUE_LENGTH
     562      char *eol;
     563#endif
    548564      char *line;
    549565      unsigned int wlen;
     
    564580        continue;
    565581
     582#ifndef CONFIG_WITH_VALUE_LENGTH
    566583      linelen = strlen (line);
     584#else
     585      linelen = ebuf->eol - line;
     586      assert (strlen (line) == linelen);
     587#endif
    567588
    568589      /* Check for a shell command line first.
     
    612633          collapsed = xmalloc (collapsed_length);
    613634        }
     635#ifndef CONFIG_WITH_VALUE_LENGTH
    614636      strcpy (collapsed, line);
    615637      /* Collapse continuation lines.  */
    616638      collapse_continuations (collapsed);
    617639      remove_comments (collapsed);
     640#else
     641      memcpy (collapsed, line, linelen + 1);
     642      /* Collapse continuation lines.  */
     643      eol = collapse_continuations (collapsed, linelen);
     644      assert (strchr (collapsed, '\0') == eol);
     645      eol = remove_comments (collapsed, eol);
     646      assert (strchr (collapsed, '\0') == eol);
     647#endif
    618648
    619649      /* Compare a word, both length and contents. */
     
    723753            }
    724754          else if (!ignoring
     755#ifndef CONFIG_WITH_VALUE_LENGTH
    725756                   && !try_variable_definition (fstart, p2, o_override, 0))
     757#else
     758                   && !try_variable_definition (fstart, p2, eol, o_override, 0))
     759#endif
    726760            error (fstart, _("invalid `override' directive"));
    727761
     
    757791            }
    758792          else if (!ignoring
     793# ifndef CONFIG_WITH_VALUE_LENGTH
    759794                   && !try_variable_definition (fstart, p2, o_local, 0))
     795# else
     796                   && !try_variable_definition (fstart, p2, eol, o_local, 0))
     797# endif
    760798            error (fstart, _("invalid `local' directive"));
    761799
     
    778816              struct variable *v;
    779817
     818#ifndef CONFIG_WITH_VALUE_LENGTH
    780819              v = try_variable_definition (fstart, p2, o_file, 0);
     820#else
     821              v = try_variable_definition (fstart, p2, eol, o_file, 0);
     822#endif
    781823              if (v != 0)
    782824                v->export = v_export;
     
    789831                  /* Expand the line so we can use indirect and constructed
    790832                     variable names in an export command.  */
    791                   cp = ap = allocated_variable_expand (p2);
     833                  cp = ap = allocated_variable_expand (p2); ///// FIXME
    792834
    793835                  for (p = find_next_token (&cp, &l); p != 0;
     
    819861              /* Expand the line so we can use indirect and constructed
    820862                 variable names in an unexport command.  */
    821               cp = ap = allocated_variable_expand (p2);
     863              cp = ap = allocated_variable_expand (p2); ///// FIXME
    822864
    823865              for (p = find_next_token (&cp, &l); p != 0;
     
    862904
    863905#ifdef CONFIG_WITH_INCLUDEDEP
     906      assert (strchr (p2, '\0') == eol);
    864907      if (word1eq ("includedep") || word1eq ("includedep-queue") || word1eq ("includedep-flush"))
    865908        {
     
    874917          char *free_me = NULL;
    875918          char *name = p2;
    876           char *end = strchr (name, '\0');
    877           char saved;
    878           if (memchr (name, '$', end - name))
     919
     920          if (memchr (name, '$', eol - name))
    879921            {
    880922              free_me = name = allocated_variable_expand (name);
    881923              while (isspace ((unsigned char)*name))
    882924                ++name;
    883               end = strchr (name, '\0');
     925              eol = strchr (name, '\0');
    884926            }
    885927
    886           while (end > name && isspace ((unsigned char)end[-1]))
    887             --end;
    888 
    889           saved = *end; /* not sure if this is required... */
    890           *end = '\0';
     928          while (eol > name && isspace ((unsigned char)eol[-1]))
     929            --eol;
     930
     931          *eol = '\0';
    891932          eval_include_dep (name, fstart, op);
    892           *end = saved;
    893933
    894934          if (free_me)
     
    909949          int noerror = (p[0] != 'i');
    910950
    911           p = allocated_variable_expand (p2);
     951          p = allocated_variable_expand (p2); //// FIXME
    912952
    913953          /* If no filenames, it's a no-op.  */
     
    956996        }
    957997
     998#ifndef CONFIG_WITH_VALUE_LENGTH
    958999      if (try_variable_definition (fstart, p, o_file, 0))
     1000#else
     1001      if (try_variable_definition (fstart, p, eol, o_file, 0))
     1002#endif
    9591003        /* This line has been dealt with.  */
    9601004        goto rule_complete;
     
    10041048        semip = cmdleft;
    10051049
     1050#ifndef CONFIG_WITH_VALUE_LENGTH
    10061051        collapse_continuations (line);
     1052#else
     1053        collapse_continuations (line, strlen (line)); /**@todo fix this */
     1054#endif
    10071055
    10081056        /* We can't expand the entire line, since if it's a per-target
     
    14111459   This is done by copying the text at LINE onto itself.  */
    14121460
     1461#ifndef CONFIG_WITH_VALUE_LENGTH
    14131462static void
    14141463remove_comments (char *line)
     1464#else
     1465static char *
     1466remove_comments (char *line, char *eol)
     1467#endif
    14151468{
    14161469  char *comment;
     
    14211474    /* Cut off the line at the #.  */
    14221475    *comment = '\0';
     1476
     1477#ifdef CONFIG_WITH_VALUE_LENGTH
     1478  if (comment)
     1479    eol = comment;
     1480  assert (strchr (line, '\0') == eol);
     1481  return eol;
     1482#endif
    14231483}
    14241484
     
    14611521      line = ebuf->buffer;
    14621522
     1523#ifndef CONFIG_WITH_VALUE_LENGTH
    14631524      collapse_continuations (line);
     1525#else
     1526      ebuf->eol = collapse_continuations (line, ebuf->eol - line);
     1527#endif
    14641528
    14651529      /* If the line doesn't begin with a tab, test to see if it introduces
     
    14701534        {
    14711535          p = next_token (line);
     1536#ifndef CONFIG_WITH_VALUE_LENGTH
    14721537          len = strlen (p);
     1538#else
     1539          len = ebuf->eol - p;
     1540          assert (len == strlen (p));
     1541#endif
    14731542
    14741543          /* If this is another 'define', increment the level count.  */
     
    14831552            {
    14841553              p += 5;
     1554#ifndef CONFIG_WITH_VALUE_LENGTH
    14851555              remove_comments (p);
     1556#else
     1557              ebuf->eol = remove_comments (p, ebuf->eol);
     1558#endif
    14861559              if (*next_token (p) != '\0')
    14871560                error (&ebuf->floc,
     
    15061579
    15071580      /* Otherwise add this line to the variable definition.  */
     1581#ifndef CONFIG_WITH_VALUE_LENGTH
    15081582      len = strlen (line);
     1583#else
     1584      len = ebuf->eol - line;
     1585      assert (len == strlen (line));
     1586#endif
    15091587      if (idx + len + 1 > length)
    15101588        {
     
    19602038          /* I don't think this can fail since we already determined it was a
    19612039             variable definition.  */
     2040#ifndef CONFIG_WITH_VALUE_LENGTH
    19622041          v = parse_variable_definition (&p->variable, defn);
     2042#else
     2043          v = parse_variable_definition (&p->variable, defn, NULL);
     2044#endif
    19632045          assert (v != 0);
    19642046
     
    19882070
    19892071          current_variable_set_list = f->variables;
     2072#ifndef CONFIG_WITH_VALUE_LENGTH
    19902073          v = try_variable_definition (flocp, defn, origin, 1);
     2074#else
     2075          v = try_variable_definition (flocp, defn, NULL, origin, 1);
     2076#endif
    19912077          if (!v)
    19922078            error (flocp, _("Malformed target-specific variable definition"));
     
    28362922        {
    28372923          ebuf->bufnext = ebuf->bufstart + ebuf->size + 1;
     2924#ifdef CONFIG_WITH_VALUE_LENGTH
     2925          ebuf->eol = end;
     2926#endif
    28382927          return 0;
    28392928        }
     
    28502939  *eol = '\0';
    28512940  ebuf->bufnext = eol+1;
     2941#ifdef CONFIG_WITH_VALUE_LENGTH
     2942  ebuf->eol = eol;
     2943#endif
    28522944
    28532945  return 0;
     
    28742966  end = p + ebuf->size;
    28752967  *p = '\0';
     2968#ifdef CONFIG_WITH_VALUE_LENGTH
     2969  ebuf->eol = p;
     2970#endif
    28762971
    28772972  while (fgets (p, end - p, ebuf->fp) != 0)
     
    29273022        {
    29283023          p[-1] = '\0';
     3024#ifdef CONFIG_WITH_VALUE_LENGTH
     3025          ebuf->eol = p - 1;
     3026#endif
    29293027          break;
    29303028        }
     
    29333031         another line.  */
    29343032      if (end - p >= 80)
    2935         continue;
     3033        {
     3034#ifdef CONFIG_WITH_VALUE_LENGTH
     3035          ebuf->eol = p;
     3036#endif
     3037          continue;
     3038        }
    29363039
    29373040      /* We need more space at the end of our buffer, so realloc it.
     
    29453048        end = start + ebuf->size;
    29463049        *p = '\0';
     3050#ifdef CONFIG_WITH_VALUE_LENGTH
     3051        ebuf->eol = p;
     3052#endif
    29473053      }
    29483054    }
     
    34933599  return new;
    34943600}
     3601
  • trunk/src/kmk/variable.c

    r1809 r1811  
    921921              else
    922922                {
     923#ifndef CONFIG_WITH_VALUE_LENGTH
    923924                  v = do_variable_definition (
    924925                    &p->variable.fileinfo, p->variable.name,
    925926                    p->variable.value, p->variable.origin,
    926927                    p->variable.flavor, 1);
     928#else
     929                  v = do_variable_definition_2 (
     930                    &p->variable.fileinfo, p->variable.name,
     931                    p->variable.value, p->variable.value_length, 0, 0,
     932                    p->variable.origin, p->variable.flavor, 1);
     933#endif
    927934                }
    928935
     
    20302037
    20312038struct variable *
     2039#ifndef CONFIG_WITH_VALUE_LENGTH
    20322040parse_variable_definition (struct variable *v, char *line)
     2041#else
     2042parse_variable_definition (struct variable *v, char *line, char *eos)
     2043#endif
    20332044{
    20342045  register int c;
     
    21192130  v->value = p;
    21202131#ifdef CONFIG_WITH_VALUE_LENGTH
    2121   v->value_length = v->value_alloc_len = -1;
     2132  v->value_alloc_len = -1;
     2133  v->value_length = eos != NULL ? eos - p : -1;
     2134  assert (eos == NULL || strchr (p, '\0') == eos);
    21222135#endif
    21232136
     
    21532166
    21542167struct variable *
     2168#ifndef CONFIG_WITH_VALUE_LENGTH
    21552169try_variable_definition (const struct floc *flocp, char *line,
    21562170                         enum variable_origin origin, int target_var)
     2171#else
     2172try_variable_definition (const struct floc *flocp, char *line, char *eos,
     2173                         enum variable_origin origin, int target_var)
     2174#endif
    21572175{
    21582176  struct variable v;
     
    21642182    v.fileinfo.filenm = 0;
    21652183
     2184#ifndef CONFIG_WITH_VALUE_LENGTH
    21662185  if (!parse_variable_definition (&v, line))
    21672186    return 0;
     
    21692188  vp = do_variable_definition (flocp, v.name, v.value,
    21702189                               origin, v.flavor, target_var);
     2190#else
     2191  if (!parse_variable_definition (&v, line, eos))
     2192    return 0;
     2193
     2194  vp = do_variable_definition_2 (flocp, v.name, v.value,
     2195                                 v.value_length != -1 ? v.value_length : ~0U,
     2196                                 0, NULL, origin, v.flavor, target_var);
     2197#endif
    21712198
    21722199  free (v.name);
  • trunk/src/kmk/variable.h

    r1809 r1811  
    191191                                         enum variable_flavor flavor,
    192192                                         int target_var);
     193struct variable *parse_variable_definition (struct variable *v, char *line);
     194struct variable *try_variable_definition (const struct floc *flocp, char *line,
     195                                          enum variable_origin origin,
     196                                          int target_var);
    193197#else  /* CONFIG_WITH_VALUE_LENGTH */
    194198# define do_variable_definition(flocp, varname, value, origin, flavor, target_var) \
     
    204208                                           enum variable_flavor flavor,
    205209                                           int target_var);
    206 #endif /* CONFIG_WITH_VALUE_LENGTH */
    207 struct variable *parse_variable_definition (struct variable *v, char *line);
     210struct variable *parse_variable_definition (struct variable *v, char *line,
     211                                            char *eos);
    208212struct variable *try_variable_definition (const struct floc *flocp, char *line,
     213                                          char *eos,
    209214                                          enum variable_origin origin,
    210215                                          int target_var);
     216#endif /* CONFIG_WITH_VALUE_LENGTH */
    211217void init_hash_global_variable_set (void);
    212218void hash_init_function_table (void);
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