Skip to content

Commit

Permalink
Minor optimization (#5231)
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanFreeman authored Jan 9, 2024
1 parent e1ee8c3 commit 3ace5d6
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
1 change: 1 addition & 0 deletions ext-src/php_swoole_cxx.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
_(SW_ZEND_STR_REMOTE_PORT, "remote_port") \
_(SW_ZEND_STR_REMOTE_ADDR, "remote_addr") \
_(SW_ZEND_STR_MASTER_TIME, "master_time") \
_(SW_ZEND_STR_QUERY_STRING, "query_string") \
_(SW_ZEND_STR_HTTP10, "HTTP/1.0") \
_(SW_ZEND_STR_HTTP11, "HTTP/1.1") \

Expand Down
7 changes: 3 additions & 4 deletions ext-src/swoole_http_request.cc
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ static int http_request_on_query_string(swoole_http_parser *parser, const char *
zval tmp;
HashTable *ht = Z_ARR_P(ctx->request.zserver);
ZVAL_STRINGL(&tmp, (char *) at, length);
zend_hash_str_add(ht, ZEND_STRL("query_string"), &tmp);
http_server_add_server_array(ht, SW_ZSTR_KNOWN(SW_ZEND_STR_QUERY_STRING), &tmp);

// parse url params
sapi_module.treat_data(
Expand Down Expand Up @@ -357,9 +357,8 @@ static int http_request_on_header_value(swoole_http_parser *parser, const char *
HttpContext *ctx = (HttpContext *) parser->data;
zval *zheader = ctx->request.zheader;
size_t header_len = ctx->current_header_name_len;
zend::CharPtr _header_name;
_header_name.assign_tolower(ctx->current_header_name, header_len);
char *header_name = _header_name.get();
char header_name[header_len];
zend_str_tolower_copy(header_name, ctx->current_header_name, header_len);

if (ctx->parse_cookie && SW_STREQ(header_name, header_len, "cookie")) {
zval *zcookie = swoole_http_init_and_read_property(
Expand Down
2 changes: 1 addition & 1 deletion ext-src/swoole_http_response.cc
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ String *HttpContext::get_write_buffer() {
return ((Socket *) private_data)->get_write_buffer();
} else {
if (!write_buffer) {
write_buffer = new String(SW_BUFFER_SIZE_STD);
write_buffer = new String(SW_BUFFER_SIZE_STD, sw_php_allocator());
}
return write_buffer;
}
Expand Down
4 changes: 2 additions & 2 deletions ext-src/swoole_http_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -220,12 +220,12 @@ HttpContext *swoole_http_context_new(SessionId fd) {

zval *zrequest_object = &ctx->request._zobject;
ctx->request.zobject = zrequest_object;
object_init_ex(zrequest_object, swoole_http_request_ce);
ZVAL_OBJ(zrequest_object, swoole_http_request_ce->create_object(swoole_http_request_ce));
php_swoole_http_request_set_context(zrequest_object, ctx);

zval *zresponse_object = &ctx->response._zobject;
ctx->response.zobject = zresponse_object;
object_init_ex(zresponse_object, swoole_http_response_ce);
ZVAL_OBJ(zresponse_object, swoole_http_response_ce->create_object(swoole_http_response_ce));
php_swoole_http_response_set_context(zresponse_object, ctx);

http_server_set_object_fd_property(SW_Z8_OBJ_P(zrequest_object), swoole_http_request_ce, fd);
Expand Down

0 comments on commit 3ace5d6

Please sign in to comment.