Branch: Tag:

2004-04-29

2004-04-29 19:23:20 by Martin Nilsson <mani@lysator.liu.se>

Another slight optimization of replace. Fixes for callablep on arrays. More documentation of interleave_array.

Rev: src/builtin_functions.c:1.543

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.542 2004/04/29 01:05:29 nilsson Exp $ + || $Id: builtin_functions.c,v 1.543 2004/04/29 19:23:20 nilsson Exp $   */      #include "global.h" - RCSID("$Id: builtin_functions.c,v 1.542 2004/04/29 01:05:29 nilsson Exp $"); + RCSID("$Id: builtin_functions.c,v 1.543 2004/04/29 19:23:20 nilsson Exp $");   #include "interpret.h"   #include "svalue.h"   #include "pike_macros.h"
3036:    return str;    }    -  v=(struct tupel *)xalloc(sizeof(struct tupel)*from->size); -  -  for(num=e=0;e<from->size;e++) -  { -  if(ITEM(from)[e].type != T_STRING) -  { -  free((char *)v); -  Pike_error("Replace: from array is not array(string)\n"); +  if(from->type_field & ~BIT_STRING) { +  array_fix_type_field(from); +  if(from->type_field & ~BIT_STRING) +  Pike_error("replace: from array not array(string).\n");    }    -  if(ITEM(to)[e].type != T_STRING) -  { -  free((char *)v); -  Pike_error("Replace: to array is not array(string)\n"); +  if(to->type_field & ~BIT_STRING) { +  array_fix_type_field(to); +  if(to->type_field & ~BIT_STRING) +  Pike_error("replace: to array not array(string).\n");    }    -  +  v=(struct tupel *)xalloc(sizeof(struct tupel)*from->size); +  +  for(num=e=0;e<from->size;e++) +  {    if(ITEM(from)[e].u.string->size_shift > str->size_shift)    continue;   
3158:    if(args < 3)    {    if (args==2 && -  Pike_sp[1-args].type==T_MAPPING) +  Pike_sp[-1].type==T_MAPPING)    { -  +  /* FIXME: Check that the mapping is string:string here, otherwise +  the error message will mention the from/to array. */    stack_dup();    f_indices(1);    stack_swap();
3516:    res = 1;    break;    case T_ARRAY: -  /* FIXME: This is not completely finished. E.g. ({ 0 }) is -  callable, but isn't reported as such. */ -  if( Pike_sp[-args].u.array->type_field & (BIT_CALLABLE) || -  !Pike_sp[-args].u.array->type_field) +  array_fix_type_field(Pike_sp[-args].u.array); +  if( (Pike_sp[-args].u.array->type_field==BIT_CALLABLE) || +  !Pike_sp[-args].u.array->type_field) {    res = 1; -  +  } +  else if( !(Pike_sp[-args].u.array->type_field & +  ~(BIT_CALLABLE|BIT_INT)) ) { +  struct array *a = Pike_sp[-args].u.array; +  int i; +  res = 1; +  for(i=0; i<a->size; i++) +  if( ITEM(a)[i].type == T_INT && ITEM(a)[i].u.integer ) { +  res = 0;    break;    } -  +  } +  break; +  }    pop_n_elems(args);    push_int(res);   }
4782:    *!    *! Interleave a sparse matrix.    *! -  *! Returns an array with offsets that describe how to interleave -  *! the rows of @[tab]. +  *! Returns an array with offsets that describe how to shift the +  *! rows of @[tab] so that only at most one non-zero value exists in +  *! every column.    */   static void f_interleave_array(INT32 args)   {