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

This commit is contained in:
UbitUmarov
2021-05-31 18:12:33 +01:00
parent afaa181676
commit 4855e11346
3 changed files with 42 additions and 17 deletions

View File

@@ -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);
}
}
}

View File

@@ -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);
}
}

View File

@@ -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