static void rehash_indirect_table(indirect_table *tab) { if ( TIGHT(tab->table, tab) ) { indirect_buckets *oldtab = tab->table; indirect_buckets *newtab = PL_malloc(sizeof(*newtab)); unsigned int mask; size_t index; int i, last=FALSE; newtab->size = oldtab->size * 2; newtab->buckets = PL_malloc(newtab->size*sizeof(*newtab->buckets)); memset(newtab->buckets, 0, newtab->size*sizeof(*newtab->buckets)); newtab->prev = oldtab; mask = newtab->size - 1; for(index=1, i=0; !last; i++) { size_t upto = (size_t)2<<i; indirect *b = tab->array.blocks[i]; if ( upto >= tab->highest ) { upto = tab->highest; last = TRUE; } for(; index<upto; index++) { indirect *a = b+index; if ( INDIRECT_IS_VALID(a->references) ) { size_t sz = wsizeofInd(a->header); unsigned int v; v = MurmurHashAligned2(a->data, sz*sizeof(word), MURMUR_SEED) & mask; a->next = newtab->buckets[v]; newtab->buckets[v] = a; } } } tab->table = newtab; } }
void get_integer(word w, Number n) { if ( storage(w) == STG_INLINE ) { n->type = V_INTEGER, n->value.i = valInt(w); } else { GET_LD Word p = addressIndirect(w); size_t wsize = wsizeofInd(*p); p++; if ( wsize == WORDS_PER_INT64 ) { n->type = V_INTEGER; memcpy(&n->value.i, p, sizeof(int64_t)); } else { n->type = V_MPZ; n->value.mpz->_mp_size = (int)*p++; n->value.mpz->_mp_alloc = 0; n->value.mpz->_mp_d = (mp_limb_t*) p; } } }
t = (char *)&g[1]; w = (pl_wchar_t*)t; w[0] = 0; *t = 'W'; memcpy(&w[1], s, len*sizeof(pl_wchar_t)); } return consPtr(g, TAG_STRING|STG_GLOBAL); } char * getCharsString__LD(word w, size_t *len ARG_LD) { Word p = valPtr(w); word m = *p; size_t wn = wsizeofInd(m); size_t pad = padHdr(m); char *s; if ( len ) *len = wn*sizeof(word) - pad - 1; /* -1 for the 'B' */ s = (char *)&p[1]; if ( *s == 'B' ) return s+1; assert(*s == 'W'); return NULL; }
newtab->buckets[v] = a; } } } tab->table = newtab; } } word extern_indirect(indirect_table *tab, word val, Word *gp ARG_LD) { size_t index = val>>LMASK_BITS; int idx = MSB(index); indirect *h = &tab->array.blocks[idx][index]; size_t wsize = wsizeofInd(h->header); Word p, r; if ( !hasGlobalSpace(wsize+2) ) { int rc; if ( (rc=ensureGlobalSpace(wsize+2, ALLOW_GC)) != TRUE ) { raiseStackOverflow(rc); return 0; } } if ( gp ) r = p = *gp; else r = p = gTop;