Skip to content

Commit

Permalink
Add const lvalue ref to core/* container parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
Muller-Castro committed Feb 14, 2024
1 parent 907db8e commit a8bc9f3
Show file tree
Hide file tree
Showing 92 changed files with 346 additions and 346 deletions.
4 changes: 2 additions & 2 deletions core/config/project_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ Error ProjectSettings::setup(const String &p_path, const String &p_main_pack, bo
return err;
}

bool ProjectSettings::has_setting(String p_var) const {
bool ProjectSettings::has_setting(const String &p_var) const {
_THREAD_SAFE_METHOD_

return props.has(p_var);
Expand Down Expand Up @@ -971,7 +971,7 @@ Error ProjectSettings::_save_custom_bnd(const String &p_file) { // add other par
}

#ifdef TOOLS_ENABLED
bool _csproj_exists(String p_root_dir) {
bool _csproj_exists(const String &p_root_dir) {
Ref<DirAccess> dir = DirAccess::open(p_root_dir);
ERR_FAIL_COND_V(dir.is_null(), false);

Expand Down
2 changes: 1 addition & 1 deletion core/config/project_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ class ProjectSettings : public Object {
void store_global_class_list(const Array &p_classes);
String get_global_class_list_path() const;

bool has_setting(String p_var) const;
bool has_setting(const String &p_var) const;
String localize_path(const String &p_path) const;
String globalize_path(const String &p_path) const;

Expand Down
4 changes: 2 additions & 2 deletions core/core_bind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ String OS::get_executable_path() const {
return ::OS::get_singleton()->get_executable_path();
}

Error OS::shell_open(String p_uri) {
Error OS::shell_open(const String &p_uri) {
if (p_uri.begins_with("res://")) {
WARN_PRINT("Attempting to open an URL with the \"res://\" protocol. Use `ProjectSettings.globalize_path()` to convert a Godot-specific path to a system path before opening it with `OS.shell_open()`.");
} else if (p_uri.begins_with("user://")) {
Expand All @@ -266,7 +266,7 @@ Error OS::shell_open(String p_uri) {
return ::OS::get_singleton()->shell_open(p_uri);
}

Error OS::shell_show_in_file_manager(String p_path, bool p_open_folder) {
Error OS::shell_show_in_file_manager(const String &p_path, bool p_open_folder) {
if (p_path.begins_with("res://")) {
WARN_PRINT("Attempting to explore file path with the \"res://\" protocol. Use `ProjectSettings.globalize_path()` to convert a Godot-specific path to a system path before opening it with `OS.shell_show_in_file_manager()`.");
} else if (p_path.begins_with("user://")) {
Expand Down
4 changes: 2 additions & 2 deletions core/core_bind.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ class OS : public Object {
int create_process(const String &p_path, const Vector<String> &p_arguments, bool p_open_console = false);
int create_instance(const Vector<String> &p_arguments);
Error kill(int p_pid);
Error shell_open(String p_uri);
Error shell_show_in_file_manager(String p_path, bool p_open_folder = true);
Error shell_open(const String &p_uri);
Error shell_show_in_file_manager(const String &p_path, bool p_open_folder = true);

bool is_process_running(int p_pid) const;
int get_process_id() const;
Expand Down
4 changes: 2 additions & 2 deletions core/crypto/aes_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

#include "core/crypto/aes_context.h"

Error AESContext::start(Mode p_mode, PackedByteArray p_key, PackedByteArray p_iv) {
Error AESContext::start(Mode p_mode, const PackedByteArray &p_key, const PackedByteArray &p_iv) {
ERR_FAIL_COND_V_MSG(mode != MODE_MAX, ERR_ALREADY_IN_USE, "AESContext already started. Call 'finish' before starting a new one.");
ERR_FAIL_COND_V_MSG(p_mode < 0 || p_mode >= MODE_MAX, ERR_INVALID_PARAMETER, "Invalid mode requested.");
// Key check.
Expand All @@ -52,7 +52,7 @@ Error AESContext::start(Mode p_mode, PackedByteArray p_key, PackedByteArray p_iv
return OK;
}

PackedByteArray AESContext::update(PackedByteArray p_src) {
PackedByteArray AESContext::update(const PackedByteArray &p_src) {
ERR_FAIL_COND_V_MSG(mode < 0 || mode >= MODE_MAX, PackedByteArray(), "AESContext not started. Call 'start' before calling 'update'.");
int len = p_src.size();
ERR_FAIL_COND_V_MSG(len % 16, PackedByteArray(), "The number of bytes to be encrypted must be multiple of 16. Add padding if needed");
Expand Down
4 changes: 2 additions & 2 deletions core/crypto/aes_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ class AESContext : public RefCounted {
static void _bind_methods();

public:
Error start(Mode p_mode, PackedByteArray p_key, PackedByteArray p_iv = PackedByteArray());
PackedByteArray update(PackedByteArray p_src);
Error start(Mode p_mode, const PackedByteArray &p_key, const PackedByteArray &p_iv = PackedByteArray());
PackedByteArray update(const PackedByteArray &p_src);
PackedByteArray get_iv_state();
void finish();

Expand Down
8 changes: 4 additions & 4 deletions core/crypto/crypto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ HMACContext *HMACContext::create() {

/// Crypto

void (*Crypto::_load_default_certificates)(String p_path) = nullptr;
void (*Crypto::_load_default_certificates)(const String &p_path) = nullptr;
Crypto *(*Crypto::_create)() = nullptr;
Crypto *Crypto::create() {
if (_create) {
Expand All @@ -133,13 +133,13 @@ Crypto *Crypto::create() {
ERR_FAIL_V_MSG(nullptr, "Crypto is not available when the mbedtls module is disabled.");
}

void Crypto::load_default_certificates(String p_path) {
void Crypto::load_default_certificates(const String &p_path) {
if (_load_default_certificates) {
_load_default_certificates(p_path);
}
}

PackedByteArray Crypto::hmac_digest(HashingContext::HashType p_hash_type, PackedByteArray p_key, PackedByteArray p_msg) {
PackedByteArray Crypto::hmac_digest(HashingContext::HashType p_hash_type, const PackedByteArray &p_key, const PackedByteArray &p_msg) {
Ref<HMACContext> ctx = Ref<HMACContext>(HMACContext::create());
ERR_FAIL_COND_V_MSG(ctx.is_null(), PackedByteArray(), "HMAC is not available without mbedtls module.");
Error err = ctx->start(p_hash_type, p_key);
Expand All @@ -151,7 +151,7 @@ PackedByteArray Crypto::hmac_digest(HashingContext::HashType p_hash_type, Packed

// Compares two HMACS for equality without leaking timing information in order to prevent timing attacks.
// @see: https://paragonie.com/blog/2015/11/preventing-timing-attacks-on-string-comparison-with-double-hmac-strategy
bool Crypto::constant_time_compare(PackedByteArray p_trusted, PackedByteArray p_received) {
bool Crypto::constant_time_compare(const PackedByteArray &p_trusted, const PackedByteArray &p_received) {
const uint8_t *t = p_trusted.ptr();
const uint8_t *r = p_received.ptr();
int tlen = p_trusted.size();
Expand Down
32 changes: 16 additions & 16 deletions core/crypto/crypto.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ class CryptoKey : public Resource {

public:
static CryptoKey *create();
virtual Error load(String p_path, bool p_public_only = false) = 0;
virtual Error save(String p_path, bool p_public_only = false) = 0;
virtual Error load(const String &p_path, bool p_public_only = false) = 0;
virtual Error save(const String &p_path, bool p_public_only = false) = 0;
virtual String save_to_string(bool p_public_only = false) = 0;
virtual Error load_from_string(String p_string_key, bool p_public_only = false) = 0;
virtual Error load_from_string(const String &p_string_key, bool p_public_only = false) = 0;
virtual bool is_public_only() const = 0;
};

Expand All @@ -62,9 +62,9 @@ class X509Certificate : public Resource {

public:
static X509Certificate *create();
virtual Error load(String p_path) = 0;
virtual Error load(const String &p_path) = 0;
virtual Error load_from_memory(const uint8_t *p_buffer, int p_len) = 0;
virtual Error save(String p_path) = 0;
virtual Error save(const String &p_path) = 0;
virtual String save_to_string() = 0;
virtual Error load_from_string(const String &string) = 0;
};
Expand Down Expand Up @@ -113,8 +113,8 @@ class HMACContext : public RefCounted {
public:
static HMACContext *create();

virtual Error start(HashingContext::HashType p_hash_type, PackedByteArray p_key) = 0;
virtual Error update(PackedByteArray p_data) = 0;
virtual Error start(HashingContext::HashType p_hash_type, const PackedByteArray &p_key) = 0;
virtual Error update(const PackedByteArray &p_data) = 0;
virtual PackedByteArray finish() = 0;

HMACContext() {}
Expand All @@ -127,26 +127,26 @@ class Crypto : public RefCounted {
protected:
static void _bind_methods();
static Crypto *(*_create)();
static void (*_load_default_certificates)(String p_path);
static void (*_load_default_certificates)(const String &p_path);

public:
static Crypto *create();
static void load_default_certificates(String p_path);
static void load_default_certificates(const String &p_path);

virtual PackedByteArray generate_random_bytes(int p_bytes) = 0;
virtual Ref<CryptoKey> generate_rsa(int p_bytes) = 0;
virtual Ref<X509Certificate> generate_self_signed_certificate(Ref<CryptoKey> p_key, String p_issuer_name, String p_not_before, String p_not_after) = 0;
virtual Ref<X509Certificate> generate_self_signed_certificate(Ref<CryptoKey> p_key, const String &p_issuer_name, const String &p_not_before, const String &p_not_after) = 0;

virtual Vector<uint8_t> sign(HashingContext::HashType p_hash_type, Vector<uint8_t> p_hash, Ref<CryptoKey> p_key) = 0;
virtual bool verify(HashingContext::HashType p_hash_type, Vector<uint8_t> p_hash, Vector<uint8_t> p_signature, Ref<CryptoKey> p_key) = 0;
virtual Vector<uint8_t> encrypt(Ref<CryptoKey> p_key, Vector<uint8_t> p_plaintext) = 0;
virtual Vector<uint8_t> decrypt(Ref<CryptoKey> p_key, Vector<uint8_t> p_ciphertext) = 0;
virtual Vector<uint8_t> sign(HashingContext::HashType p_hash_type, const Vector<uint8_t> &p_hash, Ref<CryptoKey> p_key) = 0;
virtual bool verify(HashingContext::HashType p_hash_type, const Vector<uint8_t> &p_hash, const Vector<uint8_t> &p_signature, Ref<CryptoKey> p_key) = 0;
virtual Vector<uint8_t> encrypt(Ref<CryptoKey> p_key, const Vector<uint8_t> &p_plaintext) = 0;
virtual Vector<uint8_t> decrypt(Ref<CryptoKey> p_key, const Vector<uint8_t> &p_ciphertext) = 0;

PackedByteArray hmac_digest(HashingContext::HashType p_hash_type, PackedByteArray p_key, PackedByteArray p_msg);
PackedByteArray hmac_digest(HashingContext::HashType p_hash_type, const PackedByteArray &p_key, const PackedByteArray &p_msg);

// Compares two PackedByteArrays for equality without leaking timing information in order to prevent timing attacks.
// @see: https://paragonie.com/blog/2015/11/preventing-timing-attacks-on-string-comparison-with-double-hmac-strategy
bool constant_time_compare(PackedByteArray p_trusted, PackedByteArray p_received);
bool constant_time_compare(const PackedByteArray &p_trusted, const PackedByteArray &p_received);

Crypto() {}
};
Expand Down
2 changes: 1 addition & 1 deletion core/crypto/hashing_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Error HashingContext::start(HashType p_type) {
return ERR_UNAVAILABLE;
}

Error HashingContext::update(PackedByteArray p_chunk) {
Error HashingContext::update(const PackedByteArray &p_chunk) {
ERR_FAIL_NULL_V(ctx, ERR_UNCONFIGURED);
size_t len = p_chunk.size();
ERR_FAIL_COND_V(len == 0, FAILED);
Expand Down
2 changes: 1 addition & 1 deletion core/crypto/hashing_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class HashingContext : public RefCounted {

public:
Error start(HashType p_type);
Error update(PackedByteArray p_chunk);
Error update(const PackedByteArray &p_chunk);
PackedByteArray finish();

HashingContext() {}
Expand Down
2 changes: 1 addition & 1 deletion core/debugger/engine_debugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ void EngineDebugger::iteration(uint64_t p_frame_ticks, uint64_t p_process_ticks,
singleton->poll_events(true);
}

void EngineDebugger::initialize(const String &p_uri, bool p_skip_breakpoints, Vector<String> p_breakpoints, void (*p_allow_focus_steal_fn)()) {
void EngineDebugger::initialize(const String &p_uri, bool p_skip_breakpoints, const Vector<String> &p_breakpoints, void (*p_allow_focus_steal_fn)()) {
register_uri_handler("tcp://", RemoteDebuggerPeerTCP::create); // TCP is the default protocol. Platforms/modules can add more.
if (p_uri.is_empty()) {
return;
Expand Down
2 changes: 1 addition & 1 deletion core/debugger/engine_debugger.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class EngineDebugger {

_FORCE_INLINE_ static ScriptDebugger *get_script_debugger() { return script_debugger; };

static void initialize(const String &p_uri, bool p_skip_breakpoints, Vector<String> p_breakpoints, void (*p_allow_focus_steal_fn)());
static void initialize(const String &p_uri, bool p_skip_breakpoints, const Vector<String> &p_breakpoints, void (*p_allow_focus_steal_fn)());
static void deinitialize();
static void register_profiler(const StringName &p_name, const Profiler &p_profiler);
static void unregister_profiler(const StringName &p_name);
Expand Down
2 changes: 1 addition & 1 deletion core/debugger/remote_debugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class RemoteDebugger::PerformanceProfiler : public EngineProfiler {
}
};

Error RemoteDebugger::_put_msg(String p_message, Array p_data) {
Error RemoteDebugger::_put_msg(const String &p_message, const Array &p_data) {
Array msg;
msg.push_back(p_message);
msg.push_back(Thread::get_caller_id());
Expand Down
2 changes: 1 addition & 1 deletion core/debugger/remote_debugger.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class RemoteDebugger : public EngineDebugger {
static void _err_handler(void *p_this, const char *p_func, const char *p_file, int p_line, const char *p_err, const char *p_descr, bool p_editor_notify, ErrorHandlerType p_type);

ErrorMessage _create_overflow_error(const String &p_what, const String &p_descr);
Error _put_msg(String p_message, Array p_data);
Error _put_msg(const String &p_message, const Array &p_data);

bool is_peer_connected() { return peer->is_peer_connected(); }
void flush_output();
Expand Down
2 changes: 1 addition & 1 deletion core/extension/gdextension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -914,7 +914,7 @@ Error GDExtensionResourceLoader::load_gdextension_resource(const String &p_path,
return ERR_INVALID_DATA;
}

String library_path = GDExtension::find_extension_library(p_path, config, [](String p_feature) { return OS::get_singleton()->has_feature(p_feature); });
String library_path = GDExtension::find_extension_library(p_path, config, [](const String &p_feature) { return OS::get_singleton()->has_feature(p_feature); });

if (library_path.is_empty()) {
const String os_arch = OS::get_singleton()->get_name().to_lower() + "." + Engine::get_singleton()->get_architecture_name();
Expand Down
14 changes: 7 additions & 7 deletions core/input/input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ static String _hex_str(uint8_t p_byte) {
return ret;
}

void Input::joy_connection_changed(int p_idx, bool p_connected, String p_name, String p_guid, Dictionary p_joypad_info) {
void Input::joy_connection_changed(int p_idx, bool p_connected, const String &p_name, const String &p_guid, const Dictionary &p_joypad_info) {
_THREAD_SAFE_METHOD_

// Clear the pressed status if a Joypad gets disconnected.
Expand Down Expand Up @@ -1414,7 +1414,7 @@ void Input::_get_mapped_hat_events(const JoyDeviceMapping &mapping, HatDir p_hat
}
}

JoyButton Input::_get_output_button(String output) {
JoyButton Input::_get_output_button(const String &output) {
for (int i = 0; i < (int)JoyButton::SDL_MAX; i++) {
if (output == _joy_buttons[i]) {
return JoyButton(i);
Expand All @@ -1423,7 +1423,7 @@ JoyButton Input::_get_output_button(String output) {
return JoyButton::INVALID;
}

JoyAxis Input::_get_output_axis(String output) {
JoyAxis Input::_get_output_axis(const String &output) {
for (int i = 0; i < (int)JoyAxis::SDL_MAX; i++) {
if (output == _joy_axes[i]) {
return JoyAxis(i);
Expand All @@ -1432,7 +1432,7 @@ JoyAxis Input::_get_output_axis(String output) {
return JoyAxis::INVALID;
}

void Input::parse_mapping(String p_mapping) {
void Input::parse_mapping(const String &p_mapping) {
_THREAD_SAFE_METHOD_;
JoyDeviceMapping mapping;

Expand Down Expand Up @@ -1535,7 +1535,7 @@ void Input::parse_mapping(String p_mapping) {
map_db.push_back(mapping);
}

void Input::add_joy_mapping(String p_mapping, bool p_update_existing) {
void Input::add_joy_mapping(const String &p_mapping, bool p_update_existing) {
parse_mapping(p_mapping);
if (p_update_existing) {
Vector<String> entry = p_mapping.split(",");
Expand All @@ -1549,7 +1549,7 @@ void Input::add_joy_mapping(String p_mapping, bool p_update_existing) {
}
}

void Input::remove_joy_mapping(String p_guid) {
void Input::remove_joy_mapping(const String &p_guid) {
for (int i = map_db.size() - 1; i >= 0; i--) {
if (p_guid == map_db[i].uid) {
map_db.remove_at(i);
Expand All @@ -1563,7 +1563,7 @@ void Input::remove_joy_mapping(String p_guid) {
}
}

void Input::set_fallback_mapping(String p_guid) {
void Input::set_fallback_mapping(const String &p_guid) {
for (int i = 0; i < map_db.size(); i++) {
if (map_db[i].uid == p_guid) {
fallback_mapping = i;
Expand Down
14 changes: 7 additions & 7 deletions core/input/input.h
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,8 @@ class Input : public Object {
JoyEvent _get_mapped_button_event(const JoyDeviceMapping &mapping, JoyButton p_button);
JoyEvent _get_mapped_axis_event(const JoyDeviceMapping &mapping, JoyAxis p_axis, float p_value, JoyAxisRange &r_range);
void _get_mapped_hat_events(const JoyDeviceMapping &mapping, HatDir p_hat, JoyEvent r_events[(size_t)HatDir::MAX]);
JoyButton _get_output_button(String output);
JoyAxis _get_output_axis(String output);
JoyButton _get_output_button(const String &output);
JoyAxis _get_output_axis(const String &output);
void _button_event(int p_device, JoyButton p_index, bool p_pressed);
void _axis_event(int p_device, JoyAxis p_axis, float p_value);
void _update_action_cache(const StringName &p_action_name, ActionState &r_action_state);
Expand Down Expand Up @@ -295,7 +295,7 @@ class Input : public Object {
Vector2 get_joy_vibration_strength(int p_device);
float get_joy_vibration_duration(int p_device);
uint64_t get_joy_vibration_timestamp(int p_device);
void joy_connection_changed(int p_idx, bool p_connected, String p_name, String p_guid = "", Dictionary p_joypad_info = Dictionary());
void joy_connection_changed(int p_idx, bool p_connected, const String &p_name, const String &p_guid = "", const Dictionary &p_joypad_info = Dictionary());

Vector3 get_gravity() const;
Vector3 get_accelerometer() const;
Expand Down Expand Up @@ -339,21 +339,21 @@ class Input : public Object {
CursorShape get_current_cursor_shape() const;
void set_custom_mouse_cursor(const Ref<Resource> &p_cursor, CursorShape p_shape = Input::CURSOR_ARROW, const Vector2 &p_hotspot = Vector2());

void parse_mapping(String p_mapping);
void parse_mapping(const String &p_mapping);
void joy_button(int p_device, JoyButton p_button, bool p_pressed);
void joy_axis(int p_device, JoyAxis p_axis, float p_value);
void joy_hat(int p_device, BitField<HatMask> p_val);

void add_joy_mapping(String p_mapping, bool p_update_existing = false);
void remove_joy_mapping(String p_guid);
void add_joy_mapping(const String &p_mapping, bool p_update_existing = false);
void remove_joy_mapping(const String &p_guid);

int get_unused_joy_id();

bool is_joy_known(int p_device);
String get_joy_guid(int p_device) const;
bool should_ignore_device(int p_vendor_id, int p_product_id) const;
Dictionary get_joy_info(int p_device) const;
void set_fallback_mapping(String p_guid);
void set_fallback_mapping(const String &p_guid);

void flush_buffered_events();
bool is_using_input_buffering();
Expand Down
2 changes: 1 addition & 1 deletion core/io/config_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ void ConfigFile::set_value(const String &p_section, const String &p_key, const V
}
}

Variant ConfigFile::get_value(const String &p_section, const String &p_key, Variant p_default) const {
Variant ConfigFile::get_value(const String &p_section, const String &p_key, const Variant &p_default) const {
if (!values.has(p_section) || !values[p_section].has(p_key)) {
ERR_FAIL_COND_V_MSG(p_default.get_type() == Variant::NIL, Variant(),
vformat("Couldn't find the given section \"%s\" and key \"%s\", and no default was given.", p_section, p_key));
Expand Down
2 changes: 1 addition & 1 deletion core/io/config_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class ConfigFile : public RefCounted {

public:
void set_value(const String &p_section, const String &p_key, const Variant &p_value);
Variant get_value(const String &p_section, const String &p_key, Variant p_default = Variant()) const;
Variant get_value(const String &p_section, const String &p_key, const Variant &p_default = Variant()) const;

bool has_section(const String &p_section) const;
bool has_section_key(const String &p_section, const String &p_key) const;
Expand Down
Loading

0 comments on commit a8bc9f3

Please sign in to comment.