Skip to content

Commit

Permalink
TL fetch: optimize tl_Dictionary (#1051)
Browse files Browse the repository at this point in the history
Reserve enough space to prevent array reallocations
  • Loading branch information
apolyakov authored Aug 2, 2024
1 parent 8ac7ded commit be12bf9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

.idea
.vscode
.cache
build
*.iml
/cmake-build-*
Expand Down
10 changes: 5 additions & 5 deletions runtime/tl/tl_builtins.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@

#pragma once

#include <cstdint>
#include <memory>

#include "common/tl/constants/common.h"

#include "runtime-core/include.h"
#include "runtime/interface.h"
#include "runtime-core/runtime-core.h"
#include "runtime/rpc.h"
#include "runtime/tl/rpc_function.h"
#include "runtime/tl/rpc_tl_query.h"
Expand Down Expand Up @@ -508,12 +507,12 @@ struct tl_Dictionary_impl {

array<mixed> fetch() {
CHECK_EXCEPTION(return array<mixed>());
array<mixed> result;
int32_t n = rpc_fetch_int();
if (n < 0) {
CurrentTlQuery::get().raise_fetching_error("Dictionary size is negative");
return result;
return {};
}
array<mixed> result{array_size{n, false}};
for (int32_t i = 0; i < n; ++i) {
const auto &key = KeyT().fetch();
fetch_magic_if_not_bare(inner_value_magic, "Incorrect magic of inner type of some Dictionary");
Expand Down Expand Up @@ -547,6 +546,7 @@ struct tl_Dictionary_impl {
CurrentTlQuery::get().raise_fetching_error("Dictionary size is negative");
return;
}
out.reserve(n, false);
for (int32_t i = 0; i < n; ++i) {
typename KeyT::PhpType key;
KeyT().typed_fetch_to(key);
Expand Down

0 comments on commit be12bf9

Please sign in to comment.