From 4855e1134673468b205b46d1952a30c9f7f91198 Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Mon, 31 May 2021 18:12:33 +0100 Subject: [PATCH] a few more changes to lsl list; add osListSortInPlace(LSL_List src, LSL_Integer stride, LSL_Integer ascending), does the sort directly on src, avoiding creation on a new list when that is not needed --- .../Shared/Api/Implementation/OSSL_Api.cs | 18 +++++---- .../Shared/Api/Interface/IOSSL_Api.cs | 1 + .../Region/ScriptEngine/Shared/LSL_Types.cs | 40 ++++++++++++++----- 3 files changed, 42 insertions(+), 17 deletions(-) diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs index ef3d4b4a88..4f1eb52e63 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs @@ -764,15 +764,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api // CheckThreatLevel(ThreatLevel.VeryHigh, "osSetRot"); - if (World.Entities.ContainsKey(target)) + if (World.Entities.TryGetValue(target, out EntityBase entity)) { - if (World.Entities.TryGetValue(target, out EntityBase entity)) - { - if (entity is SceneObjectGroup) - ((SceneObjectGroup)entity).UpdateGroupRotationR(rotation); - else if (entity is ScenePresence) - ((ScenePresence)entity).Rotation = rotation; - } + if (entity is SceneObjectGroup) + ((SceneObjectGroup)entity).UpdateGroupRotationR(rotation); + else if (entity is ScenePresence) + ((ScenePresence)entity).Rotation = rotation; } else { @@ -6096,5 +6093,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api return av.IsNPC ? 2 : 1; } + + public void osListSortInPlace(LSL_List src, LSL_Integer stride, LSL_Integer ascending) + { + src.SortInPlace(stride, ascending == 1); + } } } \ No newline at end of file diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs index 602306853a..42024c55e9 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs @@ -596,5 +596,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces LSL_Integer osAvatarType(LSL_Key avkey); LSL_Integer osAvatarType(LSL_String sFirstName, LSL_String sLastName); + void osListSortInPlace(LSL_List src, LSL_Integer stride, LSL_Integer ascending); } } diff --git a/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs b/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs index 6910bb61fe..11ab46be3a 100644 --- a/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs +++ b/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs @@ -1320,18 +1320,43 @@ namespace OpenSim.Region.ScriptEngine.Shared public list Sort(int stride, bool ascending) { - if (m_data == null || m_data.Length == 0) + if (m_data == null) return new list(); // Don't even bother - object[] ret = new object[m_data.Length]; - Array.Copy(m_data, 0, ret, 0, m_data.Length); + int len = m_data.Length; + if(len == 0) + return new list(); // Don't even bother - if (stride <= 0) + object[] ret = new object[len]; + Array.Copy(m_data, 0, ret, 0, len); + + if (stride < 1) stride = 1; - if ((ret.Length <= stride) || (ret.Length % stride) != 0) + if ((len <= stride) || (len % stride) != 0) return new list(ret); + Sort(ret, stride, ascending); + return new list(ret); + } + + public void SortInPlace(int stride, bool ascending) + { + if (m_data == null) + return; // Don't even bother + + if (stride < 1) + stride = 1; + + int len = m_data.Length; + if ((len <= stride) || (len % stride) != 0) + return; + + Sort(m_data, stride, ascending); + } + + public void Sort(object[] ret, int stride, bool ascending) + { // if list does not consists of homogeneous types // and because of the desired type specific feathered sorting behavior // requeried by the spec, we MUST use a non-optimized bubble sort @@ -1393,10 +1418,9 @@ namespace OpenSim.Region.ScriptEngine.Shared } } } - return new list(ret); + return; } - if (ascending) { for (int i = 0; i < ret.Length - stride; i += stride) @@ -1457,8 +1481,6 @@ namespace OpenSim.Region.ScriptEngine.Shared ret[i] = pivot; } } - - return new list(ret); } #region CSV Methods