Skip to content

Commit 01a7aa6

Browse files
authored
[k2] replace tl::is_int32_overflow with std::in_range (#1527)
1 parent 7a037d7 commit 01a7aa6

3 files changed

Lines changed: 6 additions & 10 deletions

File tree

runtime-light/stdlib/rpc/rpc-api.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ inline bool f$store_byte(int64_t v) noexcept {
8484
}
8585

8686
inline bool f$store_int(int64_t v) noexcept {
87-
if (tl::is_int32_overflow(v)) [[unlikely]] {
87+
if (!std::in_range<int32_t>(v)) [[unlikely]] {
8888
kphp::log::warning("integer {} overflows int32, it will be cast to {}", v, static_cast<int32_t>(v));
8989
}
9090
tl::i32{.value = static_cast<int32_t>(v)}.store(RpcServerInstanceState::get().tl_storer);
@@ -243,7 +243,7 @@ inline bool f$rpc_parse(const Optional<string>& new_rpc_data) noexcept {
243243
class_instance<C$VK$TL$RpcFunction> f$rpc_server_fetch_request() noexcept;
244244

245245
inline kphp::coro::task<bool> f$store_error(int64_t error_code, string error_msg) noexcept {
246-
if (tl::is_int32_overflow(error_code)) [[unlikely]] {
246+
if (!std::in_range<int32_t>(error_code)) [[unlikely]] {
247247
kphp::log::warning("error_code overflows int32, {} will be stored", static_cast<int32_t>(error_code));
248248
}
249249

runtime-light/stdlib/rpc/rpc-tl-builtins.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44

55
#include "runtime-light/stdlib/rpc/rpc-tl-builtins.h"
66

7+
#include <cstdint>
8+
#include <utility>
9+
710
#include "runtime-light/server/rpc/rpc-server-state.h"
811
#include "runtime-light/stdlib/diagnostics/logs.h"
9-
#include "runtime-light/tl/tl-core.h"
1012

1113
mixed tl_arr_get(const mixed& arr, const string& str_key, int64_t num_key, int64_t precomputed_hash) noexcept {
1214
auto& cur_query{CurrentTlQuery::get()};
@@ -28,7 +30,7 @@ mixed tl_arr_get(const mixed& arr, const string& str_key, int64_t num_key, int64
2830

2931
int32_t t_Int::prepare_int_for_storing(int64_t v) noexcept {
3032
auto v32{static_cast<int32_t>(v)};
31-
if (tl::is_int32_overflow(v)) [[unlikely]] {
33+
if (!std::in_range<int32_t>(v)) [[unlikely]] {
3234
if (RpcServerInstanceState::get().fail_rpc_on_int32_overflow) {
3335
CurrentTlQuery::get().raise_storing_error("Got int32 overflow with value '%" PRIi64 "'. Serialization will fail.", v);
3436
} else {

runtime-light/tl/tl-core.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,13 @@
1212
#include <span>
1313
#include <utility>
1414

15-
#include "common/algorithms/find.h"
1615
#include "runtime-common/core/allocator/script-allocator.h"
1716
#include "runtime-common/core/std/containers.h"
1817
#include "runtime-light/metaprogramming/concepts.h"
1918
#include "runtime-light/stdlib/diagnostics/logs.h"
2019

2120
namespace tl {
2221

23-
inline bool is_int32_overflow(int64_t v) noexcept {
24-
const auto v32{static_cast<int32_t>(v)};
25-
return vk::none_of_equal(v, int64_t{v32}, int64_t{static_cast<uint32_t>(v32)});
26-
}
27-
2822
class storer {
2923
static constexpr auto DEFAULT_BUFFER_CAPACITY = 1024;
3024

0 commit comments

Comments
 (0)