Example #1
0
/**
 * Increment references of the given shared string.
 *
 * @param str The shared string.
 * @return    A pointer to an instance of the string on success.
 *            @c NULL on failure.
 *
 * This is similar to eina_share_common_add(), but it's faster since it will
 * avoid lookups if possible, but on the down side it requires the parameter
 * to be shared before, in other words, it must be the return of a previous
 * eina_share_common_add().
 *
 * There is no unref since this is the work of eina_share_common_del().
 */
EAPI const char *
eina_stringshare_ref(const char *str)
{
   int slen;
   DBG("str=%p (%s)", str, str ? str : "");

   if (!str)
      return eina_share_common_ref(stringshare_share, str);

   /* special cases */
   if      (str[0] == '\0')
      slen = 0;
   else if (str[1] == '\0')
      slen = 1;
   else if (str[2] == '\0')
      slen = 2;
   else if (str[3] == '\0')
      slen = 3;
   else
      slen = 3 + (int)strlen(str + 3);

   if (slen < 2)
     {
        eina_share_common_population_add(stringshare_share, slen);

        return str;
     }
   else if (slen < 4)
     {
        const char *s;
        eina_share_common_population_add(stringshare_share, slen);

        STRINGSHARE_LOCK_SMALL();
        s = _eina_stringshare_small_add(str, slen);
        STRINGSHARE_UNLOCK_SMALL();

        return s;
     }

   return eina_share_common_ref(stringshare_share, str);
}
Example #2
0
EAPI Eina_Stringshare *
eina_stringshare_ref(Eina_Stringshare *str)
{
    int slen;

    if (!str)
        return eina_share_common_ref(stringshare_share, str);

    /* special cases */
    if      (str[0] == '\0')
        slen = 0;
    else if (str[1] == '\0')
        slen = 1;
    else if (str[2] == '\0')
        slen = 2;
    else if (str[3] == '\0')
        slen = 3;
    else
        slen = 3 + (int)strlen(str + 3);

    if (slen < 2)
    {
        eina_share_common_population_add(stringshare_share, slen);

        return str;
    }
    else if (slen < 4)
    {
        const char *s;
        eina_share_common_population_add(stringshare_share, slen);

        eina_lock_take(&_mutex_small);
        s = _eina_stringshare_small_add(str, slen);
        eina_lock_release(&_mutex_small);

        return s;
    }

    return eina_share_common_ref(stringshare_share, str);
}
Example #3
0
/**
 * Increment references of the given shared string.
 *
 * @param str The shared string.
 * @return    A pointer to an instance of the string on success.
 *            @c NULL on failure.
 *
 * This is similar to eina_share_common_add(), but it's faster since it will
 * avoid lookups if possible, but on the down side it requires the parameter
 * to be shared before, in other words, it must be the return of a previous
 * eina_ustringshare_add().
 *
 * There is no unref since this is the work of eina_ustringshare_del().
 */
EAPI const Eina_Unicode *eina_ustringshare_ref(const Eina_Unicode * str)
{
	return (const Eina_Unicode *)
	    eina_share_common_ref(ustringshare_share, (const char *) str);
}