Skip to content

Commit

Permalink
remove unused code, use __builtin_expect a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
radkesvat committed Jun 22, 2024
1 parent d497191 commit e8d2ae5
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 19 deletions.
6 changes: 3 additions & 3 deletions tunnels/adapters/connector/tcp/tcp_connector.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ static void onWriteComplete(hio_t *io)
{
// resume the read on other end of the connection
tcp_connector_con_state_t *cstate = (tcp_connector_con_state_t *) (hevent_userdata(io));
if (cstate == NULL)
if (WW_UNLIKELY(cstate == NULL))
{
return;
}
Expand All @@ -82,7 +82,7 @@ static void onWriteComplete(hio_t *io)
static void onRecv(hio_t *io, shift_buffer_t *buf)
{
tcp_connector_con_state_t *cstate = (tcp_connector_con_state_t *) (hevent_userdata(io));
if (cstate == NULL)
if (WW_UNLIKELY(cstate == NULL))
{
reuseBuffer(hloop_bufferpool(hevent_loop(io)), buf);
return;
Expand Down Expand Up @@ -137,7 +137,7 @@ static void onLineResumed(void *userdata)
static void onOutBoundConnected(hio_t *upstream_io)
{
tcp_connector_con_state_t *cstate = hevent_userdata(upstream_io);
if (cstate == NULL)
if (WW_UNLIKELY(cstate == NULL))
{
return;
}
Expand Down
2 changes: 1 addition & 1 deletion tunnels/adapters/connector/udp/udp_connector.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ static void cleanup(udp_connector_con_state_t *cstate)
static void onRecvFrom(hio_t *io, shift_buffer_t *buf)
{
udp_connector_con_state_t *cstate = (udp_connector_con_state_t *) (hevent_userdata(io));
if (cstate == NULL)
if (WW_UNLIKELY(cstate == NULL))
{
reuseBuffer(hloop_bufferpool(hevent_loop(io)), buf);
return;
Expand Down
4 changes: 2 additions & 2 deletions tunnels/adapters/listener/tcp/tcp_listener.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ static void onWriteComplete(hio_t *io)
{
// resume the read on other end of the connection
tcp_listener_con_state_t *cstate = (tcp_listener_con_state_t *) (hevent_userdata(io));
if (cstate == NULL)
if (WW_UNLIKELY(cstate == NULL))
{
return;
}
Expand Down Expand Up @@ -224,7 +224,7 @@ static void downStream(tunnel_t *self, context_t *c)
static void onRecv(hio_t *io, shift_buffer_t *buf)
{
tcp_listener_con_state_t *cstate = (tcp_listener_con_state_t *) (hevent_userdata(io));
if (cstate == NULL)
if (WW_UNLIKELY(cstate == NULL))
{
reuseBuffer(hloop_bufferpool(hevent_loop(io)), buf);
return;
Expand Down
14 changes: 3 additions & 11 deletions tunnels/client/http2/http2_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,6 @@ static void sendGrpcFinalData(tunnel_t *self, line_t *line, size_t stream_id)
static bool trySendRequest(tunnel_t *self, http2_client_con_state_t *con, size_t stream_id, shift_buffer_t *buf)
{
line_t *line = con->line;
if (con == NULL)
{
if (buf)
{
reuseBuffer(getLineBufferPool(con->line), buf);
}
return false;
}

char *data = NULL;
size_t len;
Expand Down Expand Up @@ -154,7 +146,7 @@ static int onHeaderCallback(nghttp2_session *session, const nghttp2_frame *frame
(void) value;
(void) valuelen;
(void) flags;
if (userdata == NULL)
if (WW_UNLIKELY(userdata == NULL))
{
return 0;
}
Expand Down Expand Up @@ -196,7 +188,7 @@ static int onDataChunkRecvCallback(nghttp2_session *session, uint8_t flags, int3
size_t len, void *userdata)
{
(void) flags;
if (userdata == NULL || len <= 0)
if (WW_UNLIKELY(userdata == NULL || len <= 0))
{
return 0;
}
Expand Down Expand Up @@ -260,7 +252,7 @@ static int onDataChunkRecvCallback(nghttp2_session *session, uint8_t flags, int3

static int onFrameRecvCallback(nghttp2_session *session, const nghttp2_frame *frame, void *userdata)
{
if (userdata == NULL)
if (WW_UNLIKELY(userdata == NULL))
{
return 0;
}
Expand Down
4 changes: 2 additions & 2 deletions tunnels/server/http2/http2_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ static int onHeaderCallback(nghttp2_session *session, const nghttp2_frame *frame
(void) namelen;
(void) valuelen;
(void) flags;
if (userdata == NULL)
if (WW_UNLIKELY(userdata == NULL))
{
return 0;
}
Expand Down Expand Up @@ -140,7 +140,7 @@ static int onDataChunkRecvCallback(nghttp2_session *session, uint8_t flags, int3

static int onFrameRecvCallback(nghttp2_session *session, const nghttp2_frame *frame, void *userdata)
{
if (userdata == NULL)
if (WW_UNLIKELY(userdata == NULL))
{
return 0;
}
Expand Down

0 comments on commit e8d2ae5

Please sign in to comment.