Skip to content

Commit

Permalink
refactor: Remove unnecessary copies
Browse files Browse the repository at this point in the history
  • Loading branch information
slavek-kucera authored Mar 18, 2024
1 parent 5230327 commit 7d929f5
Show file tree
Hide file tree
Showing 46 changed files with 110 additions and 105 deletions.
4 changes: 3 additions & 1 deletion language_server/src/parsing_metadata_serialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ void to_json(nlohmann::json& j, const telemetry_error& err)
if (err.error_details != "")
properties["error_details"] = err.error_details;
j = nlohmann::json {
{ "method_name", "server_error/" + err.error_type }, { "properties", properties }, { "measurements", {} }
{ "method_name", "server_error/" + std::string(err.error_type) },
{ "properties", properties },
{ "measurements", {} },
};
}

Expand Down
5 changes: 3 additions & 2 deletions language_server/src/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ void server::call_method(const std::string& method, std::optional<request_id> id
}
}

void server::send_telemetry_error(std::string where, std::string what)
void server::send_telemetry_error(std::string_view where, std::string_view what)
{
if (!telemetry_provider_)
return;
Expand All @@ -111,8 +111,9 @@ void server::telemetry_request_done(method_telemetry_data start)
{
if (telemetry_provider_ && !start.method_name.empty())
telemetry_provider_->send_telemetry(telemetry_info {
std::string(start.method_name),
start.method_name,
std::chrono::duration<double>(std::chrono::steady_clock::now() - start.start).count(),
std::nullopt,
});
}

Expand Down
4 changes: 2 additions & 2 deletions language_server/src/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
#include <chrono>
#include <map>
#include <string>
#include <string_view>
#include <unordered_map>
#include <utility>
#include <variant>
#include <vector>

#include "feature.h"
Expand Down Expand Up @@ -77,7 +77,7 @@ class server : public response_provider
// Calls a method that is registered in methods_ with the specified name with arguments and id of request.
void call_method(const std::string& method, std::optional<request_id> id, const nlohmann::json& args);

void send_telemetry_error(std::string where, std::string what = "");
void send_telemetry_error(std::string_view where, std::string_view what = "");

void cancel_request_handler(const nlohmann::json& args);

Expand Down
8 changes: 4 additions & 4 deletions language_server/src/telemetry_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#define HLASMPLUGIN_LANGUAGESERVER_TELEMETRY_INFO_H

#include <optional>
#include <string>
#include <string_view>
#include <variant>

#include "protocol.h"
Expand All @@ -30,15 +30,15 @@ struct telemetry_metrics_info

struct telemetry_info
{
std::string method_name;
std::string_view method_name;
double duration;
std::optional<telemetry_metrics_info> metrics;
};

struct telemetry_error
{
std::string error_type;
std::string error_details;
std::string_view error_type;
std::string_view error_details;
};

using telemetry_message = std::variant<telemetry_info, telemetry_error>;
Expand Down
2 changes: 1 addition & 1 deletion parser_library/src/checking/checker_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ inline bool is_operand_empty(const asm_operand* to_check_operand)
return dynamic_cast<const empty_operand*>(to_check_operand) != nullptr;
}

inline bool has_one_comma(const std::vector<const asm_operand*> to_check)
inline bool has_one_comma(const std::vector<const asm_operand*>& to_check)
{
return to_check.size() == 2 && is_operand_empty(to_check[0]) && is_operand_empty(to_check[1]);
}
Expand Down
8 changes: 4 additions & 4 deletions parser_library/src/checking/instr_operand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ complex_operand::complex_operand() = default;

complex_operand::complex_operand(
std::string operand_identifier, std::vector<std::unique_ptr<asm_operand>> operand_params)
: operand_identifier(operand_identifier)
: operand_identifier(std::move(operand_identifier))
, operand_parameters(std::move(operand_params)) {};

machine_operand::machine_operand() = default;
Expand Down Expand Up @@ -227,13 +227,13 @@ one_operand::one_operand()
{}

one_operand::one_operand(std::string operand_identifier, int value)
: operand_identifier(operand_identifier)
: operand_identifier(std::move(operand_identifier))
, value(value)
, is_default(false)
{}

