From bb8aa107fd064a095479350bd22b1ce3ed146784 Mon Sep 17 00:00:00 2001 From: Aaron Franke Date: Wed, 13 May 2020 05:31:51 -0400 Subject: [PATCH] Remove 32-bit String to_int method --- core/math/expression.cpp | 2 +- core/ustring.cpp | 29 ++----------------------- core/ustring.h | 3 +-- core/variant.cpp | 2 +- drivers/unix/net_socket_posix.cpp | 2 +- editor/editor_file_system.cpp | 6 ++--- editor/editor_properties.cpp | 10 ++++----- editor/editor_resource_preview.cpp | 6 ++--- editor/property_editor.cpp | 8 +++---- main/main.cpp | 2 +- main/tests/test_string.cpp | 2 +- modules/gdnative/gdnative/string.cpp | 2 +- modules/gdscript/gdscript_tokenizer.cpp | 2 +- 13 files changed, 25 insertions(+), 51 deletions(-) diff --git a/core/math/expression.cpp b/core/math/expression.cpp index db3bf2f830..e13ed75b8a 100644 --- a/core/math/expression.cpp +++ b/core/math/expression.cpp @@ -1062,7 +1062,7 @@ Error Expression::_get_token(Token &r_token) { if (is_float) { r_token.value = num.to_double(); } else { - r_token.value = num.to_int64(); + r_token.value = num.to_int(); } return OK; diff --git a/core/ustring.cpp b/core/ustring.cpp index cfb547742a..986bf089c8 100644 --- a/core/ustring.cpp +++ b/core/ustring.cpp @@ -1742,32 +1742,7 @@ int64_t String::bin_to_int64(bool p_with_prefix) const { return binary * sign; } -int String::to_int() const { - if (length() == 0) { - return 0; - } - - int to = (find(".") >= 0) ? find(".") : length(); - - int integer = 0; - int sign = 1; - - for (int i = 0; i < to; i++) { - CharType c = operator[](i); - if (c >= '0' && c <= '9') { - ERR_FAIL_COND_V_MSG(integer > INT32_MAX / 10, sign == 1 ? INT32_MAX : INT32_MIN, "Cannot represent " + *this + " as integer, provided value is " + (sign == 1 ? "too big." : "too small.")); - integer *= 10; - integer += c - '0'; - - } else if (integer == 0 && c == '-') { - sign = -sign; - } - } - - return integer * sign; -} - -int64_t String::to_int64() const { +int64_t String::to_int() const { if (length() == 0) { return 0; } @@ -1780,7 +1755,7 @@ int64_t String::to_int64() const { for (int i = 0; i < to; i++) { CharType c = operator[](i); if (c >= '0' && c <= '9') { - ERR_FAIL_COND_V_MSG(integer > INT64_MAX / 10, sign == 1 ? INT64_MAX : INT64_MIN, "Cannot represent " + *this + " as 64-bit integer, provided value is " + (sign == 1 ? "too big." : "too small.")); + ERR_FAIL_COND_V_MSG(integer > INT64_MAX / 10, sign == 1 ? INT64_MAX : INT64_MIN, "Cannot represent " + *this + " as an integer, provided value is " + (sign == 1 ? "too big." : "too small.")); integer *= 10; integer += c - '0'; diff --git a/core/ustring.h b/core/ustring.h index 5b13a1c704..f82e31f995 100644 --- a/core/ustring.h +++ b/core/ustring.h @@ -246,11 +246,10 @@ public: double to_double() const; float to_float() const; int hex_to_int(bool p_with_prefix = true) const; - int to_int() const; int64_t hex_to_int64(bool p_with_prefix = true) const; int64_t bin_to_int64(bool p_with_prefix = true) const; - int64_t to_int64() const; + int64_t to_int() const; static int to_int(const char *p_str, int p_len = -1); static double to_double(const char *p_str); static double to_double(const CharType *p_str, const CharType **r_end = nullptr); diff --git a/core/variant.cpp b/core/variant.cpp index 21aaa0fe9e..f6b7e2821a 100644 --- a/core/variant.cpp +++ b/core/variant.cpp @@ -1409,7 +1409,7 @@ Variant::operator int64_t() const { case FLOAT: return _data._float; case STRING: - return operator String().to_int64(); + return operator String().to_int(); default: { return 0; } diff --git a/drivers/unix/net_socket_posix.cpp b/drivers/unix/net_socket_posix.cpp index 15ad187ab4..186804dbb1 100644 --- a/drivers/unix/net_socket_posix.cpp +++ b/drivers/unix/net_socket_posix.cpp @@ -245,7 +245,7 @@ _FORCE_INLINE_ Error NetSocketPosix::_change_multicast_group(IP_Address p_ip, St continue; } - if_v6id = (uint32_t)c.index.to_int64(); + if_v6id = (uint32_t)c.index.to_int(); if (type == IP::TYPE_IPV6) { break; // IPv6 uses index. } diff --git a/editor/editor_file_system.cpp b/editor/editor_file_system.cpp index d88c61d7b2..9ca3d387d9 100644 --- a/editor/editor_file_system.cpp +++ b/editor/editor_file_system.cpp @@ -233,9 +233,9 @@ void EditorFileSystem::_scan_filesystem() { FileCache fc; fc.type = split[1]; - fc.modification_time = split[2].to_int64(); - fc.import_modification_time = split[3].to_int64(); - fc.import_valid = split[4].to_int64() != 0; + fc.modification_time = split[2].to_int(); + fc.import_modification_time = split[3].to_int(); + fc.import_valid = split[4].to_int() != 0; fc.import_group_file = split[5].strip_edges(); fc.script_class_name = split[6].get_slice("<>", 0); fc.script_class_extends = split[6].get_slice("<>", 1); diff --git a/editor/editor_properties.cpp b/editor/editor_properties.cpp index 81c4e48974..0e71d412ee 100644 --- a/editor/editor_properties.cpp +++ b/editor/editor_properties.cpp @@ -376,13 +376,13 @@ void EditorPropertyMember::_property_select() { selector->select_method_from_base_type(hint_text, current); } else if (hint == MEMBER_METHOD_OF_INSTANCE) { - Object *instance = ObjectDB::get_instance(ObjectID(hint_text.to_int64())); + Object *instance = ObjectDB::get_instance(ObjectID(hint_text.to_int())); if (instance) { selector->select_method_from_instance(instance, current); } } else if (hint == MEMBER_METHOD_OF_SCRIPT) { - Object *obj = ObjectDB::get_instance(ObjectID(hint_text.to_int64())); + Object *obj = ObjectDB::get_instance(ObjectID(hint_text.to_int())); if (Object::cast_to