pike.git / src / mapping.c

version» Context lines:

pike.git/src/mapping.c:1:   /*   || 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: mapping.c,v 1.207 2008/06/27 11:32:39 grubba Exp $ + || $Id: mapping.c,v 1.208 2008/06/28 21:37:34 grubba Exp $   */      #include "global.h"   #include "main.h"   #include "object.h"   #include "mapping.h"   #include "svalue.h"   #include "array.h"   #include "pike_macros.h"   #include "pike_error.h"
pike.git/src/mapping.c:1507:    struct mapping_data *a_md = a->data;    struct mapping_data *b_md = b->data;    INT32 e;    ONERROR err;       /* First some special cases. */    if (!a_md->size) return copy_mapping(b);    if (!b_md->size) return copy_mapping(a);    if (a_md == b_md) return copy_mapping(a);    +  if (a_md->size <= b_md->size) {    /* Copy the second mapping. */    res = copy_mapping(b);    SET_ONERROR(err, do_free_mapping, res);       /* Add elements in a that aren't in b. */    NEW_MAPPING_LOOP(a_md) {    size_t h = k->hval % b_md->hashsize;    struct keypair *k2;    for (k2 = b_md->hash[h]; k2; k2 = k2->next) {    if ((k2->hval == k->hval) && is_eq(&k2->ind, &k->ind)) {    break;    }    }    if (!k2) {    mapping_insert(res, &k->ind, &k->val);    }    }    UNSET_ONERROR(err); -  +  } else { +  /* Copy the first mapping. */ +  res = copy_mapping(a); +  SET_ONERROR(err, do_free_mapping, res); +  +  /* Add all elements in b. */ +  NEW_MAPPING_LOOP(b_md) { +  mapping_insert(res, &k->ind, &k->val); +  } +  UNSET_ONERROR(err); +  }    return res;   }      static struct mapping *xor_mappings(struct mapping *a, struct mapping *b)   {    struct mapping *res;    struct keypair *k;    struct mapping_data *a_md = a->data;    struct mapping_data *b_md = b->data;    INT32 e;