pike.git / src / pike_search_engine.c

version» Context lines:

pike.git/src/pike_search_engine.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$ +    */      /*    * Written by Fredrik Hubinette (hubbe@lysator.liu.se)    */      #define HSHIFT 0   #include "pike_search_engine2.c"   #undef HSHIFT   
pike.git/src/pike_search_engine.c:21:   #include "pike_search_engine2.c"   #undef HSHIFT            #define INTERCASE(NAME,X) \    case X: return MKPCHARP(PxC3(NAME,NSHIFT,X)(s,(PxC(p_wchar,X) *)haystack.ptr,haystacklen),X)         #define INTERMEDIATE(NAME) \ - PCHARP PxC3(NAME,NSHIFT,N)(void *s, \ -  PCHARP haystack, \ -  ptrdiff_t haystacklen) \ + PCHARP PxC3(NAME,NSHIFT,N)(void *s, \ +  PCHARP haystack, \ +  ptrdiff_t haystacklen) \   { \    switch(haystack.shift) \    { \    INTERCASE(NAME,0); \    INTERCASE(NAME,1); \    INTERCASE(NAME,2); \    } \ -  Pike_fatal("Illegal shift\n"); \ -  return haystack; /* NOT_REACHED */ \ +  UNREACHABLE(return haystack); \   } \    \   static const struct SearchMojtVtable PxC3(NAME,NSHIFT,_vtable) = { \    (SearchMojtFunc0)PxC3(NAME,NSHIFT,0), \ -  (SearchMojtFunc1)PxC3(NAME,NSHIFT,1), \ -  (SearchMojtFunc2)PxC3(NAME,NSHIFT,2), \ -  (SearchMojtFuncN)PxC3(NAME,NSHIFT,N), \ +  (SearchMojtFunc1)PxC3(NAME,NSHIFT,1), \ +  (SearchMojtFunc2)PxC3(NAME,NSHIFT,2), \ +  (SearchMojtFuncN)PxC3(NAME,NSHIFT,N), \   };         INTERMEDIATE(memchr_search)   INTERMEDIATE(memchr_memcmp2)   INTERMEDIATE(memchr_memcmp3)   INTERMEDIATE(memchr_memcmp4)   INTERMEDIATE(memchr_memcmp5)   INTERMEDIATE(memchr_memcmp6)   INTERMEDIATE(boyer_moore_hubbe)
pike.git/src/pike_search_engine.c:103:    s->set[e]=0;    linklen[e]=0;    }    hsize--;       if(max > (ptrdiff_t)needlelen) max=needlelen;    max=(max-sizeof(INT32)+1) & ~(sizeof(INT32) - 1);    if(max > MEMSEARCH_LINKS) max=MEMSEARCH_LINKS;       /* This assumes 512 buckets - Hubbe */ -  maxlinklength = my_sqrt(DO_NOT_WARN((unsigned int)max/2))+1; +  maxlinklength = (INT32)sqrt((double)max/2)+1;       ptr=& s->links[0];       q=(NCHAR *)needle;      #if PIKE_BYTEORDER == 4321 && NSHIFT == 0    for(tmp = e = 0; e < (ptrdiff_t)sizeof(INT32)-1; e++)    {    tmp<<=8;    tmp|=*(q++);
pike.git/src/pike_search_engine.c:221:    {    case 0:    s->mojt.vtab=&nil_search_vtable;    return;       case 1:    s->mojt.data=(void *)(ptrdiff_t)(needle[0]);    s->mojt.vtab=& PxC3(memchr_search,NSHIFT,_vtable);    return;    - #define MMCASE(X) \ -  case X: \ + #define MMCASE(X) \ +  case X: \    s->mojt.data=(void *) needle; \    s->mojt.vtab=& PxC4(memchr_memcmp,X,NSHIFT,_vtable); \    return       MMCASE(2);    MMCASE(3);    MMCASE(4);    MMCASE(5);    MMCASE(6);   
pike.git/src/pike_search_engine.c:307:    o=sval->u.object;    if(o->prog == pike_search_program)    {    s=OB2MSEARCH(sval->u.object);    assert (sval->u.object == s->mojt.container);    add_ref(sval->u.object);    free_string(hashkey);    return s->mojt;    }    } +  /* Paranoia: Junk entry in the mapping. Remove it. */ +  SET_SVAL(stmp, T_STRING, 0, string, hashkey); +  map_delete(memsearch_cache, &stmp);    }    -  +  if (memsearch_cache->data->size >= memsearch_cache_threshold) { +  /* Perform a gc of all Search objects that only are +  * referenced from the cache. +  * Allow the cache to grow to double the size before +  * the next synchronous gc. +  */ +  struct keypair *k = NULL; +  struct mapping_data *md = memsearch_cache->data; +  int e; +  int count = 0; +  /* NB: We inline some stuff from mapping.c here to avoid copying the md. +  */ +  for (e=0; e < md->hashsize; e++) { +  struct keypair **prev; +  for(prev = md->hash + e; (k = *prev);) { +  count++; +  if (REFCOUNTED_TYPE(TYPEOF(k->val)) && +  (*k->val.u.refs == 1)) { +  /* map_delete(memsearch_cache, &k->ind); */ +  *prev = k->next; +  free_svalue(&k->ind); +  free_svalue(&k->val); +  mapping_free_keypair(md, k); +  md->size--; +  continue; +  } else if (count < 10) { +  // locate_references(k->val.u.refs); +  } +  prev = &k->next; +  } +  } +  memsearch_cache_threshold = (memsearch_cache->data->size<<1) | 1; +  if (memsearch_cache_threshold < MIN_MEMSEARCH_THRESHOLD) { +  memsearch_cache_threshold = MIN_MEMSEARCH_THRESHOLD; +  } +  } else if ((memsearch_cache_threshold & 1) && +  (memsearch_cache->data->size<<2 < memsearch_cache_threshold)) { +  /* The real gc() has run and zapped some of our entries. +  * Assume that all entries left in the cache have more than +  * one reference. +  */ +  memsearch_cache_threshold = (memsearch_cache->data->size<<1) | 1; +  if (memsearch_cache_threshold < MIN_MEMSEARCH_THRESHOLD) { +  memsearch_cache_threshold = MIN_MEMSEARCH_THRESHOLD; +  } +  } +     o=low_clone(pike_search_program);    s=OB2MSEARCH(o);    s->mojt.container = o; /* Not refcounted self-ref. */    s->s=hashkey;       /* We use 0x7fffffff for max_haystacklen because we do    * not know how many times this search struct will be    * reused.    */    NameN(init_memsearch)(s,    needle,len,    0x7fffffff);    SET_SVAL(stmp, T_OBJECT, 0, object, o);       mapping_string_insert(memsearch_cache, hashkey, &stmp);       return s->mojt;    }   }