pike.git / src / mapping.c

version» Context lines:

pike.git/src/mapping.c:533: Inside #if defined(PIKE_DEBUG)
  #ifdef PIKE_DEBUG    if(md->refs <=0)    Pike_fatal("Zero refs in mapping->data\n");       if(d_flag>1) check_mapping(m);   #endif       /* NB: Code duplication from init_mapping(). */    if (hashsize & (hashsize - 1))    hashsize = find_next_power(hashsize); -  if ((md->hashsize == hashsize) && (md->refs == 1)) return m; +  if ((md->hashsize == hashsize) && (md->refs == 1) + #ifndef PIKE_MAPPING_KEYPAIR_LOOP +  && md->free_list + #endif +  ) return m;       init_mapping(m, hashsize, md->flags);    debug_malloc_touch(m);    new_md=m->data;       /* This operation is now 100% atomic - no locking required */    if(md->refs>1)    {    /* good */    /* More than one reference to the md ==> We need to
pike.git/src/mapping.c:891:   }      PMOD_EXPORT void low_mapping_insert(struct mapping *m,    const struct svalue *key,    const struct svalue *val,    int overwrite)   {    size_t h,h2;    struct keypair *k, **prev;    struct mapping_data *md, *omd; +  int md_too_small;      #ifdef PIKE_DEBUG    if(m->data->refs <=0)    Pike_fatal("Zero refs in mapping->data\n");   #endif       h2=hash_svalue(key);      #ifdef PIKE_DEBUG    if(d_flag>1) check_mapping(m);
pike.git/src/mapping.c:953:   #endif    return;       mi_insert:   #ifdef PIKE_DEBUG    if(m->data != md)    Pike_fatal("Wrong dataset in mapping_insert!\n");    if(d_flag>1) check_mapping(m);   #endif    free_mapping_data(md); -  /* We do a re-hash here instead of copying the mapping. */ -  if( +  +  md_too_small =   #ifndef PIKE_MAPPING_KEYPAIR_LOOP -  (!md->free_list) || +  (!md->free_list);   #else /* PIKE_MAPPING_KEYPAIR_LOOP */ -  (md->size >= md->num_keypairs) || +  (md->size >= md->num_keypairs);   #endif /* !PIKE_MAPPING_KEYPAIR_LOOP */ -  md->refs>1) +  +  /* We do a re-hash here instead of copying the mapping. */ +  if(md_too_small || md->refs>1)    { -  +  int base_hashsize = md->hashsize ? md->hashsize : AVG_LINK_LENGTH; +  int shift = md_too_small ? 1 : 0;    debug_malloc_touch(m); -  rehash(m, md->hashsize?(md->hashsize<<1):AVG_LINK_LENGTH); +  rehash(m, base_hashsize << shift);    md=m->data;    }    h=h2 & ( md->hashsize - 1);       /* no need to lock here since we are not calling is_eq - Hubbe */       k=md->free_list;   #ifndef PIKE_MAPPING_KEYPAIR_LOOP    md->free_list=k->next;   #else /* PIKE_MAPPING_KEYPAIR_LOOP */
pike.git/src/mapping.c:1011:   /* Inline the above in this file. */   #define mapping_insert(M, KEY, VAL) low_mapping_insert ((M), (KEY), (VAL), 1)      PMOD_EXPORT union anything *mapping_get_item_ptr(struct mapping *m,    const struct svalue *key,    TYPE_T t)   {    size_t h, h2;    struct keypair *k, **prev;    struct mapping_data *md,*omd; +  int md_too_small;      #ifdef PIKE_DEBUG    if(m->data->refs <=0)    Pike_fatal("Zero refs in mapping->data\n");       if(d_flag>1) check_mapping(m);       debug_malloc_touch(m);    debug_malloc_touch(m->data);   #endif
pike.git/src/mapping.c:1077: Inside #if defined(PIKE_DEBUG)
  #ifdef PIKE_DEBUG    if(m->data != md)    Pike_fatal("Wrong dataset in mapping_get_item_ptr!\n");    if(d_flag)    check_mapping(m);   #endif    free_mapping_data(md);       if(t != T_INT) return 0;    -  /* no need to call PREPARE_* because we re-hash instead */ -  if( +  md_too_small =   #ifndef PIKE_MAPPING_KEYPAIR_LOOP -  !(md->free_list) || +  !(md->free_list);   #else /* PIKE_MAPPING_KEYPAIR_LOOP */ -  (md->size >= md->num_keypairs) || +  (md->size >= md->num_keypairs);   #endif /* !PIKE_MAPPING_KEYPAIR_LOOP */ -  md->refs>1) +  +  /* no need to call PREPARE_* because we re-hash instead */ +  if(md_too_small || md->refs>1)    { -  +  int base_hashsize = md->hashsize ? md->hashsize : AVG_LINK_LENGTH; +  int shift = md_too_small ? 1 : 0;    debug_malloc_touch(m); -  rehash(m, md->hashsize?(md->hashsize<<1):AVG_LINK_LENGTH); +  rehash(m, base_hashsize << shift);    md=m->data;    }    h=h2 & ( md->hashsize - 1);       k=md->free_list;   #ifndef PIKE_MAPPING_KEYPAIR_LOOP    md->free_list=k->next;   #else /* PIKE_MAPPING_KEYPAIR_LOOP */    md->free_list++;   #endif /* !PIKE_MAPPING_KEYPAIR_LOOP */