Branch: Tag:

2001-05-31

2001-05-31 22:16:37 by Henrik Grubbström (Grubba) <grubba@grubba.org>

Fixed optimizer bug in handling of replace(). Fixes [bug 1711 (#1711)]

Rev: src/builtin_functions.c:1.370
Rev: src/testsuite.in:1.419

5:   \*/   /**/   #include "global.h" - RCSID("$Id: builtin_functions.c,v 1.369 2001/05/22 12:09:27 per Exp $"); + RCSID("$Id: builtin_functions.c,v 1.370 2001/05/31 22:16:37 grubba Exp $");   #include "interpret.h"   #include "svalue.h"   #include "pike_macros.h"
3266:    }   }    + node *optimize_replace(node *n) + { +  node **arg0 = my_get_arg(&_CDR(n), 0); +  struct pike_type *array_zero; +  struct pike_type *mapping_zero; +  +  MAKE_CONSTANT_TYPE(array_zero, tArr(tZero)); +  MAKE_CONSTANT_TYPE(mapping_zero, tMap(tZero, tZero)); +  +  if (arg0 && +  (pike_types_le(array_zero, (*arg0)->type) || +  pike_types_le(mapping_zero, (*arg0)->type))) { +  /* First argument might be an array or a mapping. +  * +  * replace() is destructive on arrays and mappings. +  */ +  n->node_info |= OPT_SIDE_EFFECT; +  n->tree_info |= OPT_SIDE_EFFECT; +  } +  return NULL; + } +    /*! @decl program compile(string source, object|void handler, @    *! int|void major, int|void minor)    *!
7792:    ADD_EFUN("random_string",f_random_string,    tFunc(tInt,tString),0);    -  ADD_EFUN("replace",f_replace, +  ADD_EFUN2("replace", f_replace,    tOr5(tFunc(tStr tStr tStr,tStr),    tFunc(tStr tArr(tStr) tArr(tStr),tStr),    tFunc(tStr tMap(tStr,tStr),tStr),    tFunc(tSetvar(0,tArray) tMix tMix,tVar(0)), -  tFunc(tSetvar(1,tMapping) tMix tMix,tVar(1))) , 0); +  tFunc(tSetvar(1,tMapping) tMix tMix,tVar(1))), +  OPT_TRY_OPTIMIZE, optimize_replace, 0);      /* function(int:int)|function(string:string)|function(0=array:0) */    ADD_EFUN("reverse",f_reverse,