Skip to content

Commit

Permalink
[coro_http][clean code]remove some unused (#816)
Browse files Browse the repository at this point in the history
  • Loading branch information
qicosmos authored Nov 19, 2024
1 parent fba32ec commit 8fe0523
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 52 deletions.
1 change: 0 additions & 1 deletion include/ylt/metric/summary_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ class summary_impl {
fltInt16 |= (fltInt32 >> 15) & 0xff;

auto i = fltInt16 >> (8 - frac_bit);
auto j = decode_impl(i);
return i;
}

Expand Down
8 changes: 4 additions & 4 deletions include/ylt/standalone/cinatra/gzip.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ inline bool inflate(std::string_view str_src, std::string &str_dest) {
// generated output
if (err == Z_STREAM_END) {
// Finish up
int kerr = ::inflateEnd(&zs);
[[maybe_unused]] int kerr = ::inflateEnd(&zs);

// Got a good result, set the size to the amount unzipped in this call
// (including all recursive calls)
Expand All @@ -202,7 +202,7 @@ inline bool inflate(std::string_view str_src, std::string &str_dest) {
str_dest.append((const char *)bytes_out,
OUTPUT_BUF_SIZE - zs.avail_out);

int kerr = ::inflateEnd(&zs);
[[maybe_unused]] int kerr = ::inflateEnd(&zs);

break;
}
Expand Down Expand Up @@ -252,7 +252,7 @@ inline bool deflate(std::string_view str_src, std::string &str_dest) {
// generated output
if (err == Z_STREAM_END) {
// Finish up
int kerr = ::deflateEnd(&zs);
[[maybe_unused]] int kerr = ::deflateEnd(&zs);

// Got a good result, set the size to the amount unzipped in this call
// (including all recursive calls)
Expand All @@ -277,7 +277,7 @@ inline bool deflate(std::string_view str_src, std::string &str_dest) {
str_dest.append((const char *)bytes_out,
OUTPUT_BUF_SIZE - zs.avail_out);

int kerr = ::deflateEnd(&zs);
[[maybe_unused]] int kerr = ::deflateEnd(&zs);

break;
}
Expand Down
1 change: 0 additions & 1 deletion include/ylt/standalone/cinatra/multipart.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ class multipart_reader_t {

part_head_t result{};
std::error_code ec{};
size_t last_size = chunked_buf_.size();
size_t size;

auto get_part_name = [](std::string_view data, std::string_view name,
Expand Down
38 changes: 0 additions & 38 deletions include/ylt/standalone/cinatra/picohttpparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -233,44 +233,6 @@ static const char *findchar_fast(const char *buf, const char *buf_end,
return buf;
}

static const char *findchar_nonprintable_fast(const char *buf,
const char *buf_end, int *found) {
#ifdef CINATRA_ARM_OPT
*found = 0;

const size_t block_size = sizeof(uint8x16_t) - 1;
const char *const end =
(size_t)(buf_end - buf) >= block_size ? buf_end - block_size : buf;

for (; buf < end; buf += sizeof(uint8x16_t)) {
uint8x16_t v = vld1q_u8((const uint8_t *)buf);

v = vorrq_u8(vcltq_u8(v, vmovq_n_u8('\041')),
vceqq_u8(v, vmovq_n_u8('\177')));

/* Pack the comparison result into 64 bits. */
const uint8x8_t rv = vshrn_n_u16(vreinterpretq_u16_u8(v), 4);
uint64_t offset = vget_lane_u64(vreinterpret_u64_u8(rv), 0);

if (offset) {
*found = 1;
__asm__("rbit %x0, %x0" : "+r"(offset));
static_assert(sizeof(unsigned long long) == sizeof(uint64_t),
"Need the number of leading 0-bits in uint64_t.");
/* offset uses 4 bits per byte of input. */
buf += __builtin_clzll(offset) / 4;
break;
}
}

return buf;
#else
static const char ALIGNED(16) ranges2[16] = "\000\040\177\177";

return findchar_fast(buf, buf_end, ranges2, 4, found);
#endif
}

static const char *get_token_to_eol(const char *buf, const char *buf_end,
const char **token, size_t *token_len,
int *ret) {
Expand Down
12 changes: 6 additions & 6 deletions src/coro_http/tests/test_cinatra.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ TEST_CASE("test for gzip") {
std::string uri = "http://127.0.0.1:8090/gzip";
client.add_header("Content-Encoding", "gzip");
auto result = async_simple::coro::syncAwait(client.async_get(uri));
auto content = get_header_value(result.resp_headers, "Content-Encoding");
// auto content = get_header_value(result.resp_headers, "Content-Encoding");
CHECK(get_header_value(result.resp_headers, "Content-Encoding") == "gzip");
CHECK(result.resp_body == "hello world");
}
Expand All @@ -69,7 +69,7 @@ TEST_CASE("test for gzip") {
std::string uri = "http://127.0.0.1:8090/deflate";
client.add_header("Content-Encoding", "deflate");
auto result = async_simple::coro::syncAwait(client.async_get(uri));
auto content = get_header_value(result.resp_headers, "Content-Encoding");
// auto content = get_header_value(result.resp_headers, "Content-Encoding");
CHECK(get_header_value(result.resp_headers, "Content-Encoding") ==
"deflate");
CHECK(result.resp_body == "hello world");
Expand All @@ -96,7 +96,7 @@ TEST_CASE("test encoding type") {
if (encoding_type ==
content_encoding::gzip) { // only post request have this field
std::string decode_str;
bool r = gzip_codec::uncompress(req.get_body(), decode_str);
gzip_codec::uncompress(req.get_body(), decode_str);
CHECK(decode_str == "Hello World");
}
resp.set_status_and_content(status_type::ok, "ok", content_encoding::gzip,
Expand Down Expand Up @@ -1889,7 +1889,7 @@ TEST_CASE("test coro_http_client chunked upload and download") {
CHECK(code);
}
auto sizes = {1024 * 1024, 2'000'000, 1024, 100, 0};
for (auto size : sizes) {
for ([[maybe_unused]] auto size : sizes) {
std::string filename = "test_chunked_upload.txt";
std::error_code ec{};
fs::remove(filename, ec);
Expand Down Expand Up @@ -1984,8 +1984,8 @@ TEST_CASE("test coro_http_client async_get") {

auto r1 =
async_simple::coro::syncAwait(client.async_get("http://www.baidu.com"));
CHECK(!r.net_err);
CHECK(r.status == 200);
CHECK(!r1.net_err);
CHECK(r1.status == 200);
}

TEST_CASE("test basic http request") {
Expand Down
4 changes: 2 additions & 2 deletions src/coro_http/tests/test_cinatra_websocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ async_simple::coro::Lazy<void> test_websocket(coro_http_client &client) {
co_return;
}

auto result = co_await client.write_websocket("hello websocket");
co_await client.write_websocket("hello websocket");
auto data = co_await client.read_websocket();
CHECK(data.resp_body == "hello websocket");
co_await client.write_websocket("test again");
Expand All @@ -81,7 +81,7 @@ async_simple::coro::Lazy<void> test_gzip_websocket(coro_http_client &client) {
}

std::string str = "hello websocket";
auto result = co_await client.write_websocket(str.data(), str.size());
co_await client.write_websocket(str.data(), str.size());
auto data = co_await client.read_websocket();
CHECK(data.resp_body == "hello websocket");

Expand Down

0 comments on commit 8fe0523

Please sign in to comment.