aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/Common
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/ScriptEngine/Common')
-rw-r--r--OpenSim/Region/ScriptEngine/Common/LSL_Types.cs96
1 files changed, 94 insertions, 2 deletions
diff --git a/OpenSim/Region/ScriptEngine/Common/LSL_Types.cs b/OpenSim/Region/ScriptEngine/Common/LSL_Types.cs
index 4fff717..3b2594d 100644
--- a/OpenSim/Region/ScriptEngine/Common/LSL_Types.cs
+++ b/OpenSim/Region/ScriptEngine/Common/LSL_Types.cs
@@ -634,6 +634,98 @@ namespace OpenSim.Region.ScriptEngine.Common
634 } 634 }
635 } 635 }
636 636
637 private class AlphanumComparatorFast : IComparer
638 {
639 public int Compare(object x, object y)
640 {
641 string s1 = x as string;
642 if (s1 == null)
643 {
644 return 0;
645 }
646 string s2 = y as string;
647 if (s2 == null)
648 {
649 return 0;
650 }
651
652 int len1 = s1.Length;
653 int len2 = s2.Length;
654 int marker1 = 0;
655 int marker2 = 0;
656
657 // Walk through two the strings with two markers.
658 while (marker1 < len1 && marker2 < len2)
659 {
660 char ch1 = s1[marker1];
661 char ch2 = s2[marker2];
662
663 // Some buffers we can build up characters in for each chunk.
664 char[] space1 = new char[len1];
665 int loc1 = 0;
666 char[] space2 = new char[len2];
667 int loc2 = 0;
668
669 // Walk through all following characters that are digits or
670 // characters in BOTH strings starting at the appropriate marker.
671 // Collect char arrays.
672 do
673 {
674 space1[loc1++] = ch1;
675 marker1++;
676
677 if (marker1 < len1)
678 {
679 ch1 = s1[marker1];
680 }
681 else
682 {
683 break;
684 }
685 } while (char.IsDigit(ch1) == char.IsDigit(space1[0]));
686
687 do
688 {
689 space2[loc2++] = ch2;
690 marker2++;
691
692 if (marker2 < len2)
693 {
694 ch2 = s2[marker2];
695 }
696 else
697 {
698 break;
699 }
700 } while (char.IsDigit(ch2) == char.IsDigit(space2[0]));
701
702 // If we have collected numbers, compare them numerically.
703 // Otherwise, if we have strings, compare them alphabetically.
704 string str1 = new string(space1);
705 string str2 = new string(space2);
706
707 int result;
708
709 if (char.IsDigit(space1[0]) && char.IsDigit(space2[0]))
710 {
711 int thisNumericChunk = int.Parse(str1);
712 int thatNumericChunk = int.Parse(str2);
713 result = thisNumericChunk.CompareTo(thatNumericChunk);
714 }
715 else
716 {
717 result = str1.CompareTo(str2);
718 }
719
720 if (result != 0)
721 {
722 return result;
723 }
724 }
725 return len1 - len2;
726 }
727 }
728
637 public list Sort(int stride, int ascending) 729 public list Sort(int stride, int ascending)
638 { 730 {
639 if (Data.Length == 0) 731 if (Data.Length == 0)
@@ -652,7 +744,7 @@ namespace OpenSim.Region.ScriptEngine.Common
652 for (int k = 0; k < Data.Length; k++) 744 for (int k = 0; k < Data.Length; k++)
653 keys[k] = Data[k].ToString(); 745 keys[k] = Data[k].ToString();
654 746
655 Array.Sort(keys, ret); 747 Array.Sort( keys, ret, new AlphanumComparatorFast() );
656 748
657 if (ascending == 0) 749 if (ascending == 0)
658 Array.Reverse(ret); 750 Array.Reverse(ret);
@@ -688,7 +780,7 @@ namespace OpenSim.Region.ScriptEngine.Common
688 vals[idx]=o; 780 vals[idx]=o;
689 } 781 }
690 782
691 Array.Sort(keys, vals); 783 Array.Sort(keys, vals, new AlphanumComparatorFast());
692 if (ascending == 0) 784 if (ascending == 0)
693 { 785 {
694 Array.Reverse(vals); 786 Array.Reverse(vals);