one_operand::one_operand(std::string operand_identifier)
: operand_identifier(operand_identifier)
: operand_identifier(std::move(operand_identifier))
, value(0)
, is_default(true)
{}
Expand All @@ -246,7 +246,7 @@ one_operand::one_operand(int value)

one_operand::one_operand(std::string operand_identifier, range range)
: operand(range)
, operand_identifier(operand_identifier)
, operand_identifier(std::move(operand_identifier))
, value(0)
, is_default(true)
{}
Expand Down
3 changes: 2 additions & 1 deletion parser_library/src/config/assembler_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "assembler_options.h"

#include <span>
#include <string_view>

#include "compiler_options.h"
#include "nlohmann/json.hpp"
Expand Down Expand Up @@ -215,7 +216,7 @@ bool assembler_options::has_value() const noexcept
}

template<typename T>
void optional_to_json(nlohmann::json& j, std::string name, const std::optional<T>& o)
void optional_to_json(nlohmann::json& j, std::string_view name, const std::optional<T>& o)
{
if (o.has_value())
j[name] = o.value();
Expand Down
2 changes: 1 addition & 1 deletion parser_library/src/context/instruction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ std::span<const assembler_instruction> instruction::all_assembler_instructions()
}

bool hlasm_plugin::parser_library::context::machine_instruction::check(std::string_view name_of_instruction,
const std::vector<const checking::machine_operand*> to_check,
const std::vector<const checking::machine_operand*>& to_check,
const range& stmt_range,
const diagnostic_collector& add_diagnostic) const
{
Expand Down
2 changes: 1 addition & 1 deletion parser_library/src/context/instruction.h
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ class machine_instruction
constexpr const instruction_set_affiliation& instr_set_affiliation() const { return m_instr_set_affiliation; };

bool check(std::string_view name_of_instruction,
const std::vector<const checking::machine_operand*> operands,
const std::vector<const checking::machine_operand*>& operands,
const range& stmt_range,
const diagnostic_collector& add_diagnostic) const; // input vector is the vector of the actual incoming values

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,14 @@ bool ordinary_assembly_context::create_symbol(
{
assert(symbol_can_be_assigned(symbols_, name));

const auto value_kind = value.value_kind();

symbols_.insert_or_assign(
name, symbol(name, value, attributes, std::move(symbol_location), hlasm_ctx_.processing_stack()));
name, symbol(name, std::move(value), attributes, std::move(symbol_location), hlasm_ctx_.processing_stack()));

bool ok = true;

if (value.value_kind() != symbol_value_kind::UNDEF)
if (value_kind != symbol_value_kind::UNDEF)
m_symbol_dependencies->add_defined(name, nullptr, li);

return ok;
Expand Down
2 changes: 1 addition & 1 deletion parser_library/src/diagnostic.h
Original file line number Diff line number Diff line change
Expand Up @@ -820,7 +820,7 @@ class diagnostic_s
: file_uri(std::move(file_uri))
, diag_range(range)
, severity(diagnostic_severity::unspecified)
, code(code)
, code(std::move(code))
, message(std::move(message))
{}
diagnostic_s(std::string file_uri,
Expand Down
6 changes: 3 additions & 3 deletions parser_library/src/lsp/document_symbol_item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@
namespace hlasm_plugin::parser_library::lsp {

document_symbol_item_s::document_symbol_item_s(std::string name, document_symbol_kind kind, range symbol_range)
: name(name)
: name(std::move(name))
, kind(kind)
, symbol_range(symbol_range)
, symbol_selection_range(symbol_range)
{}
document_symbol_item_s::document_symbol_item_s(
std::string name, document_symbol_kind kind, range symbol_range, document_symbol_list_s children)
: name(name)
: name(std::move(name))
, kind(kind)
, symbol_range(symbol_range)
, symbol_selection_range(symbol_range)
, children(children)
, children(std::move(children))
{}

bool is_similar(const document_symbol_list_s& l, const document_symbol_list_s& r)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,7 @@ void asm_processor::process_OPSYN(rebuilt_statement&& stmt)
lib_info);
}

asm_processor::asm_processor(analyzing_context ctx,
asm_processor::asm_processor(const analyzing_context& ctx,
branching_provider& branch_provider,
workspaces::parse_lib_provider& lib_provider,
statement_fields_parser& parser,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class asm_processor : public low_language_processor
const process_table_t table_;

public:
asm_processor(analyzing_context ctx,
asm_processor(const analyzing_context& ctx,
branching_provider& branch_provider,
workspaces::parse_lib_provider& lib_provider,
statement_fields_parser& parser,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ using namespace hlasm_plugin::parser_library;
using namespace processing;
using namespace workspaces;

ca_processor::ca_processor(analyzing_context ctx,
ca_processor::ca_processor(const analyzing_context& ctx,
branching_provider& branch_provider,
parse_lib_provider& lib_provider,
processing_state_listener& listener,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class ca_processor : public instruction_processor
processing_state_listener& listener_;

public:
ca_processor(analyzing_context ctx,
ca_processor(const analyzing_context& ctx,
branching_provider& branch_provider,
workspaces::parse_lib_provider& lib_provider,
processing_state_listener& listener,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class instruction_processor : public diagnosable_ctx
expressions::evaluation_context eval_ctx;

instruction_processor(
analyzing_context ctx, branching_provider& branch_provider, workspaces::parse_lib_provider& lib_provider)
const analyzing_context& ctx, branching_provider& branch_provider, workspaces::parse_lib_provider& lib_provider)
: diagnosable_ctx(*ctx.hlasm_ctx)
, ctx(ctx)
, hlasm_ctx(*ctx.hlasm_ctx)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ using namespace hlasm_plugin::parser_library;
using namespace processing;
using namespace workspaces;

low_language_processor::low_language_processor(analyzing_context ctx,
low_language_processor::low_language_processor(const analyzing_context& ctx,
branching_provider& branch_provider,
parse_lib_provider& lib_provider,
statement_fields_parser& parser,
const processing_manager& proc_mgr)
: instruction_processor(std::move(ctx), branch_provider, lib_provider)
: instruction_processor(ctx, branch_provider, lib_provider)
, parser(parser)
, proc_mgr(proc_mgr)
{}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class low_language_processor : public instruction_processor
statement_fields_parser& parser;
const processing_manager& proc_mgr;

low_language_processor(analyzing_context ctx,
low_language_processor(const analyzing_context& ctx,
branching_provider& branch_provider,
workspaces::parse_lib_provider& lib_provider,
statement_fields_parser& parser,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@

namespace hlasm_plugin::parser_library::processing {

mach_processor::mach_processor(analyzing_context ctx,
mach_processor::mach_processor(const analyzing_context& ctx,
branching_provider& branch_provider,
workspaces::parse_lib_provider& lib_provider,
statement_fields_parser& parser,
const processing_manager& proc_mgr)
: low_language_processor(std::move(ctx), branch_provider, lib_provider, parser, proc_mgr)
: low_language_processor(ctx, branch_provider, lib_provider, parser, proc_mgr)
{}

void mach_processor::process(std::shared_ptr<const processing::resolved_statement> stmt)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace hlasm_plugin::parser_library::processing {
class mach_processor : public low_language_processor
{
public:
mach_processor(analyzing_context ctx,
mach_processor(const analyzing_context& ctx,
branching_provider& branch_provider,
workspaces::parse_lib_provider& lib_provider,
statement_fields_parser& parser,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
namespace hlasm_plugin::parser_library::processing {

macro_processor::macro_processor(
analyzing_context ctx, branching_provider& branch_provider, workspaces::parse_lib_provider& lib_provider)
: instruction_processor(std::move(ctx), branch_provider, lib_provider)
const analyzing_context& ctx, branching_provider& branch_provider, workspaces::parse_lib_provider& lib_provider)
: instruction_processor(ctx, branch_provider, lib_provider)
{}

void macro_processor::process(std::shared_ptr<const processing::resolved_statement> stmt)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ struct macro_arguments
class macro_processor : public instruction_processor
{
public:
macro_processor(
analyzing_context ctx, branching_provider& branch_provider, workspaces::parse_lib_provider& lib_provider);
macro_processor(const analyzing_context& ctx,
branching_provider& branch_provider,
workspaces::parse_lib_provider& lib_provider);

void process(std::shared_ptr<const processing::resolved_statement> stmt) override;

Expand Down
Loading

0 comments on commit 7d929f5

Please sign in to comment.