Skip to content

refactor: event id from const char* to string_view#469

Open
olgavrou wants to merge 12 commits into
VowpalWabbit:masterfrom
olgavrou:event_id_string_view
Open

refactor: event id from const char* to string_view#469
olgavrou wants to merge 12 commits into
VowpalWabbit:masterfrom
olgavrou:event_id_string_view

Conversation

@olgavrou
Copy link
Copy Markdown
Collaborator

No description provided.

@olgavrou olgavrou marked this pull request as ready for review March 25, 2022 21:22
@olgavrou olgavrou requested a review from lokitoth March 25, 2022 21:22
Comment thread rlclientlib/live_model_impl.cc Outdated
void continuous_action_response::set_event_id(const char* event_id) {
_event_id = event_id;
void continuous_action_response::set_event_id(string_view event_id) {
_event_id = std::string(event_id);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
_event_id = std::string(event_id);
_event_id = std::string{event_id};

void continuous_action_response::set_model_id(const char* model_id) {
_model_id = model_id;
void continuous_action_response::set_model_id(string_view model_id) {
_model_id = std::string(model_id);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
_model_id = std::string(model_id);
_model_id = std::string{model_id};

Comment thread rlclientlib/multistep.cc
void episode_history::update(const char* event_id, const char* previous_event_id, string_view context, const ranking_response& resp) {
_depths[event_id] = this->get_depth(previous_event_id) + 1;
void episode_history::update(string_view event_id, string_view previous_event_id, string_view context, const ranking_response& resp) {
_depths[std::string(event_id)] = this->get_depth(previous_event_id) + 1;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is not great... We get heterogeneous lookup in c++14 for map I believe. Doesn't help us here though

Comment thread rlclientlib/multistep.cc

std::string episode_history::get_context(const char* previous_event_id, string_view context) const {
std::string episode_history::get_context(string_view previous_event_id, string_view context) const {
return R"({"episode":{"depth":")" + std::to_string(this->get_depth(previous_event_id) + 1) + "\"}," + std::string(context.data() + 1);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not part of this PR, but this should probably at least use a string stream

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants