Skip to content

Commit 2fa8d67

Browse files
committed
Use zend_string* instead of char* for opened_patch handling. Avoid reallocations and improve string reuse.
1 parent 2841aa9 commit 2fa8d67

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+3023
-3047
lines changed

Zend/zend.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
ZEND_API zend_class_entry *zend_standard_class_def = NULL;
4949
ZEND_API size_t (*zend_printf)(const char *format, ...);
5050
ZEND_API zend_write_func_t zend_write;
51-
ZEND_API FILE *(*zend_fopen)(const char *filename, char **opened_path);
51+
ZEND_API FILE *(*zend_fopen)(const char *filename, zend_string **opened_path);
5252
ZEND_API int (*zend_stream_open_function)(const char *filename, zend_file_handle *handle);
5353
ZEND_API void (*zend_block_interruptions)(void);
5454
ZEND_API void (*zend_unblock_interruptions)(void);
@@ -57,7 +57,7 @@ ZEND_API void (*zend_error_cb)(int type, const char *error_filename, const uint
5757
size_t (*zend_vspprintf)(char **pbuf, size_t max_len, const char *format, va_list ap);
5858
zend_string *(*zend_vstrpprintf)(size_t max_len, const char *format, va_list ap);
5959
ZEND_API char *(*zend_getenv)(char *name, size_t name_len);
60-
ZEND_API char *(*zend_resolve_path)(const char *filename, int filename_len);
60+
ZEND_API zend_string *(*zend_resolve_path)(const char *filename, int filename_len);
6161

6262
void (*zend_on_timeout)(int seconds);
6363

@@ -374,10 +374,10 @@ ZEND_API void zend_print_zval_r_ex(zend_write_func_t write_func, zval *expr, int
374374
}
375375
/* }}} */
376376

377-
static FILE *zend_fopen_wrapper(const char *filename, char **opened_path) /* {{{ */
377+
static FILE *zend_fopen_wrapper(const char *filename, zend_string **opened_path) /* {{{ */
378378
{
379379
if (opened_path) {
380-
*opened_path = estrdup(filename);
380+
*opened_path = zend_string_init(filename, strlen(filename), 0);
381381
}
382382
return fopen(filename, "rb");
383383
}
@@ -1303,7 +1303,7 @@ ZEND_API int zend_execute_scripts(int type, zval *retval, int file_count, ...) /
13031303

13041304
op_array = zend_compile_file(file_handle, type);
13051305
if (file_handle->opened_path) {
1306-
zend_hash_str_add_empty_element(&EG(included_files), file_handle->opened_path, strlen(file_handle->opened_path));
1306+
zend_hash_add_empty_element(&EG(included_files), file_handle->opened_path);
13071307
}
13081308
zend_destroy_file_handle(file_handle);
13091309
if (op_array) {

Zend/zend.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ typedef struct _zend_utility_functions {
193193
void (*error_function)(int type, const char *error_filename, const uint error_lineno, const char *format, va_list args) ZEND_ATTRIBUTE_PTR_FORMAT(printf, 4, 0);
194194
size_t (*printf_function)(const char *format, ...) ZEND_ATTRIBUTE_PTR_FORMAT(printf, 1, 2);
195195
size_t (*write_function)(const char *str, size_t str_length);
196-
FILE *(*fopen_function)(const char *filename, char **opened_path);
196+
FILE *(*fopen_function)(const char *filename, zend_string **opened_path);
197197
void (*message_handler)(zend_long message, const void *data);
198198
void (*block_interruptions)(void);
199199
void (*unblock_interruptions)(void);
@@ -204,7 +204,7 @@ typedef struct _zend_utility_functions {
204204
size_t (*vspprintf_function)(char **pbuf, size_t max_len, const char *format, va_list ap);
205205
zend_string *(*vstrpprintf_function)(size_t max_len, const char *format, va_list ap);
206206
char *(*getenv_function)(char *name, size_t name_len);
207-
char *(*resolve_path_function)(const char *filename, int filename_len);
207+
zend_string *(*resolve_path_function)(const char *filename, int filename_len);
208208
} zend_utility_functions;
209209

210210
typedef struct _zend_utility_values {
@@ -272,7 +272,7 @@ END_EXTERN_C()
272272
BEGIN_EXTERN_C()
273273
extern ZEND_API size_t (*zend_printf)(const char *format, ...) ZEND_ATTRIBUTE_PTR_FORMAT(printf, 1, 2);
274274
extern ZEND_API zend_write_func_t zend_write;
275-
extern ZEND_API FILE *(*zend_fopen)(const char *filename, char **opened_path);
275+
extern ZEND_API FILE *(*zend_fopen)(const char *filename, zend_string **opened_path);
276276
extern ZEND_API void (*zend_block_interruptions)(void);
277277
extern ZEND_API void (*zend_unblock_interruptions)(void);
278278
extern ZEND_API void (*zend_ticks_function)(int ticks);
@@ -282,7 +282,7 @@ extern ZEND_API int (*zend_stream_open_function)(const char *filename, zend_file
282282
extern size_t (*zend_vspprintf)(char **pbuf, size_t max_len, const char *format, va_list ap);
283283
extern zend_string *(*zend_vstrpprintf)(size_t max_len, const char *format, va_list ap);
284284
extern ZEND_API char *(*zend_getenv)(char *name, size_t name_len);
285-
extern ZEND_API char *(*zend_resolve_path)(const char *filename, int filename_len);
285+
extern ZEND_API zend_string *(*zend_resolve_path)(const char *filename, int filename_len);
286286

287287
ZEND_API void zend_error(int type, const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 2, 3);
288288

0 commit comments

Comments
 (0)