Skip to content

Commit 05232cc

Browse files
committed
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 5275e55.
1 parent 5275e55 commit 05232cc

File tree

3 files changed

+16
-25
lines changed

3 files changed

+16
-25
lines changed

Zend/zend_alloc.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,16 @@ struct _zend_mm_bin {
287287
char bytes[ZEND_MM_PAGE_SIZE * 8];
288288
};
289289

290+
#if ZEND_DEBUG
291+
typedef struct _zend_mm_debug_info {
292+
size_t size;
293+
const char *filename;
294+
const char *orig_filename;
295+
uint lineno;
296+
uint orig_lineno;
297+
} zend_mm_debug_info;
298+
#endif
299+
290300
struct _zend_mm_free_slot {
291301
zend_mm_free_slot *next_free_slot;
292302
};

Zend/zend_alloc.h

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,20 +50,6 @@ typedef struct _zend_leak_info {
5050
uint orig_lineno;
5151
} zend_leak_info;
5252

53-
#if ZEND_DEBUG
54-
typedef struct _zend_mm_debug_info {
55-
size_t size;
56-
const char *filename;
57-
const char *orig_filename;
58-
uint lineno;
59-
uint orig_lineno;
60-
} zend_mm_debug_info;
61-
62-
# define ZEND_MM_OVERHEAD ZEND_MM_ALIGNED_SIZE(sizeof(zend_mm_debug_info))
63-
#else
64-
# define ZEND_MM_OVERHEAD 0
65-
#endif
66-
6753
BEGIN_EXTERN_C()
6854

6955
ZEND_API char* ZEND_FASTCALL zend_strndup(const char *s, size_t length) ZEND_ATTRIBUTE_MALLOC;

Zend/zend_smart_str.h

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,14 @@
2222
#include <zend.h>
2323
#include "zend_smart_str_public.h"
2424

25-
#define SMART_STR_OVERHEAD (ZEND_MM_OVERHEAD + _STR_HEADER_SIZE)
26-
27-
#ifndef SMART_STR_PAGE
28-
# define SMART_STR_PAGE 4096
25+
#ifndef SMART_STR_PREALLOC
26+
#define SMART_STR_PREALLOC 128
2927
#endif
3028

3129
#ifndef SMART_STR_START_SIZE
32-
# define SMART_STR_START_SIZE (256 - SMART_STR_OVERHEAD - 1)
30+
#define SMART_STR_START_SIZE 78
3331
#endif
3432

35-
#define SMART_STR_NEW_SIZE(newlen) \
36-
(((newlen + SMART_STR_OVERHEAD + SMART_STR_PAGE) & ~(SMART_STR_PAGE - 1)) - SMART_STR_OVERHEAD - 1)
37-
3833
#define smart_str_appends_ex(dest, src, what) \
3934
smart_str_appendl_ex((dest), (src), strlen(src), (what))
4035
#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
6055
newlen = len;
6156
str->a = newlen < SMART_STR_START_SIZE
6257
? SMART_STR_START_SIZE
63-
: SMART_STR_NEW_SIZE(newlen);
58+
: newlen + SMART_STR_PREALLOC;
6459
str->s = zend_string_alloc(str->a, persistent);
6560
str->s->len = 0;
6661
} else {
6762
newlen = str->s->len + len;
6863
if (newlen >= str->a) {
69-
str->a = SMART_STR_NEW_SIZE(newlen);
70-
str->s = (zend_string *) perealloc2(str->s, _STR_HEADER_SIZE + str->a + 1, _STR_HEADER_SIZE + str->s->len + 1, persistent);
64+
str->a = newlen + SMART_STR_PREALLOC;
65+
str->s = (zend_string *) perealloc(str->s, _STR_HEADER_SIZE + str->a + 1, persistent);
7166
}
7267
}
7368
return newlen;

0 commit comments

Comments
 (0)