Don't use min/max as variable names.

This commit is contained in:
levlam 2021-12-15 20:55:03 +03:00
parent fe6c61f2ea
commit 1a98ac8004
5 changed files with 41 additions and 41 deletions

View File

@ -7347,7 +7347,7 @@ void Td::on_request(uint64 id, td_api::setOption &request) {
LOG(INFO) << "Set option " << request.name_;
auto set_integer_option = [&](Slice name, int64 min = 0, int64 max = std::numeric_limits<int32>::max()) {
auto set_integer_option = [&](Slice name, int64 min_value = 0, int64 max_value = std::numeric_limits<int32>::max()) {
if (request.name_ != name) {
return false;
}
@ -7360,13 +7360,13 @@ void Td::on_request(uint64 id, td_api::setOption &request) {
G()->shared_config().set_option_empty(name);
} else {
int64 value = static_cast<td_api::optionValueInteger *>(request.value_.get())->value_;
if (value < min || value > max) {
if (value < min_value || value > max_value) {
send_error_raw(id, 400,
PSLICE() << "Option's \"" << name << "\" value " << value << " is outside of a valid range ["
<< min << ", " << max << "]");
<< min_value << ", " << max_value << "]");
return true;
}
G()->shared_config().set_option_integer(name, clamp(value, min, max));
G()->shared_config().set_option_integer(name, clamp(value, min_value, max_value));
}
send_closure(actor_id(this), &Td::send_result, id, make_tl_object<td_api::ok>());
return true;

View File

@ -134,18 +134,18 @@ uint64 Random::fast_uint64() {
return static_cast<uint64>((*gen)());
}
int Random::fast(int min, int max) {
if (min == std::numeric_limits<int>::min() && max == std::numeric_limits<int>::max()) {
int Random::fast(int min_value, int max_value) {
if (min_value == std::numeric_limits<int>::min() && max_value == std::numeric_limits<int>::max()) {
// to prevent integer overflow and division by zero
min++;
min_value++;
}
DCHECK(min <= max);
return static_cast<int>(min + fast_uint32() % (max - min + 1)); // TODO signed_cast
DCHECK(min_value <= max_value);
return static_cast<int>(min_value + fast_uint32() % (max_value - min_value + 1)); // TODO signed_cast
}
double Random::fast(double min, double max) {
DCHECK(min <= max);
return min + fast_uint32() * 1.0 / std::numeric_limits<uint32>::max() * (max - min);
double Random::fast(double min_value, double max_value) {
DCHECK(min_value <= max_value);
return min_value + fast_uint32() * 1.0 / std::numeric_limits<uint32>::max() * (max_value - min_value);
}
bool Random::fast_bool() {
@ -179,11 +179,11 @@ uint64 Random::Xorshift128plus::operator()() {
return seed_[1] + y;
}
int Random::Xorshift128plus::fast(int min, int max) {
return static_cast<int>((*this)() % (max - min + 1) + min);
int Random::Xorshift128plus::fast(int min_value, int max_value) {
return static_cast<int>((*this)() % (max_value - min_value + 1) + min_value);
}
int64 Random::Xorshift128plus::fast64(int64 min, int64 max) {
return static_cast<int64>((*this)() % (max - min + 1) + min);
int64 Random::Xorshift128plus::fast64(int64 min_value, int64 max_value) {
return static_cast<int64>((*this)() % (max_value - min_value + 1) + min_value);
}
void Random::Xorshift128plus::bytes(MutableSlice dest) {

View File

@ -32,9 +32,9 @@ class Random {
static uint32 fast_uint32();
static uint64 fast_uint64();
// distribution is not uniform, min and max are included
static int fast(int min, int max);
static double fast(double min, double max);
// distribution is not uniform, min_value and max_value are included
static int fast(int min_value, int max_value);
static double fast(double min_value, double max_value);
static bool fast_bool();
class Fast {
@ -48,8 +48,8 @@ class Random {
explicit Xorshift128plus(uint64 seed);
Xorshift128plus(uint64 seed_a, uint64 seed_b);
uint64 operator()();
int fast(int min, int max);
int64 fast64(int64 min, int64 max);
int fast(int min_value, int max_value);
int64 fast64(int64 min_value, int64 max_value);
void bytes(MutableSlice dest);
private:

View File

@ -790,10 +790,10 @@ const NativeFd &UdpSocketFd::get_native_fd() const {
}
#if TD_PORT_POSIX
static Result<uint32> maximize_buffer(int socket_fd, int optname, uint32 max) {
if (setsockopt(socket_fd, SOL_SOCKET, optname, &max, sizeof(max)) == 0) {
static Result<uint32> maximize_buffer(int socket_fd, int optname, uint32 max_size) {
if (setsockopt(socket_fd, SOL_SOCKET, optname, &max_size, sizeof(max_size)) == 0) {
// fast path
return max;
return max_size;
}
/* Start with the default size. */
@ -807,32 +807,32 @@ static Result<uint32> maximize_buffer(int socket_fd, int optname, uint32 max) {
#endif
/* Binary-search for the real maximum. */
uint32 last_good = old_size;
uint32 min = old_size;
while (min <= max) {
uint32 avg = min + (max - min) / 2;
if (setsockopt(socket_fd, SOL_SOCKET, optname, &avg, sizeof(avg)) == 0) {
last_good = avg;
min = avg + 1;
uint32 last_good_size = old_size;
uint32 min_size = old_size;
while (min_size <= max_size) {
uint32 avg_size = min_size + (max_size - min_size) / 2;
if (setsockopt(socket_fd, SOL_SOCKET, optname, &avg_size, sizeof(avg_size)) == 0) {
last_good_size = avg_size;
min_size = avg_size + 1;
} else {
max = avg - 1;
max_size = avg_size - 1;
}
}
return last_good;
return last_good_size;
}
Result<uint32> UdpSocketFd::maximize_snd_buffer(uint32 max) {
return maximize_buffer(get_native_fd().fd(), SO_SNDBUF, max == 0 ? DEFAULT_UDP_MAX_SND_BUFFER_SIZE : max);
Result<uint32> UdpSocketFd::maximize_snd_buffer(uint32 max_size) {
return maximize_buffer(get_native_fd().fd(), SO_SNDBUF, max_size == 0 ? DEFAULT_UDP_MAX_SND_BUFFER_SIZE : max_size);
}
Result<uint32> UdpSocketFd::maximize_rcv_buffer(uint32 max) {
return maximize_buffer(get_native_fd().fd(), SO_RCVBUF, max == 0 ? DEFAULT_UDP_MAX_RCV_BUFFER_SIZE : max);
Result<uint32> UdpSocketFd::maximize_rcv_buffer(uint32 max_size) {
return maximize_buffer(get_native_fd().fd(), SO_RCVBUF, max_size == 0 ? DEFAULT_UDP_MAX_RCV_BUFFER_SIZE : max_size);
}
#else
Result<uint32> UdpSocketFd::maximize_snd_buffer(uint32 max) {
Result<uint32> UdpSocketFd::maximize_snd_buffer(uint32 max_size) {
return 0;
}
Result<uint32> UdpSocketFd::maximize_rcv_buffer(uint32 max) {
Result<uint32> UdpSocketFd::maximize_rcv_buffer(uint32 max_size) {
return 0;
}
#endif

View File

@ -45,8 +45,8 @@ class UdpSocketFd {
UdpSocketFd(const UdpSocketFd &) = delete;
UdpSocketFd &operator=(const UdpSocketFd &) = delete;
Result<uint32> maximize_snd_buffer(uint32 max_buffer_size = 0);
Result<uint32> maximize_rcv_buffer(uint32 max_buffer_size = 0);
Result<uint32> maximize_snd_buffer(uint32 max_size = 0);
Result<uint32> maximize_rcv_buffer(uint32 max_size = 0);
static Result<UdpSocketFd> open(const IPAddress &address) TD_WARN_UNUSED_RESULT;