summaryrefslogtreecommitdiff
path: root/Zend/zend_string.h
diff options
context:
space:
mode:
authorNikita Popov <nikic@php.net>2014-05-02 17:01:36 +0200
committerNikita Popov <nikic@php.net>2014-05-03 10:43:45 +0200
commit65f488ece3f946d53b12b8c265185a483b079dfb (patch)
tree47b91136e6f998a4c3f05b52376f89fde7f517b5 /Zend/zend_string.h
parentd8651fbe1c4caaaedc42cef1dee0dd3b3f1e447e (diff)
downloadphp-git-65f488ece3f946d53b12b8c265185a483b079dfb.tar.gz
Add STR_ALLOCA_* API, use in get_method and verify_arg
This avoid unnecessary allocations when using dynamic method dispatch and class typehints. Probably there are other places where this should be done as well, those just stood out for my usage.
Diffstat (limited to 'Zend/zend_string.h')
-rw-r--r--Zend/zend_string.h14
1 files changed, 14 insertions, 0 deletions
diff --git a/Zend/zend_string.h b/Zend/zend_string.h
index af83d4d3b5..dfdc74eda8 100644
--- a/Zend/zend_string.h
+++ b/Zend/zend_string.h
@@ -56,6 +56,20 @@ END_EXTERN_C()
#define _STR_HEADER_SIZE XtOffsetOf(zend_string, val)
+#define STR_ALLOCA_ALLOC(str, _len, use_heap) do { \
+ (str) = do_alloca(_STR_HEADER_SIZE + (_len) + 1, (use_heap)); \
+ GC_REFCOUNT(str) = 1; \
+ (str)->h = 0; \
+ (str)->len = (_len); \
+} while (0)
+#define STR_ALLOCA_INIT(str, s, len, use_heap) do { \
+ STR_ALLOCA_ALLOC(str, len, use_heap); \
+ memcpy((str)->val, (s), (len)); \
+ (str)->val[(len)] = '\0'; \
+} while (0)
+
+#define STR_ALLOCA_FREE(str, use_heap) free_alloca(str, use_heap)
+
static zend_always_inline zend_ulong zend_str_hash_val(zend_string *s)
{
if (!s->h) {