Branch: Tag:

2006-03-11

2006-03-11 17:45:37 by Henrik Grubbström (Grubba) <grubba@grubba.org>

optimize_replace() now actually uses single_string_replace_program.

Rev: src/builtin_functions.c:1.615

2:   || This file is part of Pike. For copyright information see COPYRIGHT.   || Pike is distributed under GPL, LGPL and MPL. See the file COPYING   || for more information. - || $Id: builtin_functions.c,v 1.614 2006/03/11 17:19:46 grubba Exp $ + || $Id: builtin_functions.c,v 1.615 2006/03/11 17:45:37 grubba Exp $   */      #include "global.h"
3761:    */    node **arg1 = my_get_arg(&_CDR(n), 1);    node **arg2 = my_get_arg(&_CDR(n), 2); +  struct program *replace_compiler = NULL;       if (arg1 && ((pike_types_le((*arg1)->type, array_type_string) &&    arg2 &&
3773:    * replace(string, array, string)    * replace(string, mapping(string:string))    */ -  if (!is_const(*arg0) && is_const(*arg1) && (!arg2 || is_const(*arg2))) { -  /* The second and third arguments are constants. */ +  extern struct program *multi_string_replace_program; +  replace_compiler = multi_string_replace_program; +  } else if (arg1 && pike_types_le((*arg1)->type, string_type_string) && +  arg2 && pike_types_le((*arg2)->type, string_type_string)) { +  extern struct program *single_string_replace_program; +  replace_compiler = single_string_replace_program; +  } +  if (replace_compiler && !is_const(*arg0) && is_const(*arg1) && +  (!arg2 || is_const(*arg2))) { +  /* The second and third (if any) arguments are constants. */    struct svalue *save_sp = Pike_sp;    JMP_BUF tmp;    if (SETJMP(tmp)) {
3790:    }    free_svalue(&thrown);    } else { -  extern struct program *multi_string_replace_program; +     INT16 lfun;    struct object *replace_obj;    node *ret = NULL;
3800:    args += eval_low(*arg2,1);    }    -  replace_obj = clone_object(multi_string_replace_program, args); +  replace_obj = clone_object(replace_compiler, args);       push_object(replace_obj);    if (replace_obj->prog &&
3824:    pop_n_elems(Pike_sp - save_sp);    }    } -  } +        free_type(array_zero);    free_type(mapping_zero);