Skip to content

Instantly share code, notes, and snippets.

View dstogov's full-sized avatar

Dmitry Stogov dstogov

  • Zend by Perforce
  • Russia
View GitHub Profile
@dstogov
dstogov / opt_array_merge.diff
Created October 23, 2013 12:21
Improve array_merge() performance by eliminating unnecessary zval copying
diff --git a/ext/standard/array.c b/ext/standard/array.c
index 5197203..360a691 100644
--- a/ext/standard/array.c
+++ b/ext/standard/array.c
@@ -2222,13 +2222,14 @@ PHPAPI int php_array_merge(HashTable *dest, HashTable *src, int recursive TSRMLS
case HASH_KEY_IS_STRING:
if (recursive && zend_hash_find(dest, string_key, string_key_len, (void **)&dest_entry) == SUCCESS) {
HashTable *thash = Z_TYPE_PP(dest_entry) == IS_ARRAY ? Z_ARRVAL_PP(dest_entry) : NULL;
+ zval *src_zval;
+ zval *tmp = NULL;
@dstogov
dstogov / opt_func_get_args.diff
Created October 23, 2013 12:23
Improve get_func_args() performance by eliminating unnecessary zval copying
diff --git a/Zend/zend_builtin_functions.c b/Zend/zend_builtin_functions.c
index 1ad64e7..6cbe0bc 100644
--- a/Zend/zend_builtin_functions.c
+++ b/Zend/zend_builtin_functions.c
@@ -461,12 +461,17 @@ ZEND_FUNCTION(func_get_args)
array_init_size(return_value, arg_count);
for (i=0; i<arg_count; i++) {
- zval *element;
+ zval *element, *arg;
@dstogov
dstogov / nogc.diff
Created October 29, 2013 17:19
Eliminate "useless" GC_ZVAL_CHECK_POSSIBLE_ROOT checks
diff --git a/Zend/zend_execute.c b/Zend/zend_execute.c
index 9f78218..b5c35ca 100644
--- a/Zend/zend_execute.c
+++ b/Zend/zend_execute.c
@@ -79,7 +79,6 @@ static zend_always_inline void zend_pzval_unlock_func(zval *z, zend_free_op *sho
if (unref && Z_ISREF_P(z) && Z_REFCOUNT_P(z) == 1) {
Z_UNSET_ISREF_P(z);
}
- GC_ZVAL_CHECK_POSSIBLE_ROOT(z);
}
diff --git a/Zend/zend_types.h b/Zend/zend_types.h
index 82a168f..74024c7 100644
--- a/Zend/zend_types.h
+++ b/Zend/zend_types.h
@@ -22,6 +22,10 @@
#ifndef ZEND_TYPES_H
#define ZEND_TYPES_H
+#ifndef ZEND_WIN32
+# include <inttypes.h>
diff --git a/Zend/zend.h b/Zend/zend.h
index c346c02..a90165c 100644
--- a/Zend/zend.h
+++ b/Zend/zend.h
@@ -179,6 +179,14 @@ char *alloca ();
# define ZEND_ATTRIBUTE_DEPRECATED
#endif
+#if defined(__GNUC__) && ZEND_GCC_VERSION >= 4003
+# define ZEND_ATTRIBUTE_UNUSED __attribute__((unused))
diff --git a/Zend/zend.h b/Zend/zend.h
index c346c02..a90165c 100644
--- a/Zend/zend.h
+++ b/Zend/zend.h
@@ -179,6 +179,14 @@ char *alloca ();
# define ZEND_ATTRIBUTE_DEPRECATED
#endif
+#if defined(__GNUC__) && ZEND_GCC_VERSION >= 4003
+# define ZEND_ATTRIBUTE_UNUSED __attribute__((unused))
diff --git a/Zend/zend.c b/Zend/zend.c
index 297fe26..b995966 100644
--- a/Zend/zend.c
+++ b/Zend/zend.c
@@ -385,13 +385,15 @@ ZEND_API void zend_print_zval_r_ex(zend_write_func_t write_func, zval *expr, int
switch (Z_TYPE_P(expr)) {
case IS_ARRAY:
ZEND_PUTS_EX("Array\n");
- if (++Z_ARRVAL_P(expr)->u.v.nApplyCount>1) {
+ if (!Z_IMMUTABLE_P(expr) && ++Z_ARRVAL_P(expr)->u.v.nApplyCount>1) {
diff --git a/Zend/zend_hash.h b/Zend/zend_hash.h
index c196134..0952dbe 100644
--- a/Zend/zend_hash.h
+++ b/Zend/zend_hash.h
@@ -285,11 +285,27 @@ static inline int _zend_handle_numeric_str(const char *key, int length, ulong *i
}
}
+static inline int _zend_handle_numeric(zend_string *key, ulong *idx)
+{
diff --git a/main/streams/streams.c b/main/streams/streams.c
index 02a313b..f305fe8 100644
--- a/main/streams/streams.c
+++ b/main/streams/streams.c
@@ -524,20 +524,22 @@ fprintf(stderr, "stream_free: %s:%p[%s] preserve_handle=%d release_cast=%d remov
/* it leaked: Lets deliberately NOT pefree it so that the memory manager shows it
* as leaked; it will log a warning, but lets help it out and display what kind
* of stream it was. */
- char *leakinfo;
- spprintf(&leakinfo, 0, __FILE__ "(%d) : Stream of type '%s' %p (path:%s) was not closed\n", __LINE__, stream->ops->label, stream, stream->orig_path);
diff --git a/Zend/zend_execute.c b/Zend/zend_execute.c
index ad92c5f..6ada04e 100644
--- a/Zend/zend_execute.c
+++ b/Zend/zend_execute.c
@@ -943,6 +943,26 @@ copy_value:
}
}
+static void zval_deep_copy(zval **p)
+{