From 8fe05238311f5de6427ed02a3241ffd27fcbfbde Mon Sep 17 00:00:00 2001 From: qicosmos Date: Tue, 19 Nov 2024 13:39:36 +0800 Subject: [PATCH] [coro_http][clean code]remove some unused (#816) --- include/ylt/metric/summary_impl.hpp | 1 - include/ylt/standalone/cinatra/gzip.hpp | 8 ++-- include/ylt/standalone/cinatra/multipart.hpp | 1 - .../ylt/standalone/cinatra/picohttpparser.h | 38 ------------------- src/coro_http/tests/test_cinatra.cpp | 12 +++--- .../tests/test_cinatra_websocket.cpp | 4 +- 6 files changed, 12 insertions(+), 52 deletions(-) diff --git a/include/ylt/metric/summary_impl.hpp b/include/ylt/metric/summary_impl.hpp index a6935c78c..cf48ed36b 100644 --- a/include/ylt/metric/summary_impl.hpp +++ b/include/ylt/metric/summary_impl.hpp @@ -73,7 +73,6 @@ class summary_impl { fltInt16 |= (fltInt32 >> 15) & 0xff; auto i = fltInt16 >> (8 - frac_bit); - auto j = decode_impl(i); return i; } diff --git a/include/ylt/standalone/cinatra/gzip.hpp b/include/ylt/standalone/cinatra/gzip.hpp index f8a099803..006874dda 100644 --- a/include/ylt/standalone/cinatra/gzip.hpp +++ b/include/ylt/standalone/cinatra/gzip.hpp @@ -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) @@ -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; } @@ -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) @@ -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; } diff --git a/include/ylt/standalone/cinatra/multipart.hpp b/include/ylt/standalone/cinatra/multipart.hpp index b85b5001f..154d082c3 100644 --- a/include/ylt/standalone/cinatra/multipart.hpp +++ b/include/ylt/standalone/cinatra/multipart.hpp @@ -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, diff --git a/include/ylt/standalone/cinatra/picohttpparser.h b/include/ylt/standalone/cinatra/picohttpparser.h index d57377a55..479a8c231 100644 --- a/include/ylt/standalone/cinatra/picohttpparser.h +++ b/include/ylt/standalone/cinatra/picohttpparser.h @@ -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) { diff --git a/src/coro_http/tests/test_cinatra.cpp b/src/coro_http/tests/test_cinatra.cpp index a5a2a4968..c321f7abd 100644 --- a/src/coro_http/tests/test_cinatra.cpp +++ b/src/coro_http/tests/test_cinatra.cpp @@ -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"); } @@ -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"); @@ -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, @@ -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); @@ -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") { diff --git a/src/coro_http/tests/test_cinatra_websocket.cpp b/src/coro_http/tests/test_cinatra_websocket.cpp index 402499ee7..14fe58f9a 100644 --- a/src/coro_http/tests/test_cinatra_websocket.cpp +++ b/src/coro_http/tests/test_cinatra_websocket.cpp @@ -61,7 +61,7 @@ async_simple::coro::Lazy 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"); @@ -81,7 +81,7 @@ async_simple::coro::Lazy 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");