Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add few builtins in runtime-light #1225

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

astrophysik
Copy link
Contributor

No description provided.

@astrophysik astrophysik added the k2 k2 related label Jan 23, 2025
@astrophysik astrophysik self-assigned this Jan 23, 2025
@astrophysik astrophysik requested a review from apolyakov January 23, 2025 12:26

#pragma once

#include "runtime-common/core/allocator/runtime-allocator.h"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing include <cstdint>

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. formatting
  2. braced initialization (highly recommended, but not required to get approve)
  3. replace unlikely() with [[unlikely]]
  4. I'd like to have better naming here, for example, ctx -> rt_ctx

@@ -181,3 +181,16 @@ void f$setrawcookie(const string &name, const string &value, int64_t expire_or_o
}
kphp::http::header({static_SB_spare.c_str(), static_SB_spare.size()}, false, kphp::http::status::NO_STATUS);
}

array<string> f$headers_list() noexcept {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe move it's implementation into the header?

@@ -181,3 +181,16 @@ void f$setrawcookie(const string &name, const string &value, int64_t expire_or_o
}
kphp::http::header({static_SB_spare.c_str(), static_SB_spare.size()}, false, kphp::http::status::NO_STATUS);
}

array<string> f$headers_list() noexcept {
auto &http_server_instance_st{HttpServerInstanceState::get()};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a thought: isn't it better to reduce number of variables in functions? Here, for example, we can get rid of http_server_instance_st as it's used only once

auto &http_server_instance_st{HttpServerInstanceState::get()};
const auto &headers{http_server_instance_st.headers()};

array<string> list;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add call to reserve


array<string> list;
for (const auto & header : headers) {
string value{(header.first + ": " + header.second).c_str()};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to temporary std::string here. It's better to use a combination of reserve_at_least and append

k2::iconv(&res, cd, nullptr, nullptr, nullptr, nullptr);
}

k2::iconv_close(cd);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's have it wrapped with vk::final_action


Optional<string> f$iconv(const string &input_encoding, const string &output_encoding, const string &input_str) noexcept {
iconv_t cd;
if (k2::iconv_open(&cd, output_encoding.c_str(), input_encoding.c_str()) != k2::errno_ok) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please use std::addressof instead of raw operator &.

Also, I'd appreciate if you add [[likely]]/[[unlikely]]. It's not a stopper btw

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
k2 k2 related
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants