com php-src: Changed zend_smart_str allocation granular ity to do the better job together with Zend M M and avoid useless calls to erealloc().:
Zend/zend_alloc.c Zend/zend_alloc.h Zend/zend_ smart_str.h
| From: | Dmitry Stogov | Date: | Thu, 16 Apr 2015 09:32:56 +0000 |
| Subject: | com php-src: Changed zend_smart_str allocation granular ity to do the better job together with Zend M M and avoid useless calls to erealloc().: Zend/zend_alloc.c Zend/zend_alloc.h Zend/zend_ smart_str.h |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-86325@lists.php.net to get a copy of this message | ||
Commit: 5275e5560bb186bc3950a0dbf15fe0e54ee4c6ec
Author: Dmitry Stogov <dmitry@zend.com> Thu, 16 Apr 2015 12:32:56 +0300
Parents: a759967dd1c09f8553bd5dedc82673fec15acb80
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=5275e5560bb186bc3950a0dbf15fe0e54ee4c6ec
Log:
Changed zend_smart_str allocation granularity to do the better job together with Zend MM and avoid
useless calls to erealloc().
Changed paths:
M Zend/zend_alloc.c
M Zend/zend_alloc.h
M Zend/zend_smart_str.h
Diff:
diff --git a/Zend/zend_alloc.c b/Zend/zend_alloc.c
index 6701ca4..16fd42e 100644
--- a/Zend/zend_alloc.c
+++ b/Zend/zend_alloc.c
@@ -287,16 +287,6 @@ struct _zend_mm_bin {
char bytes[ZEND_MM_PAGE_SIZE * 8];
};
-#if ZEND_DEBUG
-typedef struct _zend_mm_debug_info {
- size_t size;
- const char *filename;
- const char *orig_filename;
- uint lineno;
- uint orig_lineno;
-} zend_mm_debug_info;
-#endif
-
struct _zend_mm_free_slot {
zend_mm_free_slot *next_free_slot;
};
diff --git a/Zend/zend_alloc.h b/Zend/zend_alloc.h
index 6d89884..0cb3a71 100644
--- a/Zend/zend_alloc.h
+++ b/Zend/zend_alloc.h
@@ -50,6 +50,20 @@ typedef struct _zend_leak_info {
uint orig_lineno;
} zend_leak_info;
+#if ZEND_DEBUG
+typedef struct _zend_mm_debug_info {
+ size_t size;
+ const char *filename;
+ const char *orig_filename;
+ uint lineno;
+ uint orig_lineno;
+} zend_mm_debug_info;
+
+# define ZEND_MM_OVERHEAD ZEND_MM_ALIGNED_SIZE(sizeof(zend_mm_debug_info))
+#else
+# define ZEND_MM_OVERHEAD 0
+#endif
+
BEGIN_EXTERN_C()
ZEND_API char* ZEND_FASTCALL zend_strndup(const char *s, size_t length) ZEND_ATTRIBUTE_MALLOC;
diff --git a/Zend/zend_smart_str.h b/Zend/zend_smart_str.h
index c18b133..4a37dd6 100644
--- a/Zend/zend_smart_str.h
+++ b/Zend/zend_smart_str.h
@@ -22,14 +22,19 @@
#include <zend.h>
#include "zend_smart_str_public.h"
-#ifndef SMART_STR_PREALLOC
-#define SMART_STR_PREALLOC 128
+#define SMART_STR_OVERHEAD (ZEND_MM_OVERHEAD + _STR_HEADER_SIZE)
+
+#ifndef SMART_STR_PAGE
+# define SMART_STR_PAGE 4096
#endif
#ifndef SMART_STR_START_SIZE
-#define SMART_STR_START_SIZE 78
+# define SMART_STR_START_SIZE (256 - SMART_STR_OVERHEAD - 1)
#endif
+#define SMART_STR_NEW_SIZE(newlen) \
+ (((newlen + SMART_STR_OVERHEAD + SMART_STR_PAGE) & ~(SMART_STR_PAGE - 1)) - SMART_STR_OVERHEAD
- 1)
+
#define smart_str_appends_ex(dest, src, what) \
smart_str_appendl_ex((dest), (src), strlen(src), (what))
#define smart_str_appends(dest, src) \
@@ -55,14 +60,14 @@ static zend_always_inline size_t smart_str_alloc(smart_str *str, size_t len, zen
newlen = len;
str->a = newlen < SMART_STR_START_SIZE
? SMART_STR_START_SIZE
- : newlen + SMART_STR_PREALLOC;
+ : SMART_STR_NEW_SIZE(newlen);
str->s = zend_string_alloc(str->a, persistent);
str->s->len = 0;
} else {
newlen = str->s->len + len;
if (newlen >= str->a) {
- str->a = newlen + SMART_STR_PREALLOC;
- str->s = (zend_string *) perealloc(str->s, _STR_HEADER_SIZE + str->a + 1, persistent);
+ str->a = SMART_STR_NEW_SIZE(newlen);
+ str->s = (zend_string *) perealloc2(str->s, _STR_HEADER_SIZE + str->a + 1,
_STR_HEADER_SIZE + str->s->len + 1, persistent);
}
}
return newlen;