diff options
| author | Nikita Popov <nikic@php.net> | 2013-09-13 18:45:02 +0200 |
|---|---|---|
| committer | Nikita Popov <nikic@php.net> | 2013-09-13 19:42:10 +0200 |
| commit | 96b1c2145c2cd5e616dea191648c2d73af0239c9 (patch) | |
| tree | c9c8ae54ec95874143310c11f05337d7b7de06ad /Zend/zend_string.h | |
| parent | d2950ac2791cd03559a58e78f5cd626283b9ee4d (diff) | |
| download | php-git-96b1c2145c2cd5e616dea191648c2d73af0239c9.tar.gz | |
Provide more macros for handling of interned strings
* str_erealloc behaves like erealloc for normal strings, but will
use emalloc+memcpy for interned strings.
* str_estrndup behaves like estrndup for normal strings, but will
not copy interned strings.
* str_strndup behaves like zend_strndup for normal strings, but
will not copy interned strings.
* str_efree_rel behaves like efree_rel for normal strings, but
will not free interned strings.
* str_hash will return INTERNED_HASH for interned strings and
compute it using zend_hash_func for normal strings.
Diffstat (limited to 'Zend/zend_string.h')
| -rw-r--r-- | Zend/zend_string.h | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/Zend/zend_string.h b/Zend/zend_string.h index ebf8c816c1..725e069ed2 100644 --- a/Zend/zend_string.h +++ b/Zend/zend_string.h @@ -56,12 +56,39 @@ END_EXTERN_C() } \ } while (0) +#define str_efree_rel(s) do { \ + if (!IS_INTERNED(s)) { \ + efree_rel((char *)s); \ + } \ + } while (0) + #define str_free(s) do { \ if (!IS_INTERNED(s)) { \ free((char*)s); \ } \ } while (0) +#define str_erealloc(str, new_len) \ + (IS_INTERNED(str) \ + ? _str_erealloc(str, new_len, INTERNED_LEN(str)) \ + : erealloc(str, new_len)) + +static inline char *_str_erealloc(char *str, size_t new_len, size_t old_len) { + char *buf = emalloc(new_len); + memcpy(buf, str, old_len); + return buf; +} + +#define str_estrndup(str, len) \ + (IS_INTERNED(str) ? (str) : estrndup((str), (len))) + +#define str_strndup(str, len) \ + (IS_INTERNED(str) ? (str) : zend_strndup((str), (len))); + +#define str_hash(str, len) \ + (IS_INTERNED(str) ? INTERNED_HASH(str) : zend_hash_func((str), (len)+1)) + + #endif /* ZEND_STRING_H */ /* |
