Pass field names as Slice for another 15% speed up.

This commit is contained in:
levlam 2023-09-29 14:05:21 +03:00
parent d84a021a48
commit 6076e0e2a6

View File

@ -20,9 +20,9 @@ class TlStorerToString {
StringBuilder sb_ = StringBuilder(buffer_.as_slice(), true);
size_t shift_ = 0;
void store_field_begin(const char *name) {
void store_field_begin(Slice name) {
sb_.append_char(shift_, ' ');
if (name && name[0]) {
if (!name.empty()) {
sb_ << name << " = ";
}
}
@ -51,7 +51,7 @@ class TlStorerToString {
TlStorerToString(TlStorerToString &&) = delete;
TlStorerToString &operator=(TlStorerToString &&) = delete;
void store_field(const char *name, const string &value) {
void store_field(Slice name, const string &value) {
store_field_begin(name);
sb_.push_back('"');
sb_ << value;
@ -59,27 +59,27 @@ class TlStorerToString {
store_field_end();
}
void store_field(const char *name, const SecureString &value) {
void store_field(Slice name, const SecureString &value) {
store_field_begin(name);
sb_ << "<secret>";
store_field_end();
}
template <class T>
void store_field(const char *name, const T &value) {
void store_field(Slice name, const T &value) {
store_field_begin(name);
sb_ << value;
store_field_end();
}
void store_bytes_field(const char *name, const SecureString &value) {
void store_bytes_field(Slice name, const SecureString &value) {
store_field_begin(name);
sb_ << "<secret>";
store_field_end();
}
template <class BytesT>
void store_bytes_field(const char *name, const BytesT &value) {
void store_bytes_field(Slice name, const BytesT &value) {
static const char *hex = "0123456789ABCDEF";
store_field_begin(name);
@ -99,34 +99,34 @@ class TlStorerToString {
}
template <class ObjectT>
void store_object_field(const char *name, const ObjectT *value) {
void store_object_field(CSlice name, const ObjectT *value) {
if (value == nullptr) {
store_field(name, Slice("null"));
} else {
value->store(*this, name);
value->store(*this, name.c_str());
}
}
void store_field(const char *name, const UInt128 &value) {
void store_field(Slice name, const UInt128 &value) {
store_field_begin(name);
store_binary(as_slice(value));
store_field_end();
}
void store_field(const char *name, const UInt256 &value) {
void store_field(Slice name, const UInt256 &value) {
store_field_begin(name);
store_binary(as_slice(value));
store_field_end();
}
void store_vector_begin(const char *field_name, size_t vector_size) {
void store_vector_begin(Slice field_name, size_t vector_size) {
store_field_begin(field_name);
sb_ << "vector[" << vector_size << "] {\n";
shift_ += 2;
}
void store_class_begin(const char *field_name, const char *class_name) {
store_field_begin(field_name);
void store_class_begin(const char *field_name, Slice class_name) {
store_field_begin(Slice(field_name));
sb_ << class_name << " {\n";
shift_ += 2;
}