Skip to content

Commit

Permalink
Minor opt
Browse files Browse the repository at this point in the history
  • Loading branch information
laruence committed Aug 12, 2016
1 parent 3198434 commit 0dd66dc
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 19 deletions.
2 changes: 1 addition & 1 deletion yaf_application.c
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ PHP_METHOD(yaf_application, bootstrap) {
bootstrap_path = strpprintf(0, "%s%c%s.%s",
ZSTR_VAL(YAF_G(directory)), DEFAULT_SLASH, YAF_DEFAULT_BOOTSTRAP, ZSTR_VAL(YAF_G(ext)));
}
if (!yaf_loader_import(ZSTR_VAL(bootstrap_path), ZSTR_LEN(bootstrap_path), 0)) {
if (!yaf_loader_import(bootstrap_path, 0)) {
php_error_docref(NULL, E_WARNING, "Couldn't find bootstrap file %s", ZSTR_VAL(bootstrap_path));
retval = 0;
} else if (UNEXPECTED((ce = zend_hash_str_find_ptr(EG(class_table),
Expand Down
18 changes: 8 additions & 10 deletions yaf_dispatcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -377,14 +377,12 @@ zend_class_entry *yaf_dispatcher_get_action(zend_string *app_dir, yaf_controller
}

if ((paction = zend_hash_find(Z_ARRVAL_P(actions_map), action)) != NULL) {
char *action_path;
size_t action_path_len;
zend_string *action_path;

action_path_len = spprintf(&action_path, 0,
"%s%c%s", ZSTR_VAL(app_dir), DEFAULT_SLASH, Z_STRVAL_P(paction));
if (yaf_loader_import(action_path, action_path_len, 0)) {
action_path = strpprintf(0, "%s%c%s", ZSTR_VAL(app_dir), DEFAULT_SLASH, Z_STRVAL_P(paction));
if (yaf_loader_import(action_path, 0)) {
if ((ce = zend_hash_find_ptr(EG(class_table), class_lowercase)) != NULL) {
efree(action_path);
zend_string_release(action_path);
efree(action_upper);
zend_string_release(class_lowercase);

Expand All @@ -399,17 +397,17 @@ zend_class_entry *yaf_dispatcher_get_action(zend_string *app_dir, yaf_controller

} else {
yaf_trigger_error(YAF_ERR_NOTFOUND_ACTION,
"Could not find action %s in %s", ZSTR_VAL(class), action_path);
"Could not find action %s in %s", ZSTR_VAL(class), ZSTR_VAL(action_path));
}

efree(action_path);
zend_string_release(action_path);
efree(action_upper);
zend_string_release(class);
zend_string_release(class_lowercase);
} else {
yaf_trigger_error(YAF_ERR_NOTFOUND_ACTION,
"Failed opening action script %s: %s", action_path, strerror(errno));
efree(action_path);
"Failed opening action script %s: %s", ZSTR_VAL(action_path), strerror(errno));
zend_string_release(action_path);
}
} else {
yaf_trigger_error(YAF_ERR_NOTFOUND_ACTION, "There is no method %s%s in %s::$%s", ZSTR_VAL(action),
Expand Down
14 changes: 7 additions & 7 deletions yaf_loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -252,18 +252,18 @@ yaf_loader_t *yaf_loader_instance(yaf_loader_t *this_ptr, zend_string *library_p
}
/* }}} */

/** {{{ int yaf_loader_import(char *path, size_t len, int use_path)
/** {{{ int yaf_loader_import(zend_string *path, int use_path)
*/
int yaf_loader_import(char *path, size_t len, int use_path) {
int yaf_loader_import(zend_string *path, int use_path) {
zend_file_handle file_handle;
zend_op_array *op_array;
char realpath[MAXPATHLEN];

if (!VCWD_REALPATH(path, realpath)) {
if (!VCWD_REALPATH(ZSTR_VAL(path), realpath)) {
return 0;
}

file_handle.filename = path;
file_handle.filename = ZSTR_VAL(path);
file_handle.free_filename = 0;
file_handle.type = ZEND_HANDLE_FILENAME;
file_handle.opened_path = NULL;
Expand All @@ -273,7 +273,7 @@ int yaf_loader_import(char *path, size_t len, int use_path) {

if (op_array && file_handle.handle.stream.handle) {
if (!file_handle.opened_path) {
file_handle.opened_path = zend_string_init(path, len, 0);
file_handle.opened_path = zend_string_copy(path);
}

zend_hash_add_empty_element(&EG(included_files), file_handle.opened_path);
Expand Down Expand Up @@ -369,7 +369,7 @@ int yaf_internal_autoload(char *file_name, size_t name_len, char **directory) /*
*(directory) = estrndup(ZSTR_VAL(buf.s), ZSTR_LEN(buf.s));
}

status = yaf_loader_import(ZSTR_VAL(buf.s), ZSTR_LEN(buf.s), 0);
status = yaf_loader_import(buf.s, 0);
smart_str_free(&buf);

return status;
Expand Down Expand Up @@ -570,7 +570,7 @@ PHP_METHOD(yaf_loader, import) {
RETURN_TRUE;
}

retval = yaf_loader_import(ZSTR_VAL(file), ZSTR_LEN(file), 0);
retval = yaf_loader_import(file, 0);
if (need_free) {
zend_string_release(file);
}
Expand Down
2 changes: 1 addition & 1 deletion yaf_loader.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
extern zend_class_entry *yaf_loader_ce;

int yaf_internal_autoload(char *file_name, size_t name_len, char **directory);
int yaf_loader_import(char *path, size_t len, int use_path);
int yaf_loader_import(zend_string *path, int use_path);
int yaf_register_autoloader(yaf_loader_t *loader);
int yaf_loader_register_namespace_single(char *prefix, size_t len);
yaf_loader_t *yaf_loader_instance(yaf_loader_t *this_ptr, zend_string *library_path, zend_string *global_path);
Expand Down

0 comments on commit 0dd66dc

Please sign in to comment.