Esempio n. 1
0
_INLINE_
/* This routine works with any (long) string */
static SLstring_Type *find_string (SLCONST char *s, unsigned int len, unsigned long hash)
{
   SLstring_Type *sls;

   /* Assume it is an slstring */
   sls = find_slstring (s, hash);
   if (sls != NULL)
     return sls;

   /* Ok, not an slstring.  Try to find a matching one */
   sls = String_Hash_Table [(unsigned int) MAP_HASH_TO_INDEX(hash)];

   if (sls == NULL)
     return NULL;

   do
     {
	/* Note that we need to actually make sure that bytes[len] == 0. 
	 * In this case, it is not enough to just compare pointers.  In fact,
	 * this is called from create_nstring, etc...  It is unlikely that the
	 * pointer is a slstring
	 */
	if ((sls->hash == hash)
	    && (sls->len == len)
	    && (0 == strncmp (s, sls->bytes, len)))
	  break;

	sls = sls->next;
     }
   while (sls != NULL);

   return sls;
}
Esempio n. 2
0
_INLINE_
static void free_long_string (char *s, unsigned long hash)
{
   SLstring_Type *sls;

   if (NULL == (sls = find_slstring (s, hash)))
     {
	_pSLang_verror (SL_APPLICATION_ERROR, "invalid attempt to free string:%s", s);
	return;
     }

   sls->ref_count--;
   if (sls->ref_count != 0)
     {
#if SLANG_OPTIMIZE_FOR_SPEED
	/* cache_string (sls, len, hash); */
#endif
	return;
     }
#if SLANG_OPTIMIZE_FOR_SPEED
   uncache_string (s);
#endif
   free_sls_string (sls);
}