diff options
author | Yuri Sizov <yuris@humnom.net> | 2023-07-26 18:39:08 +0200 |
---|---|---|
committer | Yuri Sizov <yuris@humnom.net> | 2023-07-26 18:39:08 +0200 |
commit | 53ba9ccb194c0c52d25994ccec21965ac34a3d99 (patch) | |
tree | d89266cd5e0ea1cd135d3742cafbd4d64d008b07 /core/object | |
parent | 3bc842b1b129b379d8e73bb21660e9bb6b0f79f8 (diff) | |
parent | 5cc961627de43b592b1c69c5367d7ab9fb43a732 (diff) | |
download | redot-engine-53ba9ccb194c0c52d25994ccec21965ac34a3d99.tar.gz |
Merge pull request #72346 from myaaaaaaaaa/disconnect-order
Avoid sorting CallableCustomMethodPointers by their actual address values
Diffstat (limited to 'core/object')
-rw-r--r-- | core/object/callable_method_pointer.cpp | 22 |
1 files changed, 6 insertions, 16 deletions
diff --git a/core/object/callable_method_pointer.cpp b/core/object/callable_method_pointer.cpp index b53985e6b7..ed400788b1 100644 --- a/core/object/callable_method_pointer.cpp +++ b/core/object/callable_method_pointer.cpp @@ -38,13 +38,10 @@ bool CallableCustomMethodPointerBase::compare_equal(const CallableCustom *p_a, c return false; } - for (uint32_t i = 0; i < a->comp_size; i++) { - if (a->comp_ptr[i] != b->comp_ptr[i]) { - return false; - } - } - - return true; + // Avoid sorting by memory address proximity, which leads to unpredictable performance over time + // due to the reuse of old addresses for newer objects. Use byte-wise comparison to leverage the + // backwards encoding of little-endian systems as a way to decouple spatiality and time. + return memcmp(a->comp_ptr, b->comp_ptr, a->comp_size * 4) == 0; } bool CallableCustomMethodPointerBase::compare_less(const CallableCustom *p_a, const CallableCustom *p_b) { @@ -55,15 +52,8 @@ bool CallableCustomMethodPointerBase::compare_less(const CallableCustom *p_a, co return a->comp_size < b->comp_size; } - for (uint32_t i = 0; i < a->comp_size; i++) { - if (a->comp_ptr[i] == b->comp_ptr[i]) { - continue; - } - - return a->comp_ptr[i] < b->comp_ptr[i]; - } - - return false; + // See note in compare_equal(). + return memcmp(a->comp_ptr, b->comp_ptr, a->comp_size * 4) < 0; } CallableCustom::CompareEqualFunc CallableCustomMethodPointerBase::get_compare_equal_func() const { |