summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/extension/gdnative_interface.cpp24
-rw-r--r--core/input/input.cpp44
-rw-r--r--core/input/input.h8
-rw-r--r--core/input/input_event.cpp16
-rw-r--r--core/input/input_event.h2
-rw-r--r--core/math/geometry_2d.h3
-rw-r--r--core/os/memory.h14
-rw-r--r--core/string/ustring.cpp95
-rw-r--r--core/templates/cowdata.h8
9 files changed, 122 insertions, 92 deletions
diff --git a/core/extension/gdnative_interface.cpp b/core/extension/gdnative_interface.cpp
index a444b2e18e..e0ebd19376 100644
--- a/core/extension/gdnative_interface.cpp
+++ b/core/extension/gdnative_interface.cpp
@@ -74,8 +74,6 @@ static void gdnative_variant_destroy(GDNativeVariantPtr p_self) {
// variant type
-#define memnew_placement_custom(m_placement, m_class, m_constr) _post_initialize(new (m_placement, sizeof(m_class), "") m_constr)
-
static void gdnative_variant_call(GDNativeVariantPtr p_self, const GDNativeStringNamePtr p_method, const GDNativeVariantPtr *p_args, const GDNativeInt p_argcount, GDNativeVariantPtr r_return, GDNativeCallError *r_error) {
Variant *self = (Variant *)p_self;
const StringName *method = (const StringName *)p_method;
@@ -83,7 +81,7 @@ static void gdnative_variant_call(GDNativeVariantPtr p_self, const GDNativeStrin
Variant ret;
Callable::CallError error;
self->call(*method, args, p_argcount, ret, error);
- memnew_placement_custom(r_return, Variant, Variant(ret));
+ memnew_placement(r_return, Variant(ret));
if (r_error) {
r_error->error = (GDNativeCallErrorType)(error.error);
@@ -99,7 +97,7 @@ static void gdnative_variant_call_static(GDNativeVariantType p_type, const GDNat
Variant ret;
Callable::CallError error;
Variant::call_static(type, *method, args, p_argcount, ret, error);
- memnew_placement_custom(r_return, Variant, Variant(ret));
+ memnew_placement(r_return, Variant(ret));
if (r_error) {
r_error->error = (GDNativeCallErrorType)error.error;
@@ -164,7 +162,7 @@ static void gdnative_variant_get(const GDNativeVariantPtr p_self, const GDNative
const Variant *key = (const Variant *)p_key;
bool valid;
- memnew_placement_custom(r_ret, Variant, Variant(self->get(*key, &valid)));
+ memnew_placement(r_ret, Variant(self->get(*key, &valid)));
*r_valid = valid;
}
@@ -173,7 +171,7 @@ static void gdnative_variant_get_named(const GDNativeVariantPtr p_self, const GD
const StringName *key = (const StringName *)p_key;
bool valid;
- memnew_placement_custom(r_ret, Variant, Variant(self->get_named(*key, valid)));
+ memnew_placement(r_ret, Variant(self->get_named(*key, valid)));
*r_valid = valid;
}
@@ -182,7 +180,7 @@ static void gdnative_variant_get_keyed(const GDNativeVariantPtr p_self, const GD
const Variant *key = (const Variant *)p_key;
bool valid;
- memnew_placement_custom(r_ret, Variant, Variant(self->get_keyed(*key, valid)));
+ memnew_placement(r_ret, Variant(self->get_keyed(*key, valid)));
*r_valid = valid;
}
@@ -191,7 +189,7 @@ static void gdnative_variant_get_indexed(const GDNativeVariantPtr p_self, GDNati
bool valid;
bool oob;
- memnew_placement_custom(r_ret, Variant, Variant(self->get_indexed(p_index, valid, oob)));
+ memnew_placement(r_ret, Variant(self->get_indexed(p_index, valid, oob)));
*r_valid = valid;
*r_oob = oob;
}
@@ -222,7 +220,7 @@ static void gdnative_variant_iter_get(const GDNativeVariantPtr p_self, GDNativeV
Variant *iter = (Variant *)r_iter;
bool valid;
- memnew_placement_custom(r_ret, Variant, Variant(self->iter_next(*iter, valid)));
+ memnew_placement(r_ret, Variant(self->iter_next(*iter, valid)));
*r_valid = valid;
}
@@ -254,12 +252,12 @@ static void gdnative_variant_interpolate(const GDNativeVariantPtr p_a, const GDN
static void gdnative_variant_duplicate(const GDNativeVariantPtr p_self, GDNativeVariantPtr r_ret, GDNativeBool p_deep) {
const Variant *self = (const Variant *)p_self;
- memnew_placement_custom(r_ret, Variant, Variant(self->duplicate(p_deep)));
+ memnew_placement(r_ret, Variant(self->duplicate(p_deep)));
}
static void gdnative_variant_stringify(const GDNativeVariantPtr p_self, GDNativeStringPtr r_ret) {
const Variant *self = (const Variant *)p_self;
- memnew_placement_custom(r_ret, String, String(*self));
+ memnew_placement(r_ret, String(*self));
}
static GDNativeVariantType gdnative_variant_get_type(const GDNativeVariantPtr p_self) {
@@ -288,7 +286,7 @@ static GDNativeBool gdnative_variant_has_key(const GDNativeVariantPtr p_self, co
static void gdnative_variant_get_type_name(GDNativeVariantType p_type, GDNativeStringPtr r_ret) {
String name = Variant::get_type_name((Variant::Type)p_type);
- memnew_placement_custom(r_ret, String, String(name));
+ memnew_placement(r_ret, String(name));
}
static GDNativeBool gdnative_variant_can_convert(GDNativeVariantType p_from, GDNativeVariantType p_to) {
@@ -508,7 +506,7 @@ static GDNativePtrKeyedChecker gdnative_variant_get_ptr_keyed_checker(GDNativeVa
return (GDNativePtrKeyedChecker)Variant::get_member_ptr_keyed_checker(Variant::Type(p_type));
}
static void gdnative_variant_get_constant_value(GDNativeVariantType p_type, const char *p_constant, GDNativeVariantPtr r_ret) {
- memnew_placement_custom(r_ret, Variant, Variant(Variant::get_constant_value(Variant::Type(p_type), p_constant)));
+ memnew_placement(r_ret, Variant(Variant::get_constant_value(Variant::Type(p_type), p_constant)));
}
static GDNativePtrUtilityFunction gdnative_variant_get_ptr_utility_function(const char *p_function, GDNativeInt p_hash) {
StringName function = p_function;
diff --git a/core/input/input.cpp b/core/input/input.cpp
index 2da50b7dff..8ba8b892ac 100644
--- a/core/input/input.cpp
+++ b/core/input/input.cpp
@@ -460,10 +460,6 @@ Vector3 Input::get_gyroscope() const {
return gyroscope;
}
-void Input::parse_input_event(const Ref<InputEvent> &p_event) {
- _parse_input_event_impl(p_event, false);
-}
-
void Input::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_emulated) {
// Notes on mouse-touch emulation:
// - Emulated mouse events are parsed, that is, re-routed to this method, so they make the same effects
@@ -472,8 +468,6 @@ void Input::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_em
// - Emulated touch events are handed right to the main loop (i.e., the SceneTree) because they don't
// require additional handling by this class.
- _THREAD_SAFE_METHOD_
-
Ref<InputEventKey> k = p_event;
if (k.is_valid() && !k->is_echo() && k->get_keycode() != 0) {
if (k->is_pressed()) {
@@ -838,25 +832,37 @@ void Input::set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shape, co
set_custom_mouse_cursor_func(p_cursor, p_shape, p_hotspot);
}
-void Input::accumulate_input_event(const Ref<InputEvent> &p_event) {
+void Input::parse_input_event(const Ref<InputEvent> &p_event) {
+ _THREAD_SAFE_METHOD_
+
ERR_FAIL_COND(p_event.is_null());
- if (!use_accumulated_input) {
- parse_input_event(p_event);
- return;
+ if (use_accumulated_input) {
+ if (buffered_events.is_empty() || !buffered_events.back()->get()->accumulate(p_event)) {
+ buffered_events.push_back(p_event);
+ }
+ } else if (use_input_buffering) {
+ buffered_events.push_back(p_event);
+ } else {
+ _parse_input_event_impl(p_event, false);
}
- if (!accumulated_events.is_empty() && accumulated_events.back()->get()->accumulate(p_event)) {
- return; //event was accumulated, exit
+}
+
+void Input::flush_buffered_events() {
+ _THREAD_SAFE_METHOD_
+
+ while (buffered_events.front()) {
+ _parse_input_event_impl(buffered_events.front()->get(), false);
+ buffered_events.pop_front();
}
+}
- accumulated_events.push_back(p_event);
+bool Input::is_using_input_buffering() {
+ return use_input_buffering;
}
-void Input::flush_accumulated_events() {
- while (accumulated_events.front()) {
- parse_input_event(accumulated_events.front()->get());
- accumulated_events.pop_front();
- }
+void Input::set_use_input_buffering(bool p_enable) {
+ use_input_buffering = p_enable;
}
void Input::set_use_accumulated_input(bool p_enable) {
@@ -864,7 +870,7 @@ void Input::set_use_accumulated_input(bool p_enable) {
}
void Input::release_pressed_events() {
- flush_accumulated_events(); // this is needed to release actions strengths
+ flush_buffered_events(); // this is needed to release actions strengths
keys_pressed.clear();
joy_buttons_pressed.clear();
diff --git a/core/input/input.h b/core/input/input.h
index ee991aa725..6819fc8eb0 100644
--- a/core/input/input.h
+++ b/core/input/input.h
@@ -111,6 +111,7 @@ private:
bool emulate_touch_from_mouse = false;
bool emulate_mouse_from_touch = false;
+ bool use_input_buffering = false;
bool use_accumulated_input = false;
int mouse_from_touch_index = -1;
@@ -213,7 +214,7 @@ private:
void _parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_emulated);
- List<Ref<InputEvent>> accumulated_events;
+ List<Ref<InputEvent>> buffered_events;
friend class DisplayServer;
@@ -323,8 +324,9 @@ public:
String get_joy_guid(int p_device) const;
void set_fallback_mapping(String p_guid);
- void accumulate_input_event(const Ref<InputEvent> &p_event);
- void flush_accumulated_events();
+ void flush_buffered_events();
+ bool is_using_input_buffering();
+ void set_use_input_buffering(bool p_enable);
void set_use_accumulated_input(bool p_enable);
void release_pressed_events();
diff --git a/core/input/input_event.cpp b/core/input/input_event.cpp
index 6e5c1a58ae..16bb92d94b 100644
--- a/core/input/input_event.cpp
+++ b/core/input/input_event.cpp
@@ -1210,6 +1210,22 @@ String InputEventScreenDrag::to_string() {
return vformat("InputEventScreenDrag: index=%d, position=(%s), relative=(%s), speed=(%s)", index, String(get_position()), String(get_relative()), String(get_speed()));
}
+bool InputEventScreenDrag::accumulate(const Ref<InputEvent> &p_event) {
+ Ref<InputEventScreenDrag> drag = p_event;
+ if (drag.is_null())
+ return false;
+
+ if (get_index() != drag->get_index()) {
+ return false;
+ }
+
+ set_position(drag->get_position());
+ set_speed(drag->get_speed());
+ relative += drag->get_relative();
+
+ return true;
+}
+
void InputEventScreenDrag::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_index", "index"), &InputEventScreenDrag::set_index);
ClassDB::bind_method(D_METHOD("get_index"), &InputEventScreenDrag::get_index);
diff --git a/core/input/input_event.h b/core/input/input_event.h
index 57b6091123..517d63eb40 100644
--- a/core/input/input_event.h
+++ b/core/input/input_event.h
@@ -410,6 +410,8 @@ public:
virtual String as_text() const override;
virtual String to_string() override;
+ virtual bool accumulate(const Ref<InputEvent> &p_event) override;
+
InputEventScreenDrag() {}
};
diff --git a/core/math/geometry_2d.h b/core/math/geometry_2d.h
index a2894bc1d3..e1a5bfe6f2 100644
--- a/core/math/geometry_2d.h
+++ b/core/math/geometry_2d.h
@@ -32,9 +32,8 @@
#define GEOMETRY_2D_H
#include "core/math/delaunay_2d.h"
-#include "core/math/rect2.h"
#include "core/math/triangulate.h"
-#include "core/object/object.h"
+#include "core/math/vector3i.h"
#include "core/templates/vector.h"
class Geometry2D {
diff --git a/core/os/memory.h b/core/os/memory.h
index 9d09626b8c..f67384a17e 100644
--- a/core/os/memory.h
+++ b/core/os/memory.h
@@ -35,6 +35,7 @@
#include "core/templates/safe_refcount.h"
#include <stddef.h>
+#include <new>
#ifndef PAD_ALIGN
#define PAD_ALIGN 16 //must always be greater than this at much
@@ -92,15 +93,8 @@ _ALWAYS_INLINE_ T *_post_initialize(T *p_obj) {
#define memnew(m_class) _post_initialize(new ("") m_class)
-_ALWAYS_INLINE_ void *operator new(size_t p_size, void *p_pointer, size_t check, const char *p_description) {
- //void *failptr=0;
- //ERR_FAIL_COND_V( check < p_size , failptr); /** bug, or strange compiler, most likely */
-
- return p_pointer;
-}
-
#define memnew_allocator(m_class, m_allocator) _post_initialize(new (m_allocator::alloc) m_class)
-#define memnew_placement(m_placement, m_class) _post_initialize(new (m_placement, sizeof(m_class), "") m_class)
+#define memnew_placement(m_placement, m_class) _post_initialize(new (m_placement) m_class)
_ALWAYS_INLINE_ bool predelete_handler(void *) {
return true;
@@ -140,7 +134,7 @@ void memdelete_allocator(T *p_class) {
#define memnew_arr(m_class, m_count) memnew_arr_template<m_class>(m_count)
template <typename T>
-T *memnew_arr_template(size_t p_elements, const char *p_descr = "") {
+T *memnew_arr_template(size_t p_elements) {
if (p_elements == 0) {
return nullptr;
}
@@ -158,7 +152,7 @@ T *memnew_arr_template(size_t p_elements, const char *p_descr = "") {
/* call operator new */
for (size_t i = 0; i < p_elements; i++) {
- new (&elems[i], sizeof(T), p_descr) T;
+ new (&elems[i]) T;
}
}
diff --git a/core/string/ustring.cpp b/core/string/ustring.cpp
index 7beecdb6b5..2fdf6e84e5 100644
--- a/core/string/ustring.cpp
+++ b/core/string/ustring.cpp
@@ -54,11 +54,27 @@
#define snprintf _snprintf_s
#endif
-#define MAX_DECIMALS 32
-#define UPPERCASE(m_c) (((m_c) >= 'a' && (m_c) <= 'z') ? ((m_c) - ('a' - 'A')) : (m_c))
-#define LOWERCASE(m_c) (((m_c) >= 'A' && (m_c) <= 'Z') ? ((m_c) + ('a' - 'A')) : (m_c))
-#define IS_DIGIT(m_d) ((m_d) >= '0' && (m_d) <= '9')
-#define IS_HEX_DIGIT(m_d) (((m_d) >= '0' && (m_d) <= '9') || ((m_d) >= 'a' && (m_d) <= 'f') || ((m_d) >= 'A' && (m_d) <= 'F'))
+static const int MAX_DECIMALS = 32;
+
+static _FORCE_INLINE_ bool is_digit(char32_t c) {
+ return (c >= '0' && c <= '9');
+}
+
+static _FORCE_INLINE_ bool is_hex_digit(char32_t c) {
+ return (is_digit(c) || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'));
+}
+
+static _FORCE_INLINE_ bool is_upper_case(char32_t c) {
+ return (c >= 'A' && c <= 'Z');
+}
+
+static _FORCE_INLINE_ bool is_lower_case(char32_t c) {
+ return (c >= 'a' && c <= 'z');
+}
+
+static _FORCE_INLINE_ char32_t lower_case(char32_t c) {
+ return (is_upper_case(c) ? (c + ('a' - 'A')) : c);
+}
const char CharString::_null = 0;
const char16_t Char16String::_null = 0;
@@ -738,6 +754,7 @@ bool String::operator<=(const String &p_str) const {
bool String::operator>(const String &p_str) const {
return p_str < *this;
}
+
bool String::operator>=(const String &p_str) const {
return !(*this < p_str);
}
@@ -871,8 +888,8 @@ signed char String::naturalnocasecmp_to(const String &p_str) const {
while (*this_str) {
if (!*that_str) {
return 1;
- } else if (IS_DIGIT(*this_str)) {
- if (!IS_DIGIT(*that_str)) {
+ } else if (is_digit(*this_str)) {
+ if (!is_digit(*that_str)) {
return -1;
}
@@ -881,10 +898,10 @@ signed char String::naturalnocasecmp_to(const String &p_str) const {
const char32_t *that_substr = that_str;
// Compare lengths of both numerical sequences, ignoring leading zeros
- while (IS_DIGIT(*this_str)) {
+ while (is_digit(*this_str)) {
this_str++;
}
- while (IS_DIGIT(*that_str)) {
+ while (is_digit(*that_str)) {
that_str++;
}
while (*this_substr == '0') {
@@ -912,7 +929,7 @@ signed char String::naturalnocasecmp_to(const String &p_str) const {
this_substr++;
that_substr++;
}
- } else if (IS_DIGIT(*that_str)) {
+ } else if (is_digit(*that_str)) {
return 1;
} else {
if (_find_upper(*this_str) < _find_upper(*that_str)) { //more than
@@ -962,26 +979,25 @@ String String::capitalize() const {
String String::camelcase_to_underscore(bool lowercase) const {
const char32_t *cstr = get_data();
String new_string;
- const char A = 'A', Z = 'Z';
- const char a = 'a', z = 'z';
int start_index = 0;
for (int i = 1; i < this->size(); i++) {
- bool is_upper = cstr[i] >= A && cstr[i] <= Z;
- bool is_number = cstr[i] >= '0' && cstr[i] <= '9';
+ bool is_upper = is_upper_case(cstr[i]);
+ bool is_number = is_digit(cstr[i]);
+
bool are_next_2_lower = false;
bool is_next_lower = false;
bool is_next_number = false;
- bool was_precedent_upper = cstr[i - 1] >= A && cstr[i - 1] <= Z;
- bool was_precedent_number = cstr[i - 1] >= '0' && cstr[i - 1] <= '9';
+ bool was_precedent_upper = is_upper_case(cstr[i - 1]);
+ bool was_precedent_number = is_digit(cstr[i - 1]);
if (i + 2 < this->size()) {
- are_next_2_lower = cstr[i + 1] >= a && cstr[i + 1] <= z && cstr[i + 2] >= a && cstr[i + 2] <= z;
+ are_next_2_lower = is_lower_case(cstr[i + 1]) && is_lower_case(cstr[i + 2]);
}
if (i + 1 < this->size()) {
- is_next_lower = cstr[i + 1] >= a && cstr[i + 1] <= z;
- is_next_number = cstr[i + 1] >= '0' && cstr[i + 1] <= '9';
+ is_next_lower = is_lower_case(cstr[i + 1]);
+ is_next_number = is_digit(cstr[i + 1]);
}
const bool cond_a = is_upper && !was_precedent_upper && !was_precedent_number;
@@ -2198,9 +2214,9 @@ int64_t String::hex_to_int() const {
int64_t hex = 0;
while (*s) {
- char32_t c = LOWERCASE(*s);
+ char32_t c = lower_case(*s);
int64_t n;
- if (c >= '0' && c <= '9') {
+ if (is_digit(c)) {
n = c - '0';
} else if (c >= 'a' && c <= 'f') {
n = (c - 'a') + 10;
@@ -2239,7 +2255,7 @@ int64_t String::bin_to_int() const {
int64_t binary = 0;
while (*s) {
- char32_t c = LOWERCASE(*s);
+ char32_t c = lower_case(*s);
int64_t n;
if (c == '0' || c == '1') {
n = c - '0';
@@ -2269,7 +2285,7 @@ int64_t String::to_int() const {
for (int i = 0; i < to; i++) {
char32_t c = operator[](i);
- if (c >= '0' && c <= '9') {
+ if (is_digit(c)) {
bool overflow = (integer > INT64_MAX / 10) || (integer == INT64_MAX / 10 && ((sign == 1 && c > '7') || (sign == -1 && c > '8')));
ERR_FAIL_COND_V_MSG(overflow, sign == 1 ? INT64_MAX : INT64_MIN, "Cannot represent " + *this + " as 64-bit integer, provided value is " + (sign == 1 ? "too big." : "too small."));
integer *= 10;
@@ -2298,7 +2314,7 @@ int64_t String::to_int(const char *p_str, int p_len) {
for (int i = 0; i < to; i++) {
char c = p_str[i];
- if (c >= '0' && c <= '9') {
+ if (is_digit(c)) {
bool overflow = (integer > INT64_MAX / 10) || (integer == INT64_MAX / 10 && ((sign == 1 && c > '7') || (sign == -1 && c > '8')));
ERR_FAIL_COND_V_MSG(overflow, sign == 1 ? INT64_MAX : INT64_MIN, "Cannot represent " + String(p_str).substr(0, to) + " as integer, provided value is " + (sign == 1 ? "too big." : "too small."));
integer *= 10;
@@ -2329,7 +2345,7 @@ int64_t String::to_int(const wchar_t *p_str, int p_len) {
for (int i = 0; i < to; i++) {
wchar_t c = p_str[i];
- if (c >= '0' && c <= '9') {
+ if (is_digit(c)) {
bool overflow = (integer > INT64_MAX / 10) || (integer == INT64_MAX / 10 && ((sign == 1 && c > '7') || (sign == -1 && c > '8')));
ERR_FAIL_COND_V_MSG(overflow, sign == 1 ? INT64_MAX : INT64_MIN, "Cannot represent " + String(p_str).substr(0, to) + " as integer, provided value is " + (sign == 1 ? "too big." : "too small."));
integer *= 10;
@@ -2449,7 +2465,7 @@ static double built_in_strtod(const C *string, /* A decimal ASCII floating-point
decPt = -1;
for (mantSize = 0;; mantSize += 1) {
c = *p;
- if (!IS_DIGIT(c)) {
+ if (!is_digit(c)) {
if ((c != '.') || (decPt >= 0)) {
break;
}
@@ -2524,11 +2540,11 @@ static double built_in_strtod(const C *string, /* A decimal ASCII floating-point
}
expSign = false;
}
- if (!IS_DIGIT(char32_t(*p))) {
+ if (!is_digit(char32_t(*p))) {
p = pExp;
goto done;
}
- while (IS_DIGIT(char32_t(*p))) {
+ while (is_digit(char32_t(*p))) {
exp = exp * 10 + (*p - '0');
p += 1;
}
@@ -2614,7 +2630,7 @@ int64_t String::to_int(const char32_t *p_str, int p_len, bool p_clamp) {
char32_t c = *(str++);
switch (reading) {
case READING_SIGN: {
- if (c >= '0' && c <= '9') {
+ if (is_digit(c)) {
reading = READING_INT;
// let it fallthrough
} else if (c == '-') {
@@ -2631,7 +2647,7 @@ int64_t String::to_int(const char32_t *p_str, int p_len, bool p_clamp) {
[[fallthrough]];
}
case READING_INT: {
- if (c >= '0' && c <= '9') {
+ if (is_digit(c)) {
if (integer > INT64_MAX / 10) {
String number("");
str = p_str;
@@ -3800,12 +3816,12 @@ bool String::is_valid_identifier() const {
for (int i = 0; i < len; i++) {
if (i == 0) {
- if (str[0] >= '0' && str[0] <= '9') {
+ if (is_digit(str[0])) {
return false; // no start with number plz
}
}
- bool valid_char = (str[i] >= '0' && str[i] <= '9') || (str[i] >= 'a' && str[i] <= 'z') || (str[i] >= 'A' && str[i] <= 'Z') || str[i] == '_';
+ bool valid_char = is_digit(str[i]) || is_lower_case(str[i]) || is_upper_case(str[i]) || str[i] == '_';
if (!valid_char) {
return false;
@@ -3830,10 +3846,7 @@ String String::uri_encode() const {
String res;
for (int i = 0; i < temp.length(); ++i) {
char ord = temp[i];
- if (ord == '.' || ord == '-' || ord == '_' || ord == '~' ||
- (ord >= 'a' && ord <= 'z') ||
- (ord >= 'A' && ord <= 'Z') ||
- (ord >= '0' && ord <= '9')) {
+ if (ord == '.' || ord == '-' || ord == '_' || ord == '~' || is_lower_case(ord) || is_upper_case(ord) || is_digit(ord)) {
res += ord;
} else {
char h_Val[3];
@@ -3855,9 +3868,9 @@ String String::uri_decode() const {
for (int i = 0; i < src.length(); ++i) {
if (src[i] == '%' && i + 2 < src.length()) {
char ord1 = src[i + 1];
- if ((ord1 >= '0' && ord1 <= '9') || (ord1 >= 'A' && ord1 <= 'Z')) {
+ if (is_digit(ord1) || is_upper_case(ord1)) {
char ord2 = src[i + 2];
- if ((ord2 >= '0' && ord2 <= '9') || (ord2 >= 'A' && ord2 <= 'Z')) {
+ if (is_digit(ord2) || is_upper_case(ord2)) {
char bytes[3] = { (char)ord1, (char)ord2, 0 };
res += (char)strtol(bytes, nullptr, 16);
i += 2;
@@ -3963,7 +3976,7 @@ static _FORCE_INLINE_ int _xml_unescape(const char32_t *p_src, int p_src_len, ch
char32_t ct = p_src[i];
if (ct == ';') {
break;
- } else if (ct >= '0' && ct <= '9') {
+ } else if (is_digit(ct)) {
ct = ct - '0';
} else if (ct >= 'a' && ct <= 'f') {
ct = (ct - 'a') + 10;
@@ -4191,7 +4204,7 @@ bool String::is_valid_hex_number(bool p_with_prefix) const {
for (int i = from; i < len; i++) {
char32_t c = operator[](i);
- if ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F')) {
+ if (is_hex_digit(c)) {
continue;
}
return false;
@@ -4219,7 +4232,7 @@ bool String::is_valid_float() const {
bool numbers_found = false;
for (int i = from; i < len; i++) {
- if (operator[](i) >= '0' && operator[](i) <= '9') {
+ if (is_digit(operator[](i))) {
if (exponent_found) {
exponent_values_found = true;
} else {
diff --git a/core/templates/cowdata.h b/core/templates/cowdata.h
index c985593473..ba9babe0af 100644
--- a/core/templates/cowdata.h
+++ b/core/templates/cowdata.h
@@ -232,7 +232,7 @@ uint32_t CowData<T>::_copy_on_write() {
uint32_t *mem_new = (uint32_t *)Memory::alloc_static(_get_alloc_size(current_size), true);
- new (mem_new - 2, sizeof(uint32_t), "") SafeNumeric<uint32_t>(1); //refcount
+ new (mem_new - 2) SafeNumeric<uint32_t>(1); //refcount
*(mem_new - 1) = current_size; //size
T *_data = (T *)(mem_new);
@@ -286,14 +286,14 @@ Error CowData<T>::resize(int p_size) {
uint32_t *ptr = (uint32_t *)Memory::alloc_static(alloc_size, true);
ERR_FAIL_COND_V(!ptr, ERR_OUT_OF_MEMORY);
*(ptr - 1) = 0; //size, currently none
- new (ptr - 2, sizeof(uint32_t), "") SafeNumeric<uint32_t>(1); //refcount
+ new (ptr - 2) SafeNumeric<uint32_t>(1); //refcount
_ptr = (T *)ptr;
} else {
uint32_t *_ptrnew = (uint32_t *)Memory::realloc_static(_ptr, alloc_size, true);
ERR_FAIL_COND_V(!_ptrnew, ERR_OUT_OF_MEMORY);
- new (_ptrnew - 2, sizeof(uint32_t), "") SafeNumeric<uint32_t>(rc); //refcount
+ new (_ptrnew - 2) SafeNumeric<uint32_t>(rc); //refcount
_ptr = (T *)(_ptrnew);
}
@@ -323,7 +323,7 @@ Error CowData<T>::resize(int p_size) {
if (alloc_size != current_alloc_size) {
uint32_t *_ptrnew = (uint32_t *)Memory::realloc_static(_ptr, alloc_size, true);
ERR_FAIL_COND_V(!_ptrnew, ERR_OUT_OF_MEMORY);
- new (_ptrnew - 2, sizeof(uint32_t), "") SafeNumeric<uint32_t>(rc); //refcount
+ new (_ptrnew - 2) SafeNumeric<uint32_t>(rc); //refcount
_ptr = (T *)(_ptrnew);
}