Branch: Tag:

2003-04-27

2003-04-27 16:17:33 by Martin Stjernholm <mast@lysator.liu.se>

Separated the low level stuff in f_column into a new array_column and fixed
type field handling. Fixed type field handling in aggregate_array.

Rev: src/array.c:1.141
Rev: src/array.h:1.48
Rev: src/builtin.cmod:1.133

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: array.c,v 1.140 2003/04/26 16:22:26 mast Exp $ + || $Id: array.c,v 1.141 2003/04/27 16:17:33 mast Exp $   */      #include "global.h"
26:   #include "cyclic.h"   #include "multiset.h"    - RCSID("$Id: array.c,v 1.140 2003/04/26 16:22:26 mast Exp $"); + RCSID("$Id: array.c,v 1.141 2003/04/27 16:17:33 mast Exp $");      PMOD_EXPORT struct array empty_array=   {
190:    free_array(v);   }    + /* Is destructive on data if it only has one ref. */ + PMOD_EXPORT struct array *array_column (struct array *data, struct svalue *index) + { +  int e; +  struct array *a; +  TYPE_FIELD types = 0; +  +  DECLARE_CYCLIC(); +  +  /* Optimization */ +  if(data->refs == 1) +  { +  /* An array with one ref cannot possibly be cyclic */ +  struct svalue sval; +  data->type_field = BIT_MIXED | BIT_UNFINISHED; +  for(e=0;e<data->size;e++) +  { +  index_no_free(&sval, ITEM(data)+e, index); +  types |= 1 << sval.type; +  free_svalue(ITEM(data)+e); +  move_svalue (ITEM(data) + e, &sval); +  } +  data->type_field = types; +  return data; +  } +  +  if((a=(struct array *)BEGIN_CYCLIC(data,0))) +  { +  add_ref(a); +  }else{ +  push_array(a=allocate_array(data->size)); +  SET_CYCLIC_RET(a); +  +  for(e=0;e<a->size;e++) { +  index_no_free(ITEM(a)+e, ITEM(data)+e, index); +  types |= 1 << ITEM(a)[e].type; +  } +  a->type_field = types; +  +  dmalloc_touch_svalue(Pike_sp-1); +  Pike_sp--; +  } +  END_CYCLIC(); +  +  return a; + } +    PMOD_EXPORT void simple_array_index_no_free(struct svalue *s,    struct array *a,struct svalue *ind)   {
214:       case T_STRING:    { -  check_stack(4); -  ref_push_array(a); -  assign_svalue_no_free(Pike_sp++,ind); -  f_column(2); -  Pike_sp--; -  *s = *Pike_sp; -  dmalloc_touch_svalue(Pike_sp); +  s->type = T_ARRAY; +  s->u.array = array_column (a, ind);    break;    }   
1861:    struct array *a;       a=allocate_array_no_init(args,0); +  if (args) {    MEMCPY((char *)ITEM(a),(char *)(Pike_sp-args),args*sizeof(struct svalue)); -  a->type_field=BIT_MIXED; +  array_fix_type_field (a);    Pike_sp-=args;    DO_IF_DMALLOC(while(args--) dmalloc_touch_svalue(Pike_sp + args)); -  +  }    return a;   }