Tizen Native API
|
Functions | |
const Eina_Unicode * | eina_ustringshare_add_length (const Eina_Unicode *str, unsigned int slen) |
Retrieves an instance of a string for use in a program. | |
const Eina_Unicode * | eina_ustringshare_add (const Eina_Unicode *str) |
Retrieves an instance of a string for use in a program. | |
const Eina_Unicode * | eina_ustringshare_ref (const Eina_Unicode *str) |
Increments references of the given shared string. | |
void | eina_ustringshare_del (const Eina_Unicode *str) |
Notes that the given string has lost an instance. | |
int | eina_ustringshare_strlen (const Eina_Unicode *str) |
Notes that the given string must be shared. | |
void | eina_ustringshare_dump (void) |
Dumps the contents of share_common. | |
static Eina_Bool | eina_ustringshare_replace (const Eina_Unicode **p_str, const Eina_Unicode *news) |
Replace the previously stringshared pointer with new content. | |
static Eina_Bool | eina_ustringshare_replace_length (const Eina_Unicode **p_str, const Eina_Unicode *news, unsigned int slen) |
Replace the previously stringshared pointer with a new content. |
This group discusses functions that allow you to store one copy of a string, and use it throughout your program.
This is a method to reduce the number of duplicated strings kept in the memory. It's pretty common for the same strings to be dynamically allocated repeatedly between applications and libraries, especially in circumstances where you could have multiple copies of a structure that allocates the string. So rather than duplicating and freeing these strings, you request a read-only pointer to an existing string and only incur the overhead of a hash lookup.
It sounds like micro-optimizing, but profiling has shown that this can have a significant impact as you scale the number of copies up. It improves the string creation/destruction speed, reduces memory use, and decreases memory fragmentation, so a win all-around.
const Eina_Unicode* eina_ustringshare_add | ( | const Eina_Unicode * | str | ) |
Retrieves an instance of a string for use in a program.
This function retrieves an instance of str. If str is NULL
, then NULL
is returned. If str is already stored, it is just returned and its reference counter is increased. Otherwise it is added to the strings to be searched and a duplicated string of str is returned.
[in] | str | The NULL-terminated string to retrieve an instance of |
NULL
on failureconst Eina_Unicode* eina_ustringshare_add_length | ( | const Eina_Unicode * | str, |
unsigned int | slen | ||
) |
Retrieves an instance of a string for use in a program.
This function retrieves an instance of str. If str is NULL
, then NULL
is returned. If str is already stored, it is just returned and its reference counter is increased. Otherwise it is added to the strings to be searched and a duplicated string of str is returned.
[in] | str | The string to retrieve an instance of |
[in] | slen | The string size (<= strlen(str)) |
NULL
on failurevoid eina_ustringshare_del | ( | const Eina_Unicode * | str | ) |
Notes that the given string has lost an instance.
This function decreases the reference counter associated to str if it exists. If that counter reaches 0
, the memory associated to str is freed. If str is NULL
, the function returns immediately.
[in] | str | string The given string |
void eina_ustringshare_dump | ( | void | ) |
Dumps the contents of share_common.
This function dumps all the strings from share_common to stdout with a DDD: prefix per line and a memory usage summary.
const Eina_Unicode* eina_ustringshare_ref | ( | const Eina_Unicode * | str | ) |
Increments references of the given shared string.
[in] | str | The shared string |
NULL
on failure static Eina_Bool eina_ustringshare_replace | ( | const Eina_Unicode ** | p_str, |
const Eina_Unicode * | news | ||
) | [static] |
Replace the previously stringshared pointer with new content.
The string pointed by p_str should be previously stringshared or NULL
and it will be eina_ustringshare_del(). The new string will be passed to eina_ustringshare_add() and then assigned to *p_str
.
[in] | p_str | pointer to the stringhare to be replaced. Must not be NULL , but *p_str may be NULL as it is a valid stringshare handle. |
[in] | news | new string to be stringshared, may be NULL . |
EINA_TRUE
if the strings were different and thus replaced, EINA_FALSE
if the strings were the same after shared. static Eina_Bool eina_ustringshare_replace_length | ( | const Eina_Unicode ** | p_str, |
const Eina_Unicode * | news, | ||
unsigned int | slen | ||
) | [static] |
Replace the previously stringshared pointer with a new content.
The string pointed by p_str should be previously stringshared or NULL
and it will be eina_ustringshare_del(). The new string will be passed to eina_ustringshare_add_length() and then assigned to *p_str
.
[in] | p_str | pointer to the stringhare to be replaced. Must not be NULL , but *p_str may be NULL as it is a valid stringshare handle. |
[in] | news | new string to be stringshared, may be NULL . |
[in] | slen | The string size (<= strlen(str)). |
EINA_TRUE
if the strings were different and thus replaced, EINA_FALSE
if the strings were the same after shared. int eina_ustringshare_strlen | ( | const Eina_Unicode * | str | ) |
Notes that the given string must be shared.
[in] | str | The shared string to know the length It is safe to give NULL , in which case -1 is returned. |