diff --git a/include/Array.h b/include/Array.h index 0fffbda3c..a5eab7f62 100644 --- a/include/Array.h +++ b/include/Array.h @@ -1,7 +1,5 @@ #ifndef HX_ARRAY_H #define HX_ARRAY_H -#include -#include #include // --- hx::ReturnNull ------------------------------------------------------ @@ -59,78 +57,6 @@ template<> struct ArrayTraits { enum { StoreType = arrayObject }; }; template<> struct ArrayTraits { enum { StoreType = arrayString }; }; template<> struct ArrayTraits< ::cpp::Int64> { enum { StoreType = arrayInt64 }; }; -template -class SafeSorter -{ - typedef -#if (HXCPP_API_LEVEL>=500) - ::hx::Callable -#else - Dynamic -#endif - SorterFunc; - - struct ArraySorter - { - ELEM* mArray; - SorterFunc mSorter; - - ArraySorter(ELEM* inArray, SorterFunc inSorter) : mArray(inArray), mSorter(inSorter) {}; - - bool operator()(int inA, int inB) - { - return mSorter(mArray[inA], mArray[inB]) < 0; - } - }; - - template - static void SortImpl(ELEM* inArray, const int inLength, SorterFunc inSorter) - { - auto index = std::vector(inLength); - for (auto i = 0; i < inLength; i++) - { - index[i] = static_cast(i); - } - - std::stable_sort(index.begin(), index.end(), ArraySorter(inArray, inSorter)); - - // Put the results back ... - for (int i = 0; i < inLength; i++) - { - int from = index[i]; - while (from < i) - from = index[from]; - if (from != i) - { - std::swap(inArray[i], inArray[from]); - index[i] = from; - } - } - } - -public: - static void Sort(ELEM* base, const int length, SorterFunc sorter) - { - if (length < 2) - { - return; - } - - if (length <= std::numeric_limits::max()) - { - SortImpl(base, length, sorter); - } - else if (length <= std::numeric_limits::max()) - { - SortImpl(base, length, sorter); - } - else - { - SortImpl(base, length, sorter); - } - } -}; - } diff --git a/include/hx/Telemetry.h b/include/hx/Telemetry.h index cf8657785..855443353 100644 --- a/include/hx/Telemetry.h +++ b/include/hx/Telemetry.h @@ -3,7 +3,6 @@ #define HX_TELEMETRY_VERSION 1 -#include #include struct TelemetryFrame diff --git a/include/hxcpp.h b/include/hxcpp.h index 19382503a..eed4bb704 100755 --- a/include/hxcpp.h +++ b/include/hxcpp.h @@ -346,7 +346,9 @@ typedef PropertyAccessMode PropertyAccess; #include #include "Enum.h" #include +#ifdef HXCPP_TELEMETRY #include +#endif #if defined(__OBJC__) && defined(HXCPP_OBJC) #include #endif diff --git a/src/Array.cpp b/src/Array.cpp index d51401f15..fbafd0200 100644 --- a/src/Array.cpp +++ b/src/Array.cpp @@ -1,11 +1,87 @@ #include #include +#include #include #ifdef HXCPP_TELEMETRY extern void __hxt_new_array(void* obj, int size); #endif +namespace +{ + template + class SafeSorter + { + typedef +#if (HXCPP_API_LEVEL>=500) + ::hx::Callable +#else + Dynamic +#endif + SorterFunc; + + struct ArraySorter + { + ELEM* mArray; + SorterFunc mSorter; + + ArraySorter(ELEM* inArray, SorterFunc inSorter) : mArray(inArray), mSorter(inSorter) {}; + + bool operator()(int inA, int inB) + { + return mSorter(mArray[inA], mArray[inB]) < 0; + } + }; + + template + static void SortImpl(ELEM* inArray, const int inLength, SorterFunc inSorter) + { + auto index = std::vector(inLength); + for (auto i = 0; i < inLength; i++) + { + index[i] = static_cast(i); + } + + std::stable_sort(index.begin(), index.end(), ArraySorter(inArray, inSorter)); + + // Put the results back ... + for (int i = 0; i < inLength; i++) + { + int from = index[i]; + while (from < i) + from = index[from]; + if (from != i) + { + std::swap(inArray[i], inArray[from]); + index[i] = from; + } + } + } + + public: + static void Sort(ELEM* base, const int length, SorterFunc sorter) + { + if (length < 2) + { + return; + } + + if (length <= std::numeric_limits::max()) + { + SortImpl(base, length, sorter); + } + else if (length <= std::numeric_limits::max()) + { + SortImpl(base, length, sorter); + } + else + { + SortImpl(base, length, sorter); + } + } + }; +} + using namespace hx; @@ -492,9 +568,9 @@ String ArrayBase::joinArray(ArrayBase *inBase, String inSeparator) void ArrayBase::safeSort(DynamicSorterFunc inSorter, bool inIsString) { if (inIsString) - hx::SafeSorter::Sort((String *)mBase, length,inSorter); + SafeSorter::Sort((String *)mBase, length,inSorter); else - hx::SafeSorter::Sort((Dynamic *)mBase, length,inSorter); + SafeSorter::Sort((Dynamic *)mBase, length,inSorter); }