Use uint32 instead of unsigned int if possible.
This commit is contained in:
parent
9b7957c9c6
commit
0782f56408
@ -591,7 +591,7 @@ class QueueBenchmark2 final : public td::Benchmark {
|
||||
|
||||
void server_process(qvalue_t value) {
|
||||
int no = value & 0x00FFFFFF;
|
||||
int co = static_cast<int>(static_cast<unsigned int>(value) >> 24);
|
||||
int co = static_cast<int>(static_cast<td::uint32>(value) >> 24);
|
||||
// std::fprintf(stderr, "-->%d %d\n", co, no);
|
||||
if (co < 0 || co >= connections_n || no != server_conn[co]++) {
|
||||
std::fprintf(stderr, "%d %d\n", co, no);
|
||||
@ -632,7 +632,7 @@ class QueueBenchmark2 final : public td::Benchmark {
|
||||
|
||||
void client_process(qvalue_t value) {
|
||||
int no = value & 0x00FFFFFF;
|
||||
int co = static_cast<int>(static_cast<unsigned int>(value) >> 24);
|
||||
int co = static_cast<int>(static_cast<td::uint32>(value) >> 24);
|
||||
// std::fprintf(stderr, "<--%d %d\n", co, no);
|
||||
if (co < 0 || co >= connections_n || no != client_conn[co]++) {
|
||||
std::fprintf(stderr, "%d %d\n", co, no);
|
||||
|
@ -121,10 +121,10 @@ void init_vars(JNIEnv *env, const char *td_api_java_package) {
|
||||
static size_t get_utf8_from_utf16_length(const jchar *p, jsize len) {
|
||||
size_t result = 0;
|
||||
for (jsize i = 0; i < len; i++) {
|
||||
unsigned int cur = p[i];
|
||||
uint32 cur = p[i];
|
||||
if ((cur & 0xF800) == 0xD800) {
|
||||
if (i < len) {
|
||||
unsigned int next = p[++i];
|
||||
uint32 next = p[++i];
|
||||
if ((next & 0xFC00) == 0xDC00 && (cur & 0x400) == 0) {
|
||||
result += 4;
|
||||
continue;
|
||||
@ -141,8 +141,8 @@ static size_t get_utf8_from_utf16_length(const jchar *p, jsize len) {
|
||||
|
||||
static void utf16_to_utf8(const jchar *p, jsize len, char *res) {
|
||||
for (jsize i = 0; i < len; i++) {
|
||||
unsigned int cur = p[i];
|
||||
// TODO conversion unsigned int -> signed char is implementation defined
|
||||
uint32 cur = p[i];
|
||||
// TODO conversion uint32 -> signed char is implementation defined
|
||||
if (cur <= 0x7f) {
|
||||
*res++ = static_cast<char>(cur);
|
||||
} else if (cur <= 0x7ff) {
|
||||
@ -154,8 +154,8 @@ static void utf16_to_utf8(const jchar *p, jsize len, char *res) {
|
||||
*res++ = static_cast<char>(0x80 | (cur & 0x3f));
|
||||
} else {
|
||||
// correctness is already checked
|
||||
unsigned int next = p[++i];
|
||||
unsigned int val = ((cur - 0xD800) << 10) + next - 0xDC00 + 0x10000;
|
||||
uint32 next = p[++i];
|
||||
uint32 val = ((cur - 0xD800) << 10) + next - 0xDC00 + 0x10000;
|
||||
|
||||
*res++ = static_cast<char>(0xf0 | (val >> 18));
|
||||
*res++ = static_cast<char>(0x80 | ((val >> 12) & 0x3f));
|
||||
@ -178,14 +178,14 @@ static jsize get_utf16_from_utf8_length(const char *p, size_t len, jsize *surrog
|
||||
static void utf8_to_utf16(const char *p, size_t len, jchar *res) {
|
||||
// UTF-8 correctness is supposed
|
||||
for (size_t i = 0; i < len;) {
|
||||
unsigned int a = static_cast<unsigned char>(p[i++]);
|
||||
uint32 a = static_cast<unsigned char>(p[i++]);
|
||||
if (a >= 0x80) {
|
||||
unsigned int b = static_cast<unsigned char>(p[i++]);
|
||||
uint32 b = static_cast<unsigned char>(p[i++]);
|
||||
if (a >= 0xe0) {
|
||||
unsigned int c = static_cast<unsigned char>(p[i++]);
|
||||
uint32 c = static_cast<unsigned char>(p[i++]);
|
||||
if (a >= 0xf0) {
|
||||
unsigned int d = static_cast<unsigned char>(p[i++]);
|
||||
unsigned int val = ((a & 0x07) << 18) + ((b & 0x3f) << 12) + ((c & 0x3f) << 6) + (d & 0x3f) - 0x10000;
|
||||
uint32 d = static_cast<unsigned char>(p[i++]);
|
||||
uint32 val = ((a & 0x07) << 18) + ((b & 0x3f) << 12) + ((c & 0x3f) << 6) + (d & 0x3f) - 0x10000;
|
||||
*res++ = static_cast<jchar>(0xD800 + (val >> 10));
|
||||
*res++ = static_cast<jchar>(0xDC00 + (val & 0x3ff));
|
||||
} else {
|
||||
|
@ -96,11 +96,11 @@ StringBuilder &operator<<(StringBuilder &sb, const JsonString &val) {
|
||||
break;
|
||||
}
|
||||
if (128 <= ch) {
|
||||
int a = s[pos];
|
||||
uint32 a = ch;
|
||||
CHECK((a & 0x40) != 0);
|
||||
|
||||
CHECK(pos + 1 < len);
|
||||
int b = s[++pos];
|
||||
uint32 b = static_cast<unsigned char>(s[++pos]);
|
||||
CHECK((b & 0xc0) == 0x80);
|
||||
if ((a & 0x20) == 0) {
|
||||
CHECK((a & 0x1e) > 0);
|
||||
@ -109,7 +109,7 @@ StringBuilder &operator<<(StringBuilder &sb, const JsonString &val) {
|
||||
}
|
||||
|
||||
CHECK(pos + 1 < len);
|
||||
int c = s[++pos];
|
||||
uint32 c = static_cast<unsigned char>(s[++pos]);
|
||||
CHECK((c & 0xc0) == 0x80);
|
||||
if ((a & 0x10) == 0) {
|
||||
CHECK(((a & 0x0f) | (b & 0x20)) > 0);
|
||||
@ -118,7 +118,7 @@ StringBuilder &operator<<(StringBuilder &sb, const JsonString &val) {
|
||||
}
|
||||
|
||||
CHECK(pos + 1 < len);
|
||||
int d = s[++pos];
|
||||
uint32 d = static_cast<unsigned char>(s[++pos]);
|
||||
CHECK((d & 0xc0) == 0x80);
|
||||
if ((a & 0x08) == 0) {
|
||||
CHECK(((a & 0x07) | (b & 0x30)) > 0);
|
||||
|
@ -95,7 +95,7 @@ class JsonFloat {
|
||||
|
||||
class JsonOneChar {
|
||||
public:
|
||||
explicit JsonOneChar(unsigned int c) : c_(c) {
|
||||
explicit JsonOneChar(uint32 c) : c_(c) {
|
||||
}
|
||||
|
||||
friend StringBuilder &operator<<(StringBuilder &sb, const JsonOneChar &val) {
|
||||
@ -105,12 +105,12 @@ class JsonOneChar {
|
||||
}
|
||||
|
||||
private:
|
||||
unsigned int c_;
|
||||
uint32 c_;
|
||||
};
|
||||
|
||||
class JsonChar {
|
||||
public:
|
||||
explicit JsonChar(unsigned int c) : c_(c) {
|
||||
explicit JsonChar(uint32 c) : c_(c) {
|
||||
}
|
||||
friend StringBuilder &operator<<(StringBuilder &sb, const JsonChar &val) {
|
||||
auto c = val.c_;
|
||||
@ -129,7 +129,7 @@ class JsonChar {
|
||||
}
|
||||
|
||||
private:
|
||||
unsigned int c_;
|
||||
uint32 c_;
|
||||
};
|
||||
|
||||
class JsonRaw {
|
||||
|
@ -185,13 +185,13 @@ static bool is_base64_impl(Slice input) {
|
||||
}
|
||||
|
||||
if ((input.size() & 3) == 2) {
|
||||
auto value = table[static_cast<int>(input.back())];
|
||||
auto value = table[static_cast<unsigned char>(input.back())];
|
||||
if ((value & 15) != 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if ((input.size() & 3) == 3) {
|
||||
auto value = table[static_cast<int>(input.back())];
|
||||
auto value = table[static_cast<unsigned char>(input.back())];
|
||||
if ((value & 3) != 0) {
|
||||
return false;
|
||||
}
|
||||
|
@ -73,7 +73,7 @@ Logger::Logger(LogInterface &log, const LogOptions &options, int log_level, Slic
|
||||
|
||||
// log level
|
||||
sb_ << '[';
|
||||
if (static_cast<unsigned int>(log_level) < 10) {
|
||||
if (static_cast<uint32>(log_level) < 10) {
|
||||
sb_ << ' ' << static_cast<char>('0' + log_level);
|
||||
} else {
|
||||
sb_ << log_level;
|
||||
@ -83,7 +83,7 @@ Logger::Logger(LogInterface &log, const LogOptions &options, int log_level, Slic
|
||||
// thread id
|
||||
auto thread_id = get_thread_id();
|
||||
sb_ << "[t";
|
||||
if (static_cast<unsigned int>(thread_id) < 10) {
|
||||
if (static_cast<uint32>(thread_id) < 10) {
|
||||
sb_ << ' ' << static_cast<char>('0' + thread_id);
|
||||
} else {
|
||||
sb_ << thread_id;
|
||||
@ -109,7 +109,7 @@ Logger::Logger(LogInterface &log, const LogOptions &options, int log_level, Slic
|
||||
last_slash_--;
|
||||
}
|
||||
file_name = file_name.substr(last_slash_ + 1);
|
||||
sb_ << '[' << file_name << ':' << static_cast<unsigned int>(line_num) << ']';
|
||||
sb_ << '[' << file_name << ':' << static_cast<uint32>(line_num) << ']';
|
||||
}
|
||||
|
||||
// context from tag_
|
||||
|
@ -29,14 +29,14 @@ Result<std::wstring> to_wstring(CSlice slice) {
|
||||
if (wstring_len) {
|
||||
wchar_t *res = &result[0];
|
||||
for (size_t i = 0; i < slice.size();) {
|
||||
unsigned int a = static_cast<unsigned char>(slice[i++]);
|
||||
uint32 a = static_cast<unsigned char>(slice[i++]);
|
||||
if (a >= 0x80) {
|
||||
unsigned int b = static_cast<unsigned char>(slice[i++]);
|
||||
uint32 b = static_cast<unsigned char>(slice[i++]);
|
||||
if (a >= 0xe0) {
|
||||
unsigned int c = static_cast<unsigned char>(slice[i++]);
|
||||
uint32 c = static_cast<unsigned char>(slice[i++]);
|
||||
if (a >= 0xf0) {
|
||||
unsigned int d = static_cast<unsigned char>(slice[i++]);
|
||||
unsigned int val = ((a & 0x07) << 18) + ((b & 0x3f) << 12) + ((c & 0x3f) << 6) + (d & 0x3f) - 0x10000;
|
||||
uint32 d = static_cast<unsigned char>(slice[i++]);
|
||||
uint32 val = ((a & 0x07) << 18) + ((b & 0x3f) << 12) + ((c & 0x3f) << 6) + (d & 0x3f) - 0x10000;
|
||||
*res++ = static_cast<wchar_t>(0xD800 + (val >> 10));
|
||||
*res++ = static_cast<wchar_t>(0xDC00 + (val & 0x3ff));
|
||||
} else {
|
||||
@ -57,10 +57,10 @@ Result<std::wstring> to_wstring(CSlice slice) {
|
||||
Result<string> from_wstring(const wchar_t *begin, size_t size) {
|
||||
size_t result_len = 0;
|
||||
for (size_t i = 0; i < size; i++) {
|
||||
unsigned int cur = begin[i];
|
||||
uint32 cur = begin[i];
|
||||
if ((cur & 0xF800) == 0xD800) {
|
||||
if (i < size) {
|
||||
unsigned int next = begin[++i];
|
||||
uint32 next = begin[++i];
|
||||
if ((next & 0xFC00) == 0xDC00 && (cur & 0x400) == 0) {
|
||||
result_len += 4;
|
||||
continue;
|
||||
@ -76,8 +76,8 @@ Result<string> from_wstring(const wchar_t *begin, size_t size) {
|
||||
if (result_len) {
|
||||
char *res = &result[0];
|
||||
for (size_t i = 0; i < size; i++) {
|
||||
unsigned int cur = begin[i];
|
||||
// TODO conversion unsigned int -> signed char is implementation defined
|
||||
uint32 cur = begin[i];
|
||||
// TODO conversion uint32 -> signed char is implementation defined
|
||||
if (cur <= 0x7f) {
|
||||
*res++ = static_cast<char>(cur);
|
||||
} else if (cur <= 0x7ff) {
|
||||
@ -88,8 +88,8 @@ Result<string> from_wstring(const wchar_t *begin, size_t size) {
|
||||
*res++ = static_cast<char>(0x80 | ((cur >> 6) & 0x3f));
|
||||
*res++ = static_cast<char>(0x80 | (cur & 0x3f));
|
||||
} else {
|
||||
unsigned int next = begin[++i];
|
||||
unsigned int val = ((cur - 0xD800) << 10) + next - 0xDC00 + 0x10000;
|
||||
uint32 next = begin[++i];
|
||||
uint32 val = ((cur - 0xD800) << 10) + next - 0xDC00 + 0x10000;
|
||||
|
||||
*res++ = static_cast<char>(0xf0 | (val >> 18));
|
||||
*res++ = static_cast<char>(0x80 | ((val >> 12) & 0x3f));
|
||||
|
@ -15,7 +15,7 @@ bool check_utf8(CSlice str) {
|
||||
const char *data = str.data();
|
||||
const char *data_end = data + str.size();
|
||||
do {
|
||||
unsigned int a = static_cast<unsigned char>(*data++);
|
||||
uint32 a = static_cast<unsigned char>(*data++);
|
||||
if ((a & 0x80) == 0) {
|
||||
if (data == data_end + 1) {
|
||||
return true;
|
||||
@ -30,25 +30,25 @@ bool check_utf8(CSlice str) {
|
||||
|
||||
ENSURE((a & 0x40) != 0);
|
||||
|
||||
unsigned int b = static_cast<unsigned char>(*data++);
|
||||
uint32 b = static_cast<unsigned char>(*data++);
|
||||
ENSURE((b & 0xc0) == 0x80);
|
||||
if ((a & 0x20) == 0) {
|
||||
ENSURE((a & 0x1e) > 0);
|
||||
continue;
|
||||
}
|
||||
|
||||
unsigned int c = static_cast<unsigned char>(*data++);
|
||||
uint32 c = static_cast<unsigned char>(*data++);
|
||||
ENSURE((c & 0xc0) == 0x80);
|
||||
if ((a & 0x10) == 0) {
|
||||
int x = (((a & 0x0f) << 6) | (b & 0x20));
|
||||
uint32 x = (((a & 0x0f) << 6) | (b & 0x20));
|
||||
ENSURE(x != 0 && x != 0x360); // surrogates
|
||||
continue;
|
||||
}
|
||||
|
||||
unsigned int d = static_cast<unsigned char>(*data++);
|
||||
uint32 d = static_cast<unsigned char>(*data++);
|
||||
ENSURE((d & 0xc0) == 0x80);
|
||||
if ((a & 0x08) == 0) {
|
||||
int t = (((a & 0x07) << 6) | (b & 0x30));
|
||||
uint32 t = (((a & 0x07) << 6) | (b & 0x30));
|
||||
ENSURE(0 < t && t < 0x110); // end of unicode
|
||||
continue;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user