From 9b4f54c826ffa4f94efa866068c9d6ecdfb4b424 Mon Sep 17 00:00:00 2001 From: Jacek Antonelli Date: Fri, 15 Aug 2008 23:44:48 -0500 Subject: Second Life viewer sources 1.13.2.15 --- linden/indra/lscript/lscript_alloc.h | 72 +--------------------- .../lscript/lscript_compile/lscript_compile.vcproj | 6 +- .../lscript/lscript_execute/lscript_execute.vcproj | 6 +- .../lscript/lscript_library/lscript_alloc.cpp | 59 ++++++++++++++++++ .../lscript/lscript_library/lscript_library.cpp | 2 +- .../lscript/lscript_library/lscript_library.vcproj | 6 +- 6 files changed, 71 insertions(+), 80 deletions(-) (limited to 'linden/indra/lscript') diff --git a/linden/indra/lscript/lscript_alloc.h b/linden/indra/lscript/lscript_alloc.h index 67e3dc0..4d69e8e 100644 --- a/linden/indra/lscript/lscript_alloc.h +++ b/linden/indra/lscript/lscript_alloc.h @@ -246,7 +246,7 @@ inline LLScriptLibData *lsa_bubble_sort(LLScriptLibData *src, S32 stride, S32 as return retval; } - LLScriptLibData **sortarray = (LLScriptLibData **)new U32[number]; + LLScriptLibData **sortarray = new LLScriptLibData*[number]; LLScriptLibData *temp = src->mListp; while (temp) @@ -290,74 +290,6 @@ inline LLScriptLibData *lsa_bubble_sort(LLScriptLibData *src, S32 stride, S32 as } -inline LLScriptLibData *lsa_randomize(LLScriptLibData *src, S32 stride) -{ - S32 number = src->getListLength(); - - if (number <= 0) - { - return NULL; - } - - if (stride <= 0) - { - stride = 1; - } - - if (number % stride) - { - LLScriptLibData *retval = src->mListp; - src->mListp = NULL; - return retval; - } - - LLScriptLibData **sortarray = (LLScriptLibData **)new U32[number]; - - LLScriptLibData *temp = src->mListp; - S32 i = 0; - while (temp) - { - sortarray[i] = temp; - i++; - temp = temp->mListp; - } - - S32 k, j, s; - - for (k = 0; k < 20; k++) - { - for (i = 0; i < number; i += stride) - { - for (j = i; j < number; j += stride) - { - if (frand(1.f) > 0.5) - { - for (s = 0; s < stride; s++) - { - temp = sortarray[i + s]; - sortarray[i + s] = sortarray[j + s]; - sortarray[j + s] = temp; - } - } - } - } - } - - i = 1; - temp = sortarray[0]; - while (i < number) - { - temp->mListp = sortarray[i++]; - temp = temp->mListp; - } - temp->mListp = NULL; - - src->mListp = NULL; - - LLScriptLibData *ret_value = sortarray[0]; - delete [] sortarray; - - return ret_value; -} +LLScriptLibData* lsa_randomize(LLScriptLibData* src, S32 stride); #endif diff --git a/linden/indra/lscript/lscript_compile/lscript_compile.vcproj b/linden/indra/lscript/lscript_compile/lscript_compile.vcproj index 581fa27..fd03fa0 100644 --- a/linden/indra/lscript/lscript_compile/lscript_compile.vcproj +++ b/linden/indra/lscript/lscript_compile/lscript_compile.vcproj @@ -19,7 +19,7 @@ getListLength(); + if (number <= 0) + { + return NULL; + } + if (stride <= 0) + { + stride = 1; + } + if(number % stride) + { + LLScriptLibData* retval = src->mListp; + src->mListp = NULL; + return retval; + } + S32 buckets = number / stride; + + // Copy everything into a special vector for sorting; + std::vector sort_array; + sort_array.reserve(number); + LLScriptLibData* temp = src->mListp; + while(temp) + { + sort_array.push_back(temp); + temp = temp->mListp; + } + + // We cannot simply call random_shuffle or similar algorithm since + // we need to obey the stride. So, we iterate over what we have + // and swap each with a random other segment. + S32 index = 0; + S32 ii = 0; + for(; ii < number; ii += stride) + { + index = ll_rand(buckets) * stride; + for(S32 jj = 0; jj < stride; ++jj) + { + std::swap(sort_array[ii + jj], sort_array[index + jj]); + } + } + + // copy the pointers back out + ii = 1; + temp = sort_array[0]; + while (ii < number) + { + temp->mListp = sort_array[ii++]; + temp = temp->mListp; + } + temp->mListp = NULL; + + src->mListp = NULL; + + LLScriptLibData* ret_value = sort_array[0]; + return ret_value; +} diff --git a/linden/indra/lscript/lscript_library/lscript_library.cpp b/linden/indra/lscript/lscript_library/lscript_library.cpp index 098c836..1b92608 100644 --- a/linden/indra/lscript/lscript_library/lscript_library.cpp +++ b/linden/indra/lscript/lscript_library/lscript_library.cpp @@ -467,7 +467,7 @@ LLScriptLibraryFunction::~LLScriptLibraryFunction() void LLScriptLibrary::addFunction(LLScriptLibraryFunction *func) { - LLScriptLibraryFunction **temp = (LLScriptLibraryFunction **)new U32[mNextNumber + 1]; + LLScriptLibraryFunction **temp = new LLScriptLibraryFunction*[mNextNumber + 1]; if (mNextNumber) { memcpy(temp, mFunctions, sizeof(LLScriptLibraryFunction *)*mNextNumber); diff --git a/linden/indra/lscript/lscript_library/lscript_library.vcproj b/linden/indra/lscript/lscript_library/lscript_library.vcproj index f4861c7..1a340da 100644 --- a/linden/indra/lscript/lscript_library/lscript_library.vcproj +++ b/linden/indra/lscript/lscript_library/lscript_library.vcproj @@ -19,7 +19,7 @@