Revert "Changed zend_smart_str allocation granularity to do the better job together with Zend MM and avoid useless calls to erealloc()." That commit significantly increased the code size because of intensive inlining and more expensive reallocation code.

This reverts commit 5275e5560b.
This commit is contained in:
Dmitry Stogov 2015-04-16 13:11:54 +03:00
parent 5275e5560b
commit 05232cc810
3 changed files with 16 additions and 25 deletions

View file

@ -287,6 +287,16 @@ struct _zend_mm_bin {
char bytes[ZEND_MM_PAGE_SIZE * 8]; 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 { struct _zend_mm_free_slot {
zend_mm_free_slot *next_free_slot; zend_mm_free_slot *next_free_slot;
}; };

View file

@ -50,20 +50,6 @@ typedef struct _zend_leak_info {
uint orig_lineno; uint orig_lineno;
} zend_leak_info; } 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() BEGIN_EXTERN_C()
ZEND_API char* ZEND_FASTCALL zend_strndup(const char *s, size_t length) ZEND_ATTRIBUTE_MALLOC; ZEND_API char* ZEND_FASTCALL zend_strndup(const char *s, size_t length) ZEND_ATTRIBUTE_MALLOC;

View file

@ -22,19 +22,14 @@
#include <zend.h> #include <zend.h>
#include "zend_smart_str_public.h" #include "zend_smart_str_public.h"
#define SMART_STR_OVERHEAD (ZEND_MM_OVERHEAD + _STR_HEADER_SIZE) #ifndef SMART_STR_PREALLOC
#define SMART_STR_PREALLOC 128
#ifndef SMART_STR_PAGE
# define SMART_STR_PAGE 4096
#endif #endif
#ifndef SMART_STR_START_SIZE #ifndef SMART_STR_START_SIZE
# define SMART_STR_START_SIZE (256 - SMART_STR_OVERHEAD - 1) #define SMART_STR_START_SIZE 78
#endif #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) \ #define smart_str_appends_ex(dest, src, what) \
smart_str_appendl_ex((dest), (src), strlen(src), (what)) smart_str_appendl_ex((dest), (src), strlen(src), (what))
#define smart_str_appends(dest, src) \ #define smart_str_appends(dest, src) \
@ -60,14 +55,14 @@ static zend_always_inline size_t smart_str_alloc(smart_str *str, size_t len, zen
newlen = len; newlen = len;
str->a = newlen < SMART_STR_START_SIZE str->a = newlen < SMART_STR_START_SIZE
? SMART_STR_START_SIZE ? SMART_STR_START_SIZE
: SMART_STR_NEW_SIZE(newlen); : newlen + SMART_STR_PREALLOC;
str->s = zend_string_alloc(str->a, persistent); str->s = zend_string_alloc(str->a, persistent);
str->s->len = 0; str->s->len = 0;
} else { } else {
newlen = str->s->len + len; newlen = str->s->len + len;
if (newlen >= str->a) { if (newlen >= str->a) {
str->a = SMART_STR_NEW_SIZE(newlen); str->a = newlen + SMART_STR_PREALLOC;
str->s = (zend_string *) perealloc2(str->s, _STR_HEADER_SIZE + str->a + 1, _STR_HEADER_SIZE + str->s->len + 1, persistent); str->s = (zend_string *) perealloc(str->s, _STR_HEADER_SIZE + str->a + 1, persistent);
} }
} }
return newlen; return newlen;