Remove some misc.h usages in headers.
GitOrigin-RevId: 3f5ca0369113e9815935a6c6cb0fe0c5a051c248
This commit is contained in:
parent
0618005a95
commit
12cd507909
@ -18,7 +18,6 @@
|
||||
#include "td/utils/common.h"
|
||||
#include "td/utils/format.h"
|
||||
#include "td/utils/logging.h"
|
||||
#include "td/utils/misc.h"
|
||||
#include "td/utils/Slice.h"
|
||||
#include "td/utils/StringBuilder.h"
|
||||
#include "td/utils/Variant.h"
|
||||
@ -404,11 +403,11 @@ class FullRemoteFileLocation {
|
||||
case FileType::Photo:
|
||||
return make_tl_object<telegram_api::inputPhotoFileLocation>(
|
||||
photo().id_, photo().access_hash_, BufferSlice(file_reference_),
|
||||
std::string(1, static_cast<char>(narrow_cast<uint8>(thumbnail.thumbnail_type))));
|
||||
std::string(1, static_cast<char>(static_cast<uint8>(thumbnail.thumbnail_type))));
|
||||
case FileType::Thumbnail:
|
||||
return make_tl_object<telegram_api::inputDocumentFileLocation>(
|
||||
photo().id_, photo().access_hash_, BufferSlice(file_reference_),
|
||||
std::string(1, static_cast<char>(narrow_cast<uint8>(thumbnail.thumbnail_type))));
|
||||
std::string(1, static_cast<char>(static_cast<uint8>(thumbnail.thumbnail_type))));
|
||||
default:
|
||||
UNREACHABLE();
|
||||
break;
|
||||
|
@ -7,8 +7,8 @@
|
||||
#pragma once
|
||||
|
||||
#include "td/utils/common.h"
|
||||
#include "td/utils/misc.h"
|
||||
|
||||
#include <limits>
|
||||
#include <map>
|
||||
#include <tuple>
|
||||
|
||||
@ -20,7 +20,8 @@ class Enumerator {
|
||||
using Key = int32;
|
||||
|
||||
Key add(ValueT v) {
|
||||
int32 next_id = narrow_cast<int32>(arr_.size() + 1);
|
||||
CHECK(arr_.size() < static_cast<size_t>(std::numeric_limits<int32>::max() - 1));
|
||||
int32 next_id = static_cast<int32>(arr_.size() + 1);
|
||||
bool was_inserted;
|
||||
decltype(map_.begin()) it;
|
||||
std::tie(it, was_inserted) = map_.emplace(std::move(v), next_id);
|
||||
|
@ -7,8 +7,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "td/utils/common.h"
|
||||
#include "td/utils/logging.h"
|
||||
#include "td/utils/misc.h"
|
||||
#include "td/utils/port/thread_local.h"
|
||||
#include "td/utils/Slice.h"
|
||||
|
||||
@ -605,7 +603,7 @@ class ChainBufferReader {
|
||||
}
|
||||
|
||||
ChainBufferReader cut_head(size_t offset) TD_WARN_UNUSED_RESULT {
|
||||
LOG_CHECK(offset <= size()) << offset << " " << size();
|
||||
CHECK(offset <= size());
|
||||
auto it = begin_.clone();
|
||||
it.advance(offset);
|
||||
return cut_head(std::move(it));
|
||||
@ -753,8 +751,8 @@ class BufferBuilder {
|
||||
|
||||
template <class F>
|
||||
void for_each(F &&f) const & {
|
||||
for (auto &slice : reversed(to_prepend_)) {
|
||||
f(slice.as_slice());
|
||||
for (auto i = to_prepend_.size(); i > 0; i--) {
|
||||
f(to_prepend_[i - 1].as_slice());
|
||||
}
|
||||
if (!buffer_writer_.empty()) {
|
||||
f(buffer_writer_.as_slice());
|
||||
@ -765,8 +763,8 @@ class BufferBuilder {
|
||||
}
|
||||
template <class F>
|
||||
void for_each(F &&f) && {
|
||||
for (auto &slice : reversed(to_prepend_)) {
|
||||
f(std::move(slice));
|
||||
for (auto i = to_prepend_.size(); i > 0; i--) {
|
||||
f(std::move(to_prepend_[i - 1]));
|
||||
}
|
||||
if (!buffer_writer_.empty()) {
|
||||
f(buffer_writer_.as_buffer_slice());
|
||||
|
@ -6,10 +6,30 @@
|
||||
//
|
||||
#include "td/utils/tl_parsers.h"
|
||||
|
||||
#include "td/utils/misc.h"
|
||||
|
||||
namespace td {
|
||||
|
||||
alignas(4) const unsigned char TlParser::empty_data[sizeof(UInt256)] = {}; // static zero-initialized
|
||||
|
||||
TlParser::TlParser(Slice slice) {
|
||||
data_len = left_len = slice.size();
|
||||
if (is_aligned_pointer<4>(slice.begin())) {
|
||||
data = slice.ubegin();
|
||||
} else {
|
||||
int32 *buf;
|
||||
if (data_len <= small_data_array.size() * sizeof(int32)) {
|
||||
buf = &small_data_array[0];
|
||||
} else {
|
||||
LOG(ERROR) << "Unexpected big unaligned data pointer of length " << slice.size() << " at " << slice.begin();
|
||||
data_buf = std::make_unique<int32[]>(1 + data_len / sizeof(int32));
|
||||
buf = data_buf.get();
|
||||
}
|
||||
std::memcpy(buf, slice.begin(), slice.size());
|
||||
data = reinterpret_cast<unsigned char *>(buf);
|
||||
}
|
||||
}
|
||||
|
||||
void TlParser::set_error(const string &error_message) {
|
||||
if (error.empty()) {
|
||||
CHECK(!error_message.empty());
|
||||
@ -27,4 +47,11 @@ void TlParser::set_error(const string &error_message) {
|
||||
}
|
||||
}
|
||||
|
||||
BufferSlice TlBufferParser::as_buffer_slice(Slice slice) {
|
||||
if (is_aligned_pointer<4>(slice.data())) {
|
||||
return parent_->from_slice(slice);
|
||||
}
|
||||
return BufferSlice(slice);
|
||||
}
|
||||
|
||||
} // namespace td
|
||||
|
@ -10,7 +10,6 @@
|
||||
#include "td/utils/common.h"
|
||||
#include "td/utils/format.h"
|
||||
#include "td/utils/logging.h"
|
||||
#include "td/utils/misc.h"
|
||||
#include "td/utils/Slice.h"
|
||||
#include "td/utils/Status.h"
|
||||
#include "td/utils/UInt.h"
|
||||
@ -38,23 +37,7 @@ class TlParser {
|
||||
alignas(4) static const unsigned char empty_data[sizeof(UInt256)];
|
||||
|
||||
public:
|
||||
explicit TlParser(Slice slice) {
|
||||
data_len = left_len = slice.size();
|
||||
if (is_aligned_pointer<4>(slice.begin())) {
|
||||
data = slice.ubegin();
|
||||
} else {
|
||||
int32 *buf;
|
||||
if (data_len <= small_data_array.size() * sizeof(int32)) {
|
||||
buf = &small_data_array[0];
|
||||
} else {
|
||||
LOG(ERROR) << "Unexpected big unaligned data pointer of length " << slice.size() << " at " << slice.begin();
|
||||
data_buf = std::make_unique<int32[]>(1 + data_len / sizeof(int32));
|
||||
buf = data_buf.get();
|
||||
}
|
||||
std::memcpy(buf, slice.begin(), slice.size());
|
||||
data = reinterpret_cast<unsigned char *>(buf);
|
||||
}
|
||||
}
|
||||
explicit TlParser(Slice slice);
|
||||
|
||||
TlParser(const TlParser &other) = delete;
|
||||
TlParser &operator=(const TlParser &other) = delete;
|
||||
@ -143,15 +126,15 @@ class TlParser {
|
||||
T fetch_string() {
|
||||
check_len(sizeof(int32));
|
||||
size_t result_len = *data;
|
||||
const char *result_begin;
|
||||
const unsigned char *result_begin;
|
||||
size_t result_aligned_len;
|
||||
if (result_len < 254) {
|
||||
result_begin = reinterpret_cast<const char *>(data + 1);
|
||||
result_begin = data + 1;
|
||||
result_aligned_len = (result_len >> 2) << 2;
|
||||
data += sizeof(int32);
|
||||
} else if (result_len == 254) {
|
||||
result_len = data[1] + (data[2] << 8) + (data[3] << 16);
|
||||
result_begin = reinterpret_cast<const char *>(data + 4);
|
||||
result_begin = data + 4;
|
||||
result_aligned_len = ((result_len + 3) >> 2) << 2;
|
||||
data += sizeof(int32);
|
||||
} else {
|
||||
@ -165,7 +148,7 @@ class TlParser {
|
||||
return T();
|
||||
}
|
||||
result_len = static_cast<size_t>(result_len_uint64);
|
||||
result_begin = reinterpret_cast<const char *>(data + 8);
|
||||
result_begin = data + 8;
|
||||
result_aligned_len = ((result_len + 3) >> 2) << 2;
|
||||
data += sizeof(int64);
|
||||
}
|
||||
@ -174,7 +157,7 @@ class TlParser {
|
||||
return T();
|
||||
}
|
||||
data += result_aligned_len;
|
||||
return T(result_begin, result_len);
|
||||
return T(reinterpret_cast<const char *>(result_begin), result_len);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
@ -204,6 +187,7 @@ class TlBufferParser : public TlParser {
|
||||
public:
|
||||
explicit TlBufferParser(const BufferSlice *buffer_slice) : TlParser(buffer_slice->as_slice()), parent_(buffer_slice) {
|
||||
}
|
||||
|
||||
template <class T>
|
||||
T fetch_string() {
|
||||
auto result = TlParser::fetch_string<T>();
|
||||
@ -230,6 +214,7 @@ class TlBufferParser : public TlParser {
|
||||
|
||||
return T();
|
||||
}
|
||||
|
||||
template <class T>
|
||||
T fetch_string_raw(const size_t size) {
|
||||
return TlParser::fetch_string_raw<T>(size);
|
||||
@ -238,12 +223,7 @@ class TlBufferParser : public TlParser {
|
||||
private:
|
||||
const BufferSlice *parent_;
|
||||
|
||||
BufferSlice as_buffer_slice(Slice slice) {
|
||||
if (is_aligned_pointer<4>(slice.data())) {
|
||||
return parent_->from_slice(slice);
|
||||
}
|
||||
return BufferSlice(slice);
|
||||
}
|
||||
BufferSlice as_buffer_slice(Slice slice);
|
||||
};
|
||||
|
||||
template <>
|
||||
|
@ -8,7 +8,6 @@
|
||||
|
||||
#include "td/utils/common.h"
|
||||
#include "td/utils/logging.h"
|
||||
#include "td/utils/misc.h"
|
||||
#include "td/utils/Slice.h"
|
||||
#include "td/utils/StorerBase.h"
|
||||
#include "td/utils/UInt.h"
|
||||
@ -22,7 +21,6 @@ class TlStorerUnsafe {
|
||||
|
||||
public:
|
||||
explicit TlStorerUnsafe(unsigned char *buf) : buf_(buf) {
|
||||
LOG_CHECK(is_aligned_pointer<4>(buf_)) << buf_;
|
||||
}
|
||||
|
||||
TlStorerUnsafe(const TlStorerUnsafe &other) = delete;
|
||||
|
Reference in New Issue
Block a